LLamas in Space

Visual Studio Add-Ins

Two addins that I find myself relying more and more lately are the PowerCommands and Pro Power Tools for VS2010.  Linkies to both.

Visual Studio 2010 Pro Power Tools

PowerCommands for Visual Studio 2010

Both are incredibly helpful in making the IDE better.  They aren’t for the casual dev as they add a lot of options that may not be needed for a developer still learning but they do increase one’s productivity.

The #1 feature that I love most from the Pro Power Tools is a throwback to the popular Delphi IDE’s with CTRL+Click that’s bound to the normal Right Click –> Go to Definition.

If you are a clean freak like me in your IDE the Collapse Projects available on the Solution is utterly necessary.

Enjoy :)

Raven Db Index Management Support

One thing with RavenDb that I’m constantly fighting especially while trying to learn it is managing indexes.  I find myself constantly blowing my test database away only to recreate it, rebuild the indexes, and add new indexes as necessary.  The most common practice I’ve seen so far is to manually manage these indexes since they only need to be built once.  This doesn’t work for me since I’m lazy thus I needed a solution.

The solution which is fairly easy is to call the indexes api and parse out the returning Json.  The API I’m using if called from localhost is http://localhost:8080/indexes.  Let it be of note this is only necessary if you are using the Server/Service model.  If using this in an embedded capacity then just access the indexes directly on the DocumentDatabase object. 

I’ve created a simple extension method on the DocumentStore that will give me access to the information I want which is what indexes are created.  Making it so I can preemptively query the database as to what I already have and only commit the deltas.

Here’s the C# solution for your viewing pleasure.



public static class IndexExtensions
{
public static IList GetIndexes(this DocumentStore store)
{

var client = new WebClient();
var result = client.DownloadString(
store.Configuration
.ServerUrl
.CombineUrl("indexes"));

var t = JsonConvert.DeserializeObject(result) as JArray;
return (from i in t
select i["name"]
.ToString()
.Replace("\"", ""))
.ToList();
}

public static string CombineUrl(this string baseUrl, string appendedUrl)
{
if (!baseUrl.EndsWith(@"/")) baseUrl += @"/";

var builder = new UriBuilder(baseUrl);
Uri newUri = null;

if (Uri.TryCreate(builder.Uri, appendedUrl, out newUri))
return newUri.ToString();
else
throw new ArgumentException("Unable to combine the specified url values");
}
}

Here's the F# solution if you are interested.



type System.String with
member x.CombineUrl(appendedUrl:string):string =
let k = match x with
| x when x.EndsWith(@"/") -> x
| _ -> x + @"/"

Uri.TryCreate((new UriBuilder(k)).Uri, appendedUrl) |>
function
| b, n when b -> n.ToString()
| _ -> failwith "Unable to combine url Values"

type Raven.Client.Document.DocumentStore with
member x.GetIndexes:list =
(new WebClient()).DownloadString (x.Configuration.ServerUrl.CombineUrl ("indexes"))
|> JArray.Parse
|> Seq.map (fun (i:JToken) -> i.Value("name"))
|> Seq.toList

Windows GodMode

It what it says it is.  Simply put create a new folder say on your desktop and name it the following

GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}

It’ll create an icon that will give you access to additional features some of which aren’t easily found in Windows and some that are not found at all.  Not sure how useful it is but it is pretty cool.  Windows 7 does make it all pretty but I have confirmed it does work on Windows Vista as well.

Enjoy.

Employee to Consultant

Recently we had a gentleman move from being an employee to consultant here at work.  This gentleman used to be my boss, transitioned to being our “Architect” and was thusly moved to being a consultant by extraneous circumstances.

I have recently been appointed to being this individual’s contact which means I am to track his progress and assure that it meets with our standards and is being done in a decent amount of time.  While this is certainly not an issue in my mind I wonder if it will be difficult in his at some point.

I am a no nonsense type of individual that seeks to getting the job done and if possible without any type of personal feelings.  While I will certainly voice my distain for a direction I will lead a sinking ship if asked.  With all of this I do wonder if working with this gentleman our relationship will be that of consultant and client or that of our first relationship of boss and underling.  While these circumstances were thrust upon both of us is it reasonable to think that one with a long history 3+ years with a company can transition from having any personal feelings to the more aptly “What can I do for you?” mentality.

So far my feelings are that this type of transition is and would be difficult for anyone to do and moreover can and might be counter productive.  I guess we’ll see over the coming months how this transition will pan out.  I’m hopeful but definitely not going to hold my breath.

Aliased Types

One of the less used features I’ve come to know and love as I’ve been working my current project which uses NHibernate and CSLA.Net is the ability to Alias an Object utilizing the “using” clause. The following is an example.


This beauty is essentially saying to the compiler to insert Clsa.Server.ObjectFactory everywhere that CslaObjectFactory exists. This is similar to what gets done when you do a typedef in C++. This is invaluable for me because we have a slew of naming collisions in our codebase.


The CTE as understood by a Dev :)

Since being introduced to the CTE I’ve become increasingly impressed at how well it manages to increase the speed of a query. Just recently I put it to the test to see how well it can increase the speed of a query I needed for pulling the last payment of an Order that had not been authorized. The following shows the final result.

WITH MaxPayment AS(
SELECT MAX(PaymentId) AS PaymentId
FROM dbo.Payment
WHERE IsAuthorized = 'F' AND PaymentMethodId = 116
GROUP BY OrderId),
Payments AS(
SELECT p.*
FROM dbo.Payment p
INNER JOIN MaxPayment m ON p.PaymentId = m.PaymentId)
SELECT o.OrderId, o.OrderBalance, p.IsAuthorized, p.PaymentId
FROM dbo.Orders o INNER JOIN Payments p ON p.OrderId = o.OrderId
WHERE OrderStatusId < 4000 AND PackingSlipBatchId = 0
AND o.OrderId IN (…)

This beauty uses two CTE’s in order to finally inner join with the final product. This query can pull any set of OrderId’s supplied to it in a lightning fast fashion (nanoseconds).

For those not familiar with the CTE its usefulness over subqueries becomes evident when I explain that when the CTE is generated the original schema is preserved which means tasty indexes you’ve added will be preserved unlike a subquery that essentially creates an indexless temporary table copies information into it then provides a join thereafter.

Interesting side not that I discovered when formulating this query. I wanted to know if prefiltering the information in the CTE would provide any speed increases so rather than specify OrderId IN (…) in the main body of the query I would supply it in the MaxPayment CTE. Analyzing the execution plan abruptly stopped that foolishness. The execution plans regardless of where I filtered were identical thus leading me to believe that the CTE will handle all filtering last with the main body of the query.

Number to Mexican Pesos (Spanish)

I went looking everywhere for a section of code that would do the following:

Take a number such as 633,623,202.16 and translated it into spanish in terms of mexican pesos.

Suprisingly absolutely zero code exists (at least that I could find) that would do the same thing in C#. Hopefully this helps someone. I haven't optimized it at all but it should be easy enough if someone had the time to optimize it.

The code can be found here.