Moved my blog!

Add Comment | Jul 08, 2009

Just wanted to say that all the posts I made in here have been moved to a new url, namely http://www.dotnetjack.com

This move will hopefully push myself to make more posts and do more crazy stuff to write about. Hopefully some of you out there will have a peek and again hopefully some of those will even come back or put it in their feed :)

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Beware of spacing in Windows7 hosts file

12 Comments | Jun 17, 2009

The hosts file of Windows, by default located in %SystemRoot%\System32\drivers\etc, can be a bitch to edit, so it seems.

I had an XP machine running just fine with the entries from my hosts file. I then made a Windows7 partition on the same machine, with the same entries in the hosts file. Didn’t work at all. It seemed as if the hosts file was completely ignored. So I did some searches on that and tried a lot of stuff. Even up to checking out the registry entry for the path, and the system variables, if they were set to correct values.

However, nothing seemed to work. Until I saw some other example hosts files that were formatted as <ip address><single space><value>

Notice the single space. In my own hosts file, all entries were nicely outlined by use of multiple spaces, to make it easier to read. So it seems now that in Windows7, unneeded whitespace is not thrown away anymore. Threw away the “markup whitespace” and everything worked in an instance.

I don’t have any clue on how many people use the hosts file intensively, but it might not be such a bad thing for the folks in Redmond to have a look at that.

Word to the wise: beware of spacing :)

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Dude, I found my Fixedsys!

5 Comments | Jun 16, 2009

Allright, so my last short post was about the fixedsys font not being available in the RC version of Windows 7. However, it’s there, but it seems to be depending on your language settings.

Now, being the proud little Belgian that I am, I have my language set to Belgain period. Not a good thing it seems, when you are a big fan of Fixedsys. But it can be solved :)

So basically what you need to do is go to the installed fonts window, you can see the Fixedsys font is already installed, but hidden for certain languages. That’s why you need to go to the font settings window and uncheck the hide checkbox:

image

image

And all of a sudden the font is available in notepad again:

image

 

Apparantly, Visual Studio does not take this little rule into account, that’s how I found out the font was actually installed. I was able to select the font from the Visual Studio
font selector. DAMN YOU WINDOWS :)

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Dude, where’s my fixedsys?

Add Comment | Jun 10, 2009

It’s been only a few days now since Windows7 made it to the point of full-time OS on my toys, but as a huge fan of the good old FixedSys font I am shocked.

WHERE is the fixedsys font in windows7? And don’t you dare tell me you threw it out!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Incorporate LINQ in your BizTalk projects

One Comment | Apr 24, 2009

LINQ is something that has had my full attention ever since it was released. And I’ve been wanting to do something on this blog with LINQ, but never really found the inspiration to do something “special” with it. Up until now.

So it occurred to me that there is not (to my knowledge) anything available that allows you to incorporate your LINQ way-of-work with BizTalk. And why not? There are purposes enough to use LINQ in a BizTalk environment, and it doesn’t even have to be rocket science to get there. On the contrary, using LINQ for BizTalk is about as easy as it can get really. And the means of use for this are limitless. Let’s go through some of the possibilities.

NOTE: Throughout this article, you will see a few different ways of how we could incorporate LINQ in our day-to-day BizTalk development. Iin good practice, we will NOT try to re-invent hot water. Instead, we will gratefully use existing functionality through LINQ to objects, and LINQ to XML.

A first example of LINQ usage in BizTalk is re-using BizTalk objects to provide a central BizTalk Administration Console. The advantages of this are obvious: we don’t have a need for a local Windows application to view our ports, locations, orchestrations and schemas. Instead, we can incorporate all BizTalk hubs from an infrastructure into one administration site where we can query administration information, start and stop our ports, and so on. One way we can do this, is through LINQ. The following will show you how.

When you install BizTalk Server, a number of assemblies are installed to the install location. By default, this is C:\Program Files\Microsoft BizTalk Server 2006. In this directory, there is one particular assembly that draws attention, namely Microsoft.BizTalk.ExplorerOM.dll. When we would take a look at this assembly through the Reflector tool (http://www.red-gate.com/products/reflector/), we would typically see a definition like this:

clip_image002

The BtsCatalogExplorer object is the central part of this project, that is because of the following properties it holds:

clip_image004

And these are just a glimpse of the properties. In general, you can say that the BtsCatalogExplorer object “represents” one Administration Console, or one BizTalk Management instance.

So what is the problem? We could just take those collections and fire up some LINQ queries on that, right?

Well, unfortunately no. The collection objects in the BizTalk assembly are all implementing the IEnumerable and ICollection interface. No surprises, but unfortunately, also no LINQ available with extension methods. Yet this really is the key to where we want to go to, and the solution is as easy as a HelloWorld solution. We simply have to create our own object that contains a BtsCx atalogExplorer object, and cast the collection properties to generic list objects that implement IEnumerable<T>, which we need when we want to use LINQ methods in LINQ to object. When we take the SendPort collection as an example, basically what we need to do is this:

clip_image006

What we do here, is take the BtsCatalogExplorer object, and instantiate it through btsex. In order, we then cast the SendPortCollection to an IEnumerable<SendPort> through the OfType<T> method, which we then convert to a List<SendPort> through the ToList<T> method. The result is a generic List object of SendPort object, that implements IEnumerable<T>. Now that we have this LINQable object, we can do something like the following in any client environment:

clip_image008

It is a very basic, very simple example, but it shows how easy it is to introduce LINQ into the administration side of BizTalk.

Now there also is a processing side to BizTalk. Wouldn’t it be great to incorporate LINQ to that side as well? Now you can. The following example will demonstrate a simple tool to promote properties through LINQ, and I call it the LINQPromotor Pipeline Component. For this example, I will show the results first, and then the method used.

So let’s start off by summarizing the requirements. For this demo it is sufficient that we use one component per property we want to use. So the component needs to take in a property name to promote, a namespace, and a LINQ query to retrieve the value to promote. So typically, we want a configuration like this:

clip_image010
clip_image012
When we use this pipeline on an incoming message, we see the following when we query the message context:

clip_image014

Note that there are some things marked with red to draw attention. First of all, in the pipeline configuration properties, you see the PropertyName and PropertyNamespace values configurable. These are values are shown in the context where you see Name = PromotedByLinq and Namespace = http://schemas.linq.com/promotions/.

But the key here is the LINQ statement property. Instead of an XPath query that we would fill in to retrieve the value to promote, we actually write a LINQ statement to do that query. This makes the query easier to read and to configure.

One way to do this is through runtime compilation. Take the linq query in as a string, add it to a method that takes in an XElement object, compile it at runtime, execute and promote the returned string. That summarizes the way of work in this example. Now we will take a closer look.

First of all, the linq statement gets inserted in a stringbuilder that builds up a piece of code that contains one method with one parameter of type XElement, and that returns a string as the value:

public string GetVal(XElement element){}.

We then compile that piece of code using the CSharpCodeProvice object, that is located in the Microsoft.CSharp namespace.

clip_image016

Note that in order to use LINQ, you need to specify the CompilerVersion to v3.5. MSDN documentation will specify a version “3.5”, but “v3.5” is what you want to use.

The code is compiled in memory, so we can just return an assembly ob ject, create an instance of the class we generated, and invoke the method:

clip_image018

The string that is returned contains the value that we can simply promote in our IBaseMessage object through outMessage.Context.Promote(PropertyName, PropertyNamespace, value);

And the results speak for themselves.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Terminating BizTalk instances: WMI vs Operations

One Comment | Apr 17, 2009

The Administration console that is delivered with the installation of BizTalk allows a user to query suspended service instances and resume or terminate them accordingly. However, when you want to go “outside the box”, and I often do :) you might want to consider finding out possibilities of doing those actions yourself, for instance from a web based managing platform. (note: the following methods work for both BTS2006 and 2009)

When you install BizTalk, there is a WMI provider installed on your machine as well, located in the root/MicrosoftBizTalkServer namespace. That namespace actually provides just about every functionality you need for administration purposes. But in this case, I typically want to focus on the MSBTS_ServiceInstance class. (this is a snapshot taken from server explorer in VS2008)

image

If you right click the class and generate an instance, your current project will get an extra class called ROOT.MicrosoftBizTalkServer.MSBTS_ServiceInstance.cs. When you take a look at that class, you will see the three methods that I’m interested in at this moment: Suspend, Resume, and Terminate. Let’s focus on the Terminate example for this case.

If you want to terminate a service instance through WMI (and there are examples of that over the entire web, so let’s NOT get into that deeply), you can simply use the generated class and say something like:

image

When you provide the InstanceID of your service instance, together with the name and server of the BizTalk Management Database of the BizTalk environment you are working on, the generated class will construct the WMI query for you and execute behind the scenes. So what you need to keep in mind with this method is that you need to go through the entire WMI architecture before actually taking an action.

To me, it sounds easier if I could do the same action in a more direct approach to BizTalk. And lucky for both me as the people who read this (at least I hope people read this :)) we can do that!

When you go to the root install directory of BizTalk (typically that’s C:\Program Files\Microsoft BizTalk Server) you will notice an assembly called Microsoft.BizTalk.Operations.dll, which in this case you can compare to a holy grail :) Let’s take a quick peek at the assembly with Reflector:

image

Of course now every still-awake reader notices the same methods I previously stated. And using these methods are of the same ease as the WMI methods. It goes as follows:

image 

Parameters stay the same. Create an instance of the BizTalkOperations class using the servername and database name of the BizTalk Management Database, and terminate your instance using the InstanceID of the Service Instance object.

Not much difference at first sight, but the thing here really is that when using the BizTalk.Operations, you have a more direct database approach to your action, instead of going through the entire WMI system before actually doing something. Sounds like that could save some performance when you would terminate instances with 500 at a time.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Persist message context when re-injecting a message in BizTalk

Add Comment | Apr 08, 2009

There are many cases in BizTalk environments when one want to re-inject a message into their system. I’m mainly referring to testing environments where it doesn’t really matter if a message is repeated.

However, it can also be preferred to copy the context of the message into the newly injected message, because your system might want to do some processing of that context while re-injecting. When you do this from code, it’s a snap!

First of all, we need to load up our message body and context:

image

Note that you need to specify the sql server name and database name of the BizTalk Tracking Database (commonly named BizTalkDTADb, but you can configure any database name). The System.GUID attribute should be replaced with the message id of the message you want to re-inject.

Now that we have an IBaseMessage object, we can access the context and copy it to the context of a new out IBaseMessage object.

 

image

 

This way we can keep a difference between promoted context properties and standard context properties. And that’s the only thing to it, msg_out is ready to be re-injected
to the BizTalk system

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Uppercase access levels in WiX

One Comment | Apr 06, 2009

My shortest blog post ever, but just so you know: if you don’t name your properties in WiX fully uppercased (eg INSTALLOCATION) WiX won’t recognize them as global properties.

If I had known this from the beginning, it would have saved me about two days… *F-word*

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Mathematical nostalgy

Add Comment | Mar 05, 2009

There is a time in every person’s life where one likes to recap about long lost projects. Little pieces of code that made you happy inside once it was completed. Well today, I had this moment.

The project I’m talking about is something I came up with after a school lesson on fractals. I won’t be getting much into that, as I am assuming everyone knows what that is. But once that session was done, I grabbed my laptop and went to work. The fractal that originated from that piece of free time is something that made me proud up until today.

Note: I completely made this fractal up from my imagination, if the same fractal already exists, and I’m sure it does, I don’t know about it but would like more info on it.

So anyhow, I was browsing through some old folders on my external disk and discovered that I had deleted that entire project to make room for other stuff. Disappointment went through my entire body and mind. But that didn’t take too long, as I decided to re-write it. Here’s  how I did it:

Basically, the top design of the fractal would be something like this

image

A tree-like structure that keeps getting smaller in a repetitive pattern. The tricky part is of course always defining your endpoint. The start point is never a problem, because that’s the endpoint of the previous branch. But the endpoints… they make it a little hard on my head :)

Now there are probably a lot more solutions available to this problem, but in my own case, I decided to go with good old trigonometry. Since the tree is built up using rectangular triangles, it’s pretty easy to come up with a formula that calculates the points needed.

image

x2 = x1 + (cos(alfa) * branchlength)
y2 = y1 - (sin(alfa) * branchlength)

Since I have a left part and a right part, I’m starting off with alfa = 135 and beta = 45. So I’m already done with the formula, on to the code translation!

First of all, it’s fairly logical that I declared a brush, a pen, and a graphics object, in my case called b, p, and g. Nothing fancy there :)

Next part is a littly cooler; in order to implement a configurable nesting level and draw everything with as little effort as possible, I chose to make a recursive method that takes a few parameters, namely a current X position, current Y position, current length, nesting level, an alfa angle and a beta angle, signatured as: private void DrawFrac(int xCur, int yCur, int lenCur, int nestCur, int alfa, int beta){}

So now the rest of the implementation is pretty easy (afterwards :) I busted my head on it for a while because the mathematical part had been a while since I used it)

if (_nestinglevel >= nestCur)
            {
                Point start = new Point(xCur, yCur);
                Point leftEnd = new Point((xCur + Convert.ToInt32(Math.Cos(alfa * (Math.PI / 180)) * lenCur)), (yCur - Convert.ToInt32(Math.Sin(alfa * (Math.PI / 180)) * lenCur)));
                g.DrawLine(p, start, leftEnd);

                Point rightEnd = new Point((xCur + Convert.ToInt32(Math.Cos(beta * (Math.PI / 180)) * lenCur)), (yCur - Convert.ToInt32(Math.Sin(beta * (Math.PI / 180)) * lenCur)));
                g.DrawLine(p, start, rightEnd);

                nestCur++;
                DrawFrac(leftEnd.X, leftEnd.Y, (lenCur / 4) * 3, nestCur, alfa+45, beta+45);
                DrawFrac(rightEnd.X, rightEnd.Y, (lenCur / 4) * 3, nestCur, alfa-45, beta-45);
            }

the result? a nice little fractal :)

 

frac

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Joining TechDays!

One Comment | Jan 12, 2009

10, 11, and 12 March 2009, Microsoft is hosting TechDays ‘09 in our beloved Antwerp. Last year I was unable to attend all days, but this year I’ll be there from start to end.

The agenda hasn’t been published yet, so I hope there will be lots of developer sessions planned.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati