Posts

Showing posts from August, 2010

Require comment / message on all SVN commits for Visual SVN Server

(I've been posting a lot the last few days!) Something that drives me nuts is not having a comment or message when looking at SVN history. It's impossible to know what went on. Even a bad comment is better than no comment. SVN hooks are a great way to solve this. If we make a pre-commit.bat file that checks the commit data for a comment, returns an error code of 1 if it wasn't found (with some text) or returns 0 if the comment is there. Check out the pre-commit hook that I found online (thanks, Anuj Gakhar!) or check out the hook below. @echo off setlocal rem Subversion sends through the path to the repository and transaction id set REPOS=%1 set TXN=%2 rem check for an empty log message svnlook log %REPOS% -t %TXN% | findstr . > nul if %errorlevel% gtr 0 (goto err) else exit 0 :err echo. 1>&2 echo A log message or comment is required to commit 1>&2 exit 1 This works perfectly except for 1 downfall -- you have to distribute it in every freakin

Using ref Keyword with Reference Types in C#

One of our developers was using the ref keyword in a method that needed to replace the value of a property of the method's parameter. In other words... public class Person { public int ID { get; set; } public string Name { get; set; } public string Email { get; set; } } public static class ReferenceExample { public static void Main() { var person = new Person { Name = "Mark", Email = "none@none.com", }; Save(ref person); Console.WriteLine(person.ID); Console.ReadLine(); } public static void Save(ref Person person) { person.ID = 1; // Pretend this saves to a database or something } } The thinking is correct. Person needs to be passed by reference. So why not use the ref keyword, right? Well...Person is already a reference type . So if we are just replacing properties, we don't need the ref keyword. Removing it changes nothing with ou

Get the name of a property as a string in C#

Another developer showed me something very useful with Expression Trees in C# (thanks, Pierre! Full credit goes to you). To show you the awesomeness of it all, let's start with a class called Person . public class Person { public string Name { get; set; } public string Email { get; set; } } Now let's say I have an instance of Person var person = new Person { Name = "mark kockerbeck", Email = "noneofyourbusiness@face.com", }; Imagine creating a Dictionary<string,string> of this particular Person's properties (e.g. "Name" and "Email") and the corresponding property values. We could easily do something like the following: var dictionary = new Dictionary<string, string> { { "Name", person.Name }, { "Email", person.Email }, }; But there is unnecessary redundancy and repetition in this. We have to say the property twice (and as a messy string no less!). Well, we could use reflection... var di

Service Cloud - dynamic calls to a cloud of WCF services

Image
For awhile, myself and another developer have been trying to build a working prototype of an idea he proposed for a Service Cloud. Essentially the Service Cloud is a collection of WCF services hosted on a number of servers and environments that can all communicate with one another via a common interface. An "application" would then be built by orchestrating these services together. Instead of the application adding service references for each of the services it needs -- it would simply send a request to the "Gateway" service and it would figure out the rest. It would call the other services. Finally, when the execution is complete and your request has bounced all over the cloud, you get a response that many services have built together. I finally was able to create a working prototype (albeit completely contrived). The Service Cloud prototype is available on GitHub, see: http://github.com/xeb/ServiceCloud . Client The client is simple. The client adds