Latest Posts
Orchard the open source CMS from Microsoft (http://www.orchardproject.net/) has a great tempting engine. The out of the box base template “The Theme Machine” is very powerful and flexible, however if you are as design challenged as I, creating something with it that looks decent is out of the question. To that end I use a very cool template builder, Artisteer (http://www.artisteer.com/) if that is not your speed there are about a million websites where you can download free/low cost templates, however most of them generate a standard HTML page with some javascript and css. I wanted to take a minute to document how I converted my HTML template into an Orchard theme.
(Disclaimer this worked for my site, your template might require some different html changes, especially when it comes time to edit the HTML and CSS)
Step 1: Get the html template. (Did I really need to tell you that?)
Step 2: The goal is to make a theme based on the base template “The Theme Machine”. You will need to follow the instructions on the Orchard site to “Generate a New Theme” http://www.orchardproject.net/docs/Writing-a-new-theme.ashx, however their instructions have you creating an empty theme. We need to create one based on “The Theme Machine”. To do that just alter the codegen step to use the following command:
>> codegen theme MyTheme /BasedOn:TheThemeMachine /CreateProject:true /IncludeInSolution:true
Step 3: Copy the CSS & related images into the “Styles” folder of your new theme
Step 4: Copy the javascript into the “Scripts” folder of your new theme
Step 5: Copy the template html file into the Views folder. I do this so that I have it for safe keeping and it stays with the project. Orchard will not be using it directly.
Step 6: Copy the “Layout.cshtml” file from the “Views” folder from the “TheThemeMachine” template into the “Views” folder of our new theme.
Step 7: This is the hard part, time to merge the HTML template that you found/created in Step 1 with the Layout.cshtml file you copied into your “Views” folder in Step 6.
There are 2 things that you will have to worry about here:
First you need to add references for the css and js files. My template requires 3 css files and 1 js file, so I needed to add the following at the top of the layout.cshtml file. I put mine just below the includes “Style.Include” statements that were already in the file.
My template looks like this:

Converted to the layout.cshtml file it looks like:

Now that we have the head tag filled with all its goodness, it is time to do the body part. Copy over the html from the template into your Layout.cshtml file. You want to copy the html just below the “@tag.StartElement” line of code. With the markup in place, start moving the placeholders from the Layout.cshtml file into the proper places in your new template.
Once you have moved the placeholders around, you will probably need to add a css file tweak everything just right.
Step 8: The menu. My template and my client required a drop down menu, however out of the box Orchard only supports a single level menu. Time to add a module, the “Advanced Menu” module from Piotr Szmyd to be specific. After installing this module you will now have the ability to create multi level menus. However it comes with its own look and feel. If this works for you great, if not, you will have to modify it. Since my template provides for a menu that I like I am going to use it. To do so I need to copy 2 more cshtml files into my "Views” folder. After adding the module you should see a folder for it listed in your “Modules” folder called “Szmyd.Orchard.Modules.Menu”. In there you will find a “Views” folder and in it you will see Menu.cshtml, and MenuItem.cshtml. Copy those two files into the "Views” folder of your theme. Now alter them to match your template, just like you did the layout.cshtml file.
I was deploying a website and was seeing the following behavior:
- site configured to use Windows Authentication & Impersonation
- everything in KB 942043 was set correctly (http://support.microsoft.com/kb/942043)
- site was working from IE on the WebServer
- site was working from FireFox on my desktop
- site was NOT working in Chrome on my desktop “Error 338 (net::ERR_INVALID_AUTH_CREDENTIALS): Unknown error.”
- site was NOT working in IE on my desktop, 401 error message after asking for UserName and Password 3 times
The fix was to force the web server to use NTLM. To do this in IIS 7 is just a setting in system.web/system.webServer/security/authentication/windowsAuthentication/providers section of the web.config:
Here is a screen print of my web.config

I was investigating techniques to do auditing and think this is going to fit my needs, thought I would share. . . .
Let me start by saying there are about 1000 examples similar to this on the web. However none of the examples I found meet my specific requirements.
First lets discuss the requirements:
- I need to be able to apply auditing to only some of the types in my system
- I need to be able to ignore some of the properties on a type (i.e. not audit them)
- I need something flexible enough that I can apply it to multiple DbContexts
- I needed to have audit columns on each record (CreatedBy, CreatedOn, UpdatedOn, UpdatedBy).
- I needed a log table that would record when we got new records, when a field got changed, and when a record was deleted (including who and when it was done)
IAuditable Interface. I am using this guy to allow each type to “opt-in” to the auditing mechanism.

AuditIgnoreAttribute. I am using this to “opt-out” on a field by field basis of the auditing mechanism.

So now when I create my business object, I can mark him up appropriately depending on the requirements for that type. As you can see I want to audit my customer object, but not the Bio property.

Great now for the magic, the AuditableContext. This guy inherits from a normal DbContext, and overrides the SaveChanges method to add the auditing implementation. The auditing implementation is done in 5 steps:
- Figure out what the user changed and hang on to those changes for later
- Update the CreatedBy, CreatedOn, UpdatedOn, UpdatedBy columns as appropriate
- Perform a SaveChanges to write the users changes to the DB
- Update our list of user changes with the proper id’s (we need to do this because the data base is assigning the primary keys for our new entities)
- Save the list of user changes to the log table


That code should be straight forward. I did implement a helper method that figures out what fields we are interested by using a bit of reflection. NOTE: we are doing the reflection once per type and caching the results in a dictionary.

We only need to implement the AuditableContext once, each time we create a context in our app, we just inherit from it and we are off and to the races!

You can download a full working example from here
Happy Coding!
I had a great time at the event today and wanted to thank a few folks that helped make this event:
What is next? How about the Kinect? http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/
Last night at the Dallas .NET UG (http://www.ddnug.net/) Corey Smith (http://addressof.com) demoed a between extension method in VB.NET. I threw together this version for C# for your enjoyment 

All it is doing is wrapping the built in Where LINQ method . . .
As you can see that it will work on any type that implements IComparable (http://msdn.microsoft.com/en-us/library/system.icomparable.aspx). IComparable is used in .NET for ordering and sorting, just what we need!
Here is how you would call him:

As you can see there is an optional parameter at the end, so you can select if you want an inclusive or exclusive between (i.e. inclusive says we should return 10 & 20 in the results and exclusive says we should not). I defaulted it to true since that is the behavior of SQL Server (http://msdn.microsoft.com/en-us/library/ms187922.aspx)
Happy coding!
Many times you want to seed data into your DB but don’t want to put all that seed data into your code files, or perhaps you want to add stored procedures, triggers or make other database changes after code first creates your database. While I would argue that the latter impacts one of the “goals” of EF Code First (i.e. centralizing your business logic in one spot), I can see where it might have value. So lets see how we can achieve this mission.
Lets start by creating our data objects. I am going to create a simple object “Tweet”:

Great now Lets wire it up to our DbContext:

You will see that my “SetInitializer” creates a special ContextInitializer. I borrowed this idea from Julie Lerman’s blog post on seeding data (http://thedatafarm.com/blog/data-access/seeding-a-database-with-ef4-code-first/). Lets take a look at the code in that guy:

As you can see we inherit from the “CreateDatabaseIfNotExists<T>” object. This means that EF Code First will only touch database schema if the database is totally dropped. Preventing any unintended accidental database modifications. In the seed method you see that I query the file system for all files that end in .sql, sort them alphabetically (so we can control the order that they are applied to our new database). Then one by one execute them against the context. Great now I can write seed files, stored procedures, triggers or whatever else I want in standard .sql files, and Code First will take care of applying them when it creates the database.
Here is an example of some .sql files for our little Twitter clone:

Nothing all that interesting, except for the naming convention. By placing the numbers in front I can control the order that they get executed against the database.
One last note, I think using EF Code First to “generate” your database for dev/test/qa environments is a great idea. This allows all development and testing to work against a “known”, “common” database state that is easily re-creatable. I am not quite sold on using it to generate the db in production. IMHO when it comes time to migrate to production you can use one of the many database schema diff tools (VS Data Dude, Red Gate, etc.) and prepare delta scripts to “Alter” the production DB to match the test/qa server, and tightly control what gets moved to production and when.
Stumbled across this during a discussion of RIA services today. . . .
Apparently in VB you can have the “partial” modifier on only 1/2 of a partial class. However in C# you are required to put the partial modifier on both halves of the class. I will let you guys argue about what way is better. . . . I think that both have merits. . .

Playing with the WCF REST Template today (http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd). Good Stuff.
When you create a new project with the template it gives you a service called “Service1” we are going to use this guy with 1 minor change. In the “Create” method set it to echo back the object that was passed to it.
[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
return instance;
}
Ok now lets get to the meat of it and write the client
WebClient client = new WebClient();
string uri = "http://localhost.:9309/Service1/";
string data = "<SampleItem xmlns=\"http://schemas.datacontract.org/2004/07/WcfRestService2\"><Id>2147483647</Id><StringValue>String content</StringValue></SampleItem>";
client.Headers.Add("Content-Type", "application/xml");
var response = client.UploadString(uri, "POST", data);
Console.WriteLine(response);
Console.ReadKey();
I got the contents of the data string by looking at the “help” provide by the service. You can see this if you append “help” to your services URL. In my case that was http://localhost.:9309/Service1/help”. Don’t forget to add the appropriate content type. Finally upload the string and capture the response. . . that is it!
BONUS: if you want to create the XML request without the “uber-string” try this on for size. . . .
//create the xml request document
XNamespace ns = "http://schemas.datacontract.org/2004/07/WcfRestService2";
XDocument doc = new XDocument( new XElement(ns + "SampleItem", new XElement(ns + "Id", "2147483647"), new XElement(ns + "StringValue", "String content") ));
Yes, even you can do them Robert. . . . .
Step 1: use this (http://vectormagic.com) website to convert your PNG to a PDF
Step 2: rename the .PDF to .AI
Step 3: open in Expression Design and export as XAML
As you might know I have been working on the UserGroup.tv website, and I am using the new free Open Source Content Management System from Microsoft, Orchard (http://www.orchardproject.net). Noticed the other day that they have released version 1.2 and I was running 1.1, I thought to myself, self I should upgrade.
1) First things first, time to back up my local environment. I keep a copy of the site running on my laptop. I use WebMatrix with IIS Express and a copy of SQL Server running locally to develop. So before doing anything I made a backup of my local database, and the folder with my project in it.
2) Next it was time to backup the production site, my hosting company has a button to create a backup of the production db so I used it. Then copied that backup down locally. Then just to make sure that my production environment and my dev environment were in sync, I downloaded the production site overlaying my local copy. Restored the production database locally, and updated the connection string in my local copy of Orchard to point at the new database (look in the App_Data/Sites/Default/Settings.txt folder).
3) Ok, now that I am sure I got a copy of my production site running locally without any issues it is time to pull the trigger. I downloaded the latest copy of Orchard, unblocked the zip file, unzipped it into my local folder that contained the copy of my production code.
4) Now time to test, open WebMatrix fire up IIS Express and ensure that everything is working fine.
5) For me everything worked out of the box, no issues, time to go to production!
6) Now I just need to FTP up the files (without the App_Data folder) to my production site, and test everything one more time.
Total time to complete the upgrade, eat breakfast, and write this article 30 min. #winner
Was asked to put together a quick and dirty sample of doing a join in LINQ. . . .
Here are some setup classes that I am going to use:
1: public class MyDto
2: {
3: public int CustomerId { get; set; }
4: public string CustomerName { get; set; }
5: public string ItemId { get; set; }
6: public string ItemName { get; set; }
7: public float Amount { get; set; }
8: }
9:
10: public class SalesPrice
11: {
12: public int CustomerId { get; set; }
13: public string ItemId { get; set; }
14: public float Amount { get; set; }
15: }
16:
17: public class Customer
18: {
19: public int CustomerId { get; set; }
20: public string CustomerName { get; set; }
21: }
22:
23: public class Item
24: {
25: public string ItemId { get; set; }
26: public string ItemName { get; set; }
27: }
First I am going to fill the objects with some dummy data:
1: List<SalesPrice> prices = new List<SalesPrice>()
2: {
3: new SalesPrice() {CustomerId = 1, ItemId = "A", Amount = 5},
4: new SalesPrice() {CustomerId = 2, ItemId = "B", Amount = 10},
5: new SalesPrice() {CustomerId = 3, ItemId = "C", Amount = 15},
6: new SalesPrice() {CustomerId = 4, ItemId = "D", Amount = 20},
7: };
8:
9: List<Customer> customers = new List<Customer>()
10: {
11: new Customer() {CustomerId = 1, CustomerName = "Sam"},
12: new Customer() {CustomerId = 2, CustomerName = "Sally"},
13: new Customer() {CustomerId = 3, CustomerName = "Joe"},
14: new Customer() {CustomerId = 5, CustomerName = "Bill"}
15: };
16:
17: List<Item> items = new List<Item>()
18: {
19: new Item() {ItemId = "A", ItemName = "Fork"},
20: new Item() {ItemId = "B", ItemName = "Knife"},
21: new Item() {ItemId = "C", ItemName = "Teddy"},
22: new Item() {ItemId = "F", ItemName = "Ball"}
23: };
Now lets do a regular join:
1: var results1 = from p in prices
2: join c in customers
3: on p.CustomerId equals c.CustomerId
4: join i in items
5: on p.ItemId equals i.ItemId
6: select new MyDto()
7: {
8: CustomerId = p.CustomerId,
9: ItemId = p.ItemId,
10: Amount = p.Amount,
11: CustomerName = c.CustomerName,
12: ItemName = i.ItemName
13: };
Note that we are missing one of our SalesPrices, depending on your business rules this might be bad, very bad. . . . . how about an outer join
1: var results = from p in prices
2: join c in customers
3: on p.CustomerId equals c.CustomerId into priceCustomer
4: from pc in priceCustomer.DefaultIfEmpty()
5: join i in items
6: on p.ItemId equals i.ItemId into priceItems
7: from pi in priceItems.DefaultIfEmpty()
8: select new MyDto()
9: {
10: CustomerId = p.CustomerId,
11: ItemId = p.ItemId,
12: Amount = p.Amount,
13: CustomerName = pc == null ? string.Empty : pc.CustomerName,
14: ItemName = pi == null ? string.Empty : pi.ItemName
15: };
Great now we got everything! Hope this helps you, perhaps more important it is going to help me when I forget next week. 
An oldie but a goodie. I like the technique that “arjay” outlined in his codeguru post (http://www.codeguru.com/forum/showthread.php?t=441772). However he noted a problem with the arrays that XSD.exe creates, namely you have to check for null every time you want to iterate over them. In the post he suggests hand editing the generated code. I am not a big fan of that. You can easily use a partial class to avoid needing to hand edit the code. Or you can use an extension method to encapsulate the check for you.
public static List<T> ToNonNullList<T>(this T[] items)
{
if (items == null)
return new List<T>();
return items.ToList();
}
BONUS:
So how do you get the xml in the first place, perhaps you have it in a string, or it might be coming from an URI. How about a little helper class that will Deserialize it for us. . . .
public class XSerializer
{
public static T Load<T>(string uri)
{
return LoadParse<T>(XDocument.Load(uri));
}
public static T Parse<T>(string xml)
{
return LoadParse<T>(XDocument.Parse(xml));
}
private static T LoadParse<T>(XDocument xDoc)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (XmlReader reader = xDoc.CreateReader())
{
return (T)serializer.Deserialize(reader);
}
}
}
Issue:
After installing a SharePoint Update and running the Configuration Wizard you may notice that the User Profile Synchronization Service Application has stopped. Attempts to restart the User Profile Synchronization Service Application may prove unsuccessful.
Symptoms:
1) The User Profile Synchronization Service Application Fails is stopped and fails to restart
2) The following errors appear in the Event Viewer:
a. Detection of product '{90140000-104C-0000-1000-0000000FF1CE}', feature 'PeopleILM' failed during request for component '{1681AE41-ADA8-4B70-BC11-98A5A4EDD046}'
b. Detection of product '{90140000-104C-0000-1000-0000000FF1CE}', feature 'PeopleILM', component '{1C12B6E6-898C-4D58-9774-AAAFBDFE273C}' failed.
The resource 'C:\Program Files\Microsoft Office Servers\14.0\Service\Microsoft.ResourceManagement.Service.exe' does not exist.
Solution:
Give the Network Service account read/Execute permissions to the following folders:
\Program Files\Microsoft Office Servers\14.0\
\Service
\SQL
\Tools
Open Central Admin—>Application Management—>Manage Services on Farm—> Start the Profile Synchronization Service
Special Thanks to Greg Carter (HoganTaylor)
So I work from home. I also have a running machine. I haven't been running in a while because a) running is hard and b) everything has been packed away from moving around last year.
Well, the moves are over, everything is long since done and it's a holiday today (MLK) so the banks (one of which I work for) is closed. So today I got my gym room all fixed up. Setup the weights, positioned the treadmill so it's usable, etc etc. Now I need to be able to use my laptop while I am on it during the day. My first instinct was to look for a stand online. However, I had just got done actually using the machine and while on it I was listening to a TED talk about building houses (among other things) out of recycled materials. I did this with my laptop pedestal so it seemed like a logical fit. And why not?
So I used to use my laptop on here, but there was nowhere for the mouse, and you could prop the laptop on a groove on the machine control area. This works, but typing is at an angle. So that sucks. I was prepared to go to home depot and just buy some piping and maybe some other stuff to make something to kinda attach to the arms where you can hold on. I won't need to hold on for working because I will just have it at a very mild walk to get some movement during the day. Since I saw the TED talk I thought to myself "ha, I bet I can make something if I just look around."
Here's what I found and what I used (and the order I needed them):
- 2 x Old Soda carrying plastic crates
- 2 x Old Boards (about 45" long)
- Duct Tape
- Velcro
- Old notebook
That's it. Here's how I made it:
- Cut up the old crates because they had little Y grooves which helped them slide together, and also helped them slide right onto the place where you could hold on. Found my base yay! I cut these up so that I could slide all the Y portions together but since the hand rails sloped a little, I needed to be able to raise the front a little so it would be flat(ish). Problem solved, I just used an extra stack in the front and it all worked great.
- Now I had the base, I just needed something to put it on. I was thinking about going to the store and just buying a board, but then I noticed I had two smaller 1x4 boards left over from some work doing trim on the outside of the house. Perfect! So I set them on top of the crates once they were positioned, and cut the ends off some. The ends I then I put between them and I just duct taped them together. I sat around and pondered some better ways to lash them together, but then I realized that the simplest way was to just duct tape them really tightly. It worked like a champ. Now I had my board
- So now I needed a way to attach my board to the arms. I had originally thought maybe I would get a long threaded piece of metal and cut it to fit and use some nuts and washers and a hole in the board to bold the whole thing together. But that just seemed like overkill and would require a trip to the store. I had some bolts so I could bolt to the top, but that seemed like a little bit of overkill too for something so cheap and simple. Then I spied the magic solution sitting over with some old wires. Velcro! So I had one old piece of industrial strength Velcro. I dunno what that means, but I think it cost me like 10 bucks for the pack back when I got it. This was just a scrap. So I split the rough part in half just by making a small cut and tearing it down the middle. Then I put duct tape over the tops of old crates because they were full of holes. This would give something for the Velcro to stick to. Then I put on a strip for each side. After that I put a small piece of the soft stuff up towards the machine. This gave me more leverage to just pick it up when I wanted to take it apart and seemed to work well. You could add more if you wanted it to *really* stay put, but I just needed it not to move for the most part and this did the trick.
- Now it was all assembled. My victory was almost complete. I needed a place for the mouse. I toyed with the idea of stapling some old cardboard to the top (there are spaces between the boards after all. Or maybe going to the store again. Not sure why I hadn't learned to not think of that yet. =P Finally I came up with the idea of just using an old notebook I got from a trade conference years ago. It's got really thick top and bottoms so it works great. I just sit it there, but you could fasten it down if you wanted it more permanent.
- Profit!
That's it. Total cost was really just the price of using old stuff and about an hour of my time. If you had to buy stuff, then not free, but you could make something identical with just some pipe and some Y screws for walls and a board and some screws to screw that in really easily. But free is better. Here are some pictures. =)
Here are the old crates. Some of them cut up.
Here is the assembled board being placed down. You can see the duct tape holding the two boards and a block from the end of each to expand the width of the board. You can see the long strip of Velcro and the little strip in the back to keep everything in place. You can also see the crates simply wedged onto the bars.
Here you can see it with the top down and the machine visible. The old notebook is also on there for the mouse.
And finally here are two photos of the final assembly. It works great. =) sides look a little weird because I didn't cut the crates straight, but that's easily fixable if I ever need to. I don't foresee it being an issue. Best part is it's really easy to just pick up and move if needed for actual running in the morning/evening.

Also, as a bonus, here is a picture of my super cheap pedestal I stand at to work during the day in the other room. It's just three 5 gallon paint buckets and one of those metal desk protectors. I think from IKEA.
If you are at all familiar with me you know that over the past decade or so I have been a big advocate of INETA. I was a firm believer in their mission to use national influence to support local Microsoft development communities.
A few weeks ago I had received a phone call notifying me that I have been removed from the board.
Here is the announcement that they made in the INETA Newsletter:
“In November the board voted to make some structural changes, reducing the number of current director positions by two. We would like to thank Julie Yack and Shawn Weisfeld for all of their contributions to INETA during their time on the board, and as volunteers in the organization.” (see full email here http://bit.ly/iiJlW4)
I still do not understand why they felt it was necessary to remove me, and undertake this restructuring.
However, in an effort to follow the will of the board I have handed over the reins of the programs that I had started/restarted and operated (INETA Live and Community Champions). Additionally, on a going forward basis I will no longer be involved in the operations or running of these programs or with INETA as a whole.
It saddens me that the board has made this decision, I do not feel that it is in the best interest of the community or INETA as a whole. However it was there decision to make and I am going to move on with my life.
If you know me, you know that I cannot sit still for long. I am working on some ideas on what my next project is going to be. So stay tuned to my blog for more information.
Thanks to all those who attended.
If you know me I have been very involved in the recent re-launch of INETA Live (http://live.ineta.org). With the updated site one of the features we added as an OData feed, and while watching Pablo Castro’s PDC Talk the other day I was surprised to see the INETA Live logo right next to all the big dogs. Big thank you to Pablo and all the folks of the data team!
You can catch Pablo’s talk here http://bit.ly/bqQYL4 and as always all the great INETA Live content can be found at http://live.ineta.org.

Another in the series of recordings that I have done for INETA live.
Abstract:This month's presentation we have something for everyone. I am speaking at a couple of events in Arkansas and I thought it would be fun to present the hightlights from each of my talks at my own user group. 1) Adding MVC to a Web Forms Application: In this presentation I will show you how to add MVC to an existing web forms application. 2) jQuery Essentials: In this presentation I cover selectors, filters, effects, properties, writing extensions, AJAX, and the new jQuery templating. 3) What's New in Enterprise Library 5.0: The Enterprise Library has been completely rewritten. In this presentation I describe the changes and demonstrate the new features in the Data Access Application block that allow you to retrieve data as objects and to perform asynchronous data access.