The mysteries of software development and networking... RSS 2.0



 Sunday, January 13, 2008

In the .NET Framework, most of the time, the name of an assembly matches the namespace of the classes in that assembly.

Since WCF is kind of an add-on to the .NET 2.0 Framework this is not quite true for the assembly System.ServiceModel.Web.dll

Below a screenshot of what .NET Reflector shows to be inside this assembly.

As you can see this assembly extends a number of namespaces like System.Runtime.Serialization and System.Collections.ObjectModel.

The Json serialization classes are also in this assembly.

Sunday, January 13, 2008 10:42:42 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
.NET | WCF
 Friday, January 11, 2008

Okay, so I'm having a carstarter installed in my car and obviously have nothing better to do than keep tinkering with this DSL stuff.

So I'm thinking... If we create a DSL for the person writing the code, then the debug experience should also be DSL-like. Now I'm not about to write my own debugger, but instead of showing a plain DateTime (what kind of datatype is that anyway?!?!?) we're talking animals, persons and real 'talk' date of birth stuff here.

So I create a special DateOfBirth class which overrides the ToString() method and this creates a 'pretty' experience in my debug window. Notice the values for DateOfBirth. This could ofcourse be extended to person, which is still displayed as the same old school type information: 'DSL.Person'.

The complete code comes at the end of this post, but lets have a look at te code complexity when going from

Person p = new Person();
p.DateOfBirth = new DateTime(1972,9,25);

to our DSL :-)

I guess the code is not too bad. Visual Studio still scores it green on the maintainability scale, but it is clear that quite a large amount of code is needed to create a DSL. And DSL's like this get more context sensitive. Imagine if I would also like to support birds with my DSL? Birds get hatched not born. I'd have to expand my extensions class, or maybe create a whole new set of classes and methods, having a class 'HatchedOn'.

Anyway, they just called, my car is done.

Here is the code for the final sample:

namespace DSL
{
    class Program
    {
        static void Main(string[] args)
        {
            Person mark = Person.Named("Mark").BornOn(Day.the25th).Of(Month.September).InTheYear(1972);
            Animal watson = Animal.Named("Watson").BornOn(Day.the2nd).Of(Month.January).InTheYear(2001).AndItIsA(Animal.KindOf.Dog);
        }
    }


    public class DateOfBirth
    {
        public int Year;
        public Month Month;
        public Day Day;

        public static implicit operator DateTime(DateOfBirth dob)
        {
            return new DateTime(dob.Year, (int)dob.Month, (int)dob.Year);
        }

        public override string ToString()
        {
            return "Born on " + Day.ToString() + " of " + Month.ToString() + " in the year " + Year.ToString() + ".";
        }
    }

    public enum Day : int
    {
        the1st = 1,
        the2nd = 2,
        the25th = 25
    }

    public enum Month : int
    {
        January = 1,
        February = 2,
        September = 9
    }

    public interface IDateOfBirth
    {
        DateOfBirth DateOfBirth { get; set; }
    }

    public class Person : IDateOfBirth
    {
        public DateOfBirth DateOfBirth { get; set; }
        public string Name { get; set; }

        public static Person Named(string name)
        {
            Person p = new Person(name);
            p.DateOfBirth = new DateOfBirth();
            return p;
        }

        protected Person(string name)
        {
            Name = name;
        }
    }

    public class Animal : IDateOfBirth
    {
        public enum KindOf
        {
            Dog,
            Cat
        }

        public DateOfBirth DateOfBirth { get; set; }
        public string Name { get; set; }
        public KindOf KindOfAnimal { get; set; }

        public static Animal Named(string name)
        {
            Animal animal = new Animal();
            animal.Name = name;
            animal.DateOfBirth = new DateOfBirth();
            return animal;
        }
        public Animal AndItIsA(KindOf kind)
        {
            KindOfAnimal = kind;
            return this;
        }
    }


    public static class DateOfBirthExtensions
    {
        public static T BornOn<T>(this T p, Day day) where T : IDateOfBirth
        {
            p.DateOfBirth.Day = day;
            return p;
        }

        public static T Of<T>(this T p, Month month)  where T : IDateOfBirth
        {
            p.DateOfBirth.Month = month;
            return p;
        }

        public static T InTheYear<T>(this T p, int year)  where T : IDateOfBirth
        {
            p.DateOfBirth.Year = year;
            return p;
        }
    }

}

 

Friday, January 11, 2008 8:48:37 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C#

I've decided working with enumerations beats working with generics. So now I've taken my little DSL experiment back to enumerations and started implementing the DateOfBirth DSL as a generic extension method.

Since the compiler infers the type based on the actual parameters used you don't need to supply the type when using the extensions methods. Very cool!

Now my DateOfBirthExtensions can work on anything that implements the IDateOfBirth interface, be it a person or an animal :-)

 

namespace DSL
{
    class Program
    {
        static void Main(string[] args)
        {
            Person mark = Person.Named("Mark").BornOn(Day.theTwentyFifth).Of(Month.September).InTheYear(1972);
            Animal watson = Animal.Named("Watson").BornOn(Day.theSecond).Of(Month.January).InTheYear(2001).AndItIsA(Animal.KindOf.Dog);
        }
    }

    public enum Day : int
    {
        theFirst = 1,
        theSecond = 2,
        theTwentyFifth = 25
    }

    public enum Month : int
    {
        January = 1,
        February = 2,
        September = 9
    }

    public interface IDateOfBirth
    {
        DateTime DateOfBirth { get; set; }
    }

    public class Person : IDateOfBirth
    {
        public DateTime DateOfBirth { get; set; }
        public string Name { get; set; }

        public static Person Named(string name)
        {
            Person p = new Person(name);
            return p;
        }

        protected Person(string name)
        {
            Name = name;
        }
    }

    public class Animal : IDateOfBirth
    {
        public enum KindOf
        {
            Dog,
            Cat
        }

        public DateTime DateOfBirth { get; set; }
        public string Name { get; set; }
        public KindOf KindOfAnimal { get; set; }

        public static Animal Named(string name)
        {
            Animal animal = new Animal();
            animal.Name = name;
            return animal;
        }
        public Animal AndItIsA(KindOf kind)
        {
            KindOfAnimal = kind;
            return this;
        }
    }


    public static class DateOfBirthExtensions
    {
        public static T BornOn<T>(this T p, Day day) where T : IDateOfBirth
        {
            p.DateOfBirth = new DateTime(p.DateOfBirth.Year, p.DateOfBirth.Month, (int)day);
            return p;
        }

        public static T Of<T>(this T p, Month month)  where T : IDateOfBirth
        {
            p.DateOfBirth = new DateTime(p.DateOfBirth.Year, (int)month, p.DateOfBirth.Day);
            return p;
        }

        public static T InTheYear<T>(this T p, int year)  where T : IDateOfBirth
        {
            p.DateOfBirth = new DateTime(year, p.DateOfBirth.Month, p.DateOfBirth.Day);
            return p;
        }
    }

}

Friday, January 11, 2008 7:55:53 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C#

Inspired by Pinku Surana's blog about DSL's and after reading the presentation from Neal Ford I felt compelled to experiment with a little DSL style programming.

My goal was to get as close as possible to something like:

Person mark = Person.Named("Mark").BornOn(theTwentyFifth).Of(September).InTheYear(1972);

As it turns out the linking of methods is pretty easy. Where you might be inclined to create a property, just create a method which returns the base object, in this case Person.
The hardest part I found was trying to come up with something decent for 'theTwentyFifth' and 'September'. My first try was to create enumerations, but then you have to name the enum and you get something like:

Person mark = Person.Named("Mark").BornOn(Day.theTwentyFifth).Of(Month.September).InTheYear(1972);

Which is good because the intellisense in C# is great, but having to prefix it messes it up just a little. An Alternative implementation is to 'abuse' generics and do it like this:

Person mark = Person.Named("Mark").BornOn<theTwentyFifth>().Of<September>().InTheYear(1972);

The draw back to this is that intellisense is less useful and it is messy to be using generics for BornOn and Of, but not for InTheYear.
The implementation is below. I'm still thinking about which solution is more useful.


namespace DSL
{
    class Program
    {
        static void Main(string[] args)
        {
            Person mark = Person.Named("Mark").BornOn<theTwentyFifth>().Of<September>().InTheYear(1972);
        }
    }

    public abstract class CalenderMonth
    {
        public int Month { get; private set; }

        protected CalenderMonth(int month)
        {
            Month = month;
        }
    }

    public class September : CalenderMonth
    {
        public September()
            : base(9)
        {
        }
    }


    public abstract class DayOfMonth
    {
        public int Day { get; private set; }

        protected DayOfMonth(int day)
        {
            Day = day;
        }
    }

    public class theTwentyFifth : DayOfMonth
    {
        public theTwentyFifth()
            : base(25)
        {
        }
    }

    public class Person
    {
        DateTime _dob = new DateTime();
        string _name;


        public const int theFirst = 1;
        public const int theTwentyFifth = 25;

        public static Person Named(string name)
        {
            Person p = new Person(name);
            return p;
        }

        protected Person(string name)
        {
            _name = name;
        }

        public Person BornOn<T>() where T : DayOfMonth, new()
        {
            T d = new T();
            _dob = new DateTime(_dob.Year, _dob.Month, d.Day);
            return this;
        }

        public Person Of<T>() where T : CalenderMonth, new()
        {
            T m = new T();
            _dob = new DateTime(_dob.Year, m.Month, _dob.Day);
            return this;
        }

        public Person InTheYear(int year)
        {
            _dob = new DateTime(year, _dob.Month, _dob.Day);
            return this;
        }
    }

}

 

Friday, January 11, 2008 7:24:33 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C#

If you want to dynamically want to load a form and you only know the classname then the following snippet may be of use:

Type t = Type.GetType("ConsoleApplication1.Form1");
if (t != null)
{
    System.Windows.Forms.Form f = (System.Windows.Forms.Form) Activator.CreateInstance(t);
    f.ShowDialog();
}

Now, if you'd want to load the form from a different assembly, let's say, some library assembly with forms, then you need to specifiy an AssemblyQualifiedName.

Like:

Type t = Type.GetType("ClassLibrary1.Form1, ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
if (t != null)
{
    System.Windows.Forms.Form f = (System.Windows.Forms.Form)Activator.CreateInstance(t);
    f.ShowDialog();
}

This will dynamically load the form and show it. So no compiletime binding needs to be done.

 

Friday, January 11, 2008 10:33:31 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C#

The other day I was playing around with WPF in Visual Studio 2008 and I stumbled across some strange behaviour. I made a mistake in the XAML of a WFP Window.

<Button Background="LightBlueX" Name="button1" Click="button1_Click">Click here</Button>

As you can see the name of the Background color is not valid. Now as long as you have the Window opened in the designer the errorlist will display an error to inform you about the mistake. However, if you try and compile your project, you'll find that the compiler will succesfully build. Then when you run the application you'll get a runtime error (a XAML parse exception). Thinking this to be an error in the compiler I logged a bug on MSConnect.

I received the following feedback:

Hi Mark

Thanks for your report. The behavior you're reporting is actually by-design - it arises because of a trade off of complexity/performance in the build/compilation process vs surfacing all possible failures at compile time.

Errors in XAML attribute values like the one mentioned in the bug are one of the class of errors that can't be picked up with certainty by the build process without loading the entire context of the WPF application being built - this is too heavy an overhead to impose on the compilation process and would cause a major performance degradation in building.

The expected process is that the user will use the designer (which of necessity loads a lot more of the context) to locate and eliminate errors of this sort. Hence the fact that the errors list shows the error as described in the repro steps.

Thanks for taking the time to submit the issue - I hope you continue to find the designer useful and would welcome any further feedback you have.

Mark Wilson-Thomas
Program Manager
WPF Designer Team, Developer Division

Ok, that clarifies things. I'll get into the habit of checking my errorlist before saving a XAML file.

Friday, January 11, 2008 7:16:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [3] -
WPF

Maine is getting another .NET User Group and this one is actually close to where I live,yeah!!!

The B.A.N.D. (Bangor Area .NET Developers) will meet monthly. More info at: http://www.bangordevelopers.com.

Friday, January 11, 2008 6:54:15 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Thursday, January 10, 2008

I'm beginning to appreciate the power of extension methods. At first I thought: "Who wants this?". Doesn't this 'break' the encapsulation of object oriented programming?

Well yes it does, but it makes for some darn pretty code when building utility methods. Right now I'm working on some stuff with the DataContractJsonSerializer and this class has a ReadObject method which takes a stream as a parameter. When writing unit test (and regular code) I'm quite frequently going from a string to a stream. So I figured I'd create an extension method called ToMemoryStream(). This is what is looks like:

using System;
using System.IO;

namespace DevelopOne.Framework.Serialization
{
    /// <summary>
    /// Class with extension methods which are helpful when working
    /// with serialization.
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Converts a string to a memory stream and sets the position of the stream to
        /// the beginning of the stream.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static MemoryStream ToMemoryStream(this string s)
        {
            MemoryStream ms = new MemoryStream();
            byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(s);
            ms.Write(bytes, 0, bytes.Length);
            ms.Position = 0;
            return ms;
        }
    }
}

Now calling this method can be done by simply including the namespace DevelopOne.Framework.Serialization and calling ToMemoryStream() on a string.

Like this:

string json = "{\"exceptions\":[{\"type\":\"ExceptionObject\",\"errorMessage\":\"Calls to member.login must be secure.\",\"errorInfo\":null,\"errorCode\":513}]}";
MemoryStream ms = json.ToMemoryStream();

 

 



The best web hosting service is the one that not only provides cheap web hosting, but comes with perks like email hosting as well. This and the added benefits of hosting more than one domain names of course adds to the entire package. Thanks to the extensive promotion of online marketing, now anyone with access to computers knows of this. This has contributed effectively to the popularity of home business setups as well.

Thursday, January 10, 2008 8:09:58 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C#
 Tuesday, January 08, 2008
Tuesday, January 08, 2008 12:02:51 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Thursday, January 03, 2008

Roger Sessions writes about an interesting concept called SIP (Simple Iterative Partitions) in this month's ObjectWatch newsletter. He says CIO's will fail their 2008 objectives because they are unable to focus on the underlying problem that IT is facing these days, which according to him is: complexity.

I've seen quite a few project fail by having too large a scope and thus becoming way too complex, leading to project failure. So reducing complexity will lead to a higher project succes rate and thus helps you reach your goals.

The example Roger uses in his newsletter is a little flawed though. Roger assumes any system of 7 (or 14) dice can be split in 7 partitions which do not influence eachother. Reality will be that the succes or failure of any of the 7 partitions will influence the succes of the others. And unlike dice there is no black/white success with IT projects. Succesful projects typically achieve somewhere between 70 to a 100% of their original goals. 1% of a missed goal in one of the 7 partitions may lead to 100% failure in another (extreme case).

I'll be doing some more reading on the SIP proposition though. More on SIP here.

 

 



Services like cingular wireless have contributed a lot to the promotion of personal web hosting. Not that web site hosting was not happening before, but never had internet advertising been this sort of a giant. Now from laymen to professional webmasters, all know about seo, about sem strategies like ppc advertising and the list can go on. The internet marketing arena is expanding everyday.

Thursday, January 03, 2008 8:30:21 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Architecture
 Tuesday, January 01, 2008

Hurray! What a great way to start the new year. I got an email this morning informing me I've been awarded the MVP award for the fifth year running.

Congratulations! We are pleased to present you with the 2008 Microsoft MVP Award! The MVP Award is our way of saying thank you for promoting the spirit of community and enhancing people’s lives and the industry’s success every day. Your extraordinary efforts in Visual Developer - Visual C# technical communities during the past year are greatly appreciated.

Thanks to Microsoft, and in particular Rafael Munoz, for the award. Excellent!

Tuesday, January 01, 2008 2:25:47 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Saturday, December 22, 2007

The TFS MSSCCI Provider enables integrated use of Team Foundation Version Control with products that do not support Team Explorer integration. This will allow you to connect to TFS2008 from Visual Studio 2003. This is very useful if you still have .NET 1.1 projects around that need maintenance using VS2003, but you want to use a single source control solution.

Download here.

Saturday, December 22, 2007 2:54:48 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Team System
 Friday, December 21, 2007

VS2008 hasn't even been fully launched yet and already the add-ons are becoming available through the VSTS 2008 Power Tools. These power tools are very handy and also offer some bugfixes so you don't have to wait for a service release.

New in this release of the power tools:

  • Find in Source Control tool is an addition to the Team Explorer menu that provides the ability to locate files and folders in source control by the item’s status or with a wildcard expression.
  • Open a selected folder in Windows Explorer straight from Team Explorer. This feature allows you to jump straight to the mapped folder location from within Source Control Explorer.
  • Quick Label feature that allows labels to be easily applied to a given selection of files and folders in the Source Control Explorer.
  • Build Notification tool that runs in the Windows task bar notification area monitoring the status of the build definitions you have specified. It can be configured to show notifications when builds are queued, started, or completed for multiple build definitions spanning multiple Team Foundation Servers.
  • Additional TFPT.EXE commands for configuring Team Explorer connection settings (tweakui) and for  destroying Work Items and Work Items Type Definitions (destroyWI, destroyWITD).
  • Updates to the TFS Best Practices Analyzer for use with a Visual Studio Team System 2008 Team Foundation Server deployment.
  • The Process Template Editor is updated for use with Visual Studio Team System 2008 Team Foundation Server. It also has several improvements, including: the ability to launch standalone w/o a Visual Studio installation, performance improvements, improved discoverability and bug fixes.
  • Bug fixes and removal of Power Tools that are now included within Team Foundation Server: 
    • Annotate and Treedif are now included in Visual Studio Team System 2008 Team Explorer; however, Annotate remains is still available in the command-line tool (TFPT.EXE).
    • TestToolsTask is included in Visual Studio Team System 2008 Team Foundation Server as part of Team Foundation Build.

 

 



With certifications like 70-620 and 70-291 on ones credit, one can easily go for 646-171. In fact, even 642-825 is not difficult for such people. However, exams like 640-863 and 350-001 require much more preparation time and effort, than that required for a basic exam like 1z0-042.

Friday, December 21, 2007 3:39:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Team System
 Wednesday, December 19, 2007

My article on the AOL Developer Network about how I created the NFL Video of the Day gadget for Windows Vista went live last week.

Download the gadget here.

Wednesday, December 19, 2007 12:10:24 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
AOL | Vista
 Thursday, December 06, 2007

I just created my first PopFly mashup.

Thursday, December 06, 2007 8:33:09 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Tuesday, December 04, 2007

Last month Russ Fustino did a presentation in Portland, ME where he showed a little tool to grab areas of the screen. I looked on his blog, but could not find a link to this particular tool, but a little Googling did the trick.

Screen Grab Pro is a very nice (FREE) tool from Traction Software that allows you to easily grab a region on the screen and save it as a file, or paste it in a Word document.

Update: Windows Vista also offers a build in tool called 'Snipping Tool'. On some machines this tool does not get installed by default, read more on the Snipping Tool here (thanks Marcel!).

Tuesday, December 04, 2007 2:23:56 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1] -
General

Online video services like YouTube and AOL Video may appear to be a global phenomenon, but when you try and view some of the higher quality videos you'll find that the ad-riddled Flash wrappers around the movies contain DRM which implements region encoding. Today I emailed Amazon support because I purchased a couple of episodes of Shark while I was at the airport in the States, waiting for my flight to Amsterdam. All was well, and I downloaded 2 out of 5 episodes, the last three were queued since I had to get on the plane. After reaching the Netherlands I discovered that Amazon Unbox refused to let me download the remaining three episodes since my IP-address is showing that I'm no longer within the US. When is the video industry going to discover that region encoding is a bad idea?!?!

 

Tuesday, December 04, 2007 2:17:26 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Monday, December 03, 2007

During our usergroup meeting last week the topic of 'materialized views' in Oracle came up. I wasn't familiar with the term, but John looked it up for me (thanks John!).
Materialized Views in Oracle seem to differ in implementation, but accomplish much the same as Index Views in SQL Server.

More on Materialized Views:
http://en.wikipedia.org/wiki/Materialized_view

More on Indexed Views:
http://www.microsoft.com/technet/prodtechnol/sql/2005/impprfiv.mspx

 

Monday, December 03, 2007 2:27:44 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
SQL
 Sunday, December 02, 2007

With all the excitement about .NET Framework 3.5 and Visual Studio 2008 being release you might almost miss the release of .NET Framework 2.0 Service Pack 1.

It can be downloaded here (x86) and here (x64).

Microsoft .NET Framework 2.0 Service Pack 1 provides cumulative roll-up updates for customer reported issues found after the release of Microsoft .NET Framework 2.0. In addition, this release provides security improvements, and prerequisite feature support for .NET Framework 3.0 Service Pack 1, and .NET Framework 3.5.

 

Sunday, December 02, 2007 2:09:38 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General

Amazon Unbox is an online video service, allowing you to download videos to your laptop. As a frequent traveller I've started using this service recently and am extremely pleased with the quality of the video, the ease of use and availability of titles. I like to watch series (currently Shark season 2) and this is a great way for me to keep up with what I like to watch, even if I'm on the road. Episodes seem to appear on Unbox within a week, often one day, of airing on TV.

Wikipedia says:

Amazon Unbox is an Internet video on demand service offered by Amazon.com which according to their website is available to "U.S. customers located in the 48 contiguous states, Alaska, Hawaii, and the District of Columbia". The service became available on September 7, 2006 and offers television shows and films for rental and purchase from eight major television and film studios.[1] Rental pricing for feature length films range from $0.99 to $3.99, while television shows can be purchased for $1.99. Additional discounts are given for full season purchases. Downloaded films includes two versions of videos requested, a full resolution video file and a lower resolution copy for portable devices.

 

 



Maybe 70-291 is comparatively easier than 70-296, still, merely studying for 156-215 or 350-001 is not just enough to go for the latter certifications. Just in the way preparation material for 642-552 differs from that of 642-176 and cannot be used to go for a 350-030, same is the scenario in the previous case.

Sunday, December 02, 2007 6:57:20 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Amazon | General
About
This blog is run by Mark Blomsma.
© Copyright 2008
Develop-One
Sign In
Statistics
Total Posts: 337
This Year: 81
This Month: 0
This Week: 1
Comments: 94
All Content © 2008, Develop-One
DasBlog theme 'Business' created by Christoph De Baene (delarou)