Aggregator Sample in BT 2006

 
Introduction
Recently, I had the opportunity to help one of our company’s developers through some training exercises for BizTalk 2006 development. In that process I encountered what I considered to be a fantastic solution sample that I wanted to share with the BizTalk community should anyone be in a similar Trainer / Trainee situation or simply […]

Using the WF rules to iterate over a collection

I thought I understood how the WF Rules iterated over a collection.  Isn’t that always how it goes – you really prove it to yourself when you can explain it to someone else.  Well, I started to explain how I thought it worked and this person started asking questions and I soon realized that I was no longer sure I understood it.  After a bit of research and with my newly obtained understanding I tried to explain it again and it actually made sense.

So, I have decided to blog about this since I am sure that others will most likely need to do this and may even need to explain it to someone else.


During my research I found the MSDN article titled Introduction to the Windows Workflow Foundation Rules Engine which had a little blurb towards the bottom titled Collection Processing which I found to be a good start.  I also found Matt Winkle’s blog entry which had an example that he put on the Workflow Community Site.  It was this example that really solidified it for me.


he had created 4 rules


Rule 1: Initialize with a priority of 2


IF
    1==1
THEN
    this.enumerator = this.OrderItems.GetEnumerator()


Rule 2: IterateOverItems with a priority of 1


IF
    this.enumerator.MoveNext()
THEN
    this.currentItem = (RulesWithCollectionSample.OrderItem)this.enumerator.Current
    System.Console.WriteLine(“Assignednumerator” + this.currentItem.Price)
ELSE
    System.Cosole.WriteLine(“we are all done”)


Rule 3:  IndividualItem with a priority of 0


IF
    this.CurrentItem != null
THEN
    this.Total = this.Total + this.CurrentItem.Price * this.CurrentItem.Quantity
    System.Console.WriteLine(“Running Total: ” + this.Total.ToString())
ELSE
    System.Console.WriteLine(“current item is null”)


Rule 4: Finished with a priority of -1


IF
    this.CurrentItem == this.CurrentItem
THEN
    System.Console.WriteLine(“Finished True”)
    Update(“this/enumerator”)
ELSE
    System.Console.WriteLine(“Finished False”)
    Update(“this/enumerator”)


In addition to these rules you also have to decorate your class with three additional properties. 


First, create an enumerator property that is of type System.Collections.Generic.IEnumerator<T> or System.Collections.IEnumerator


Second, create an items collection to contain your collection of items which can be of type List<T> or anything that supports IEnumerator


Third, create a property to hold the current item


After looking at the rules and the properties I was ready to watch it run. 


Rule 1 ran first, as it should since it has the highest priority and has a condition that always returns true.  This rule populates the enumerator property backing store.  Then the rules engine looks for the rule with next highest priority, which is Rule 2.  This rule calls MoveNext on the enumerator and if it is able to move then true is returned and the THEN part of the rule runs which passes the current collection item to this.currentItem.  If MoveNext return false then the text “we are all done” will be written to the Output Window which is the last item output after all of the items in the collection has been iterated over.


If the MoveNext method in Rule 2 returned true, then the rules engine again looks for the next rule with the highest priority, which is now Rule 3.  Rule 3 checks to see if there is a Current Item and if so does some work (in this case updates the total).  If the Current Item is null then we will get the text “current item is null” written to the Output Window.  However, this line is never encountered when the rules run.


Finally the fourth rule is run, the condition can really be anything but it needs to be evaluated each time, which updates the engine telling it that we want to update the enumerator and force forward chaining behavior.  By doing this we are saying that the engine should look for any rules that have conditions that are reliant on the enumerator.  In this case, Rule 2 matches this and the engine loops to Rule 2 and continues to run through the rules based on priority from there.  This will then set off a loop in the rules engine moving from Rule 4 back to Rule 2, then Rule 3 and Rule 4 until the MoveNext function in Rule 2 returns false (indicating it has no more items in the collection) and the ELSE portion of the rule runs.  At this point the rules are finished processing and the control is returned back to the calling application.


Hopefully this helps explain what is required to iterate over a collection as well as what is happening during the iteration process.


 

BAM and the Tracking Profile Editor – cool resource

While delving into the depths of this for a current project – I shot a question off
to the team over in Redmond in relation to the TPE and grabing related data from different
areas of a BTS process…..NOW this is where it got great!!!

Vikas responded and check out his fantastic blog –
dedicated to Biztalk and TPE!!!

In particulare I’m interested in Continuations

Thousand thanks Vikas + co.

Cheers,

Mick.

Seriously Cool Stuff: Visual Studio 2005 Extensions for WSS v3

I just got back from a really cool Tech Ed session: OFF205 Office Developer 101: How to get started building Office 2007 solutions. Although the name doesn’t give it away, it also covered some SharePoint stuff. The first part of the session discussed some basic Office client development topics (Hello World ribbon buttons and custom Task Panes) but the interesting stuff was in the second part: Alexander Malek talked about the Visual Studio 2005 Extensions for Windows SharePoint Services v3. It was released earlier today, see Alexanders post, and Joris’ (aka Jopx) post (he was sitting next to me in this session and told me it works for B2TR). (download link).

What was so cool about VS 2005 Extensions for WSS v3? Just a couple of things that made me very happy:

  • There is a web part project template for Visual Studio 2005 that allows you to deploy and debug by pressing F5 (or the play button).
  • There is a empty SharePoint project template which allows you to insert web parts, custom fields, list definitions, content types etc (and also allows you to deploy from within Visual Studio 2005).
  • There is the SharePoint Solution Generator tool, which is my favorite! This tool allows you to generate Site Definitions for existing, customized SharePoint sites. So the scenario could go like this: create a site in SharePoint (through the web UI), add some stuff (lists, content types, web parts, …) and customize further in SharePoint Designer (even CSS). When you are happy with your site and you would like to deploy it in a more professional way than create a Site Template (STP). You can now fire up the SharePoint Solution Generator that allows you to select your site and it generates a complete Visual Studio project for you, that includes your custom Site Definition! It is really a Visual Studio project that uses the Visual Studio 2005 Extensions for WSS v3 so you can add custom fields, lists, web parts etc. This is very, very cool!

I hope I can show the web part template in my session later on this week (DEV353 Building Web Parts the Smart Way ,Thu Nov 9 17:30 – 18:45) because it will be quite important in the web part world.

Share this post: Email it! | bookmark it! | digg it! | reddit!

View Orchestration in C#

BizTalk Orchestration Designer is the core tool for laying out components representing business processes, and connecting them with logic operations when designing BizTalk applications in Visual Studio. Behind the scene, the XLANG compiler actually generates C# source code before compiling it into .NET assemblies. If you ever want to look under the hood and view […]

New Releases

New Releases

I’m in Lima, Peru all this week, so probably won’t be able to blog much. Meanwhile, several important releases are coming out:

  • .NET
    FX 3.0 RTM
    : WCF, WPF, WF and Cardspace all in RTM. I’ll be installing it as soon
    as I get back home and have a decent internet connection available.
  • Microsoft Host
    Integration Server 2006
    has been released as well. Here’s the evaluation
    download
    . Can someone please explain why if HIS came out after Commerce Server,
    why is it still a “2006” product while Commerce is a “2007” one?
  • Alongside HIS 2006, the Host
    Adapters for BizTalk 2006
    have been released as well.

technorati .NET, BizTalk.
HIS


Dynamic mapping in BizTalk

Hi guys,

I’m currently researching ways to do this outside of an orchestration – e.g. pipeline.

Here’s a simple technique you can use INSIDE an
Orch.

(1) variable declarations in the Orch.
System.Type MapToApplyType;

(2) message declaration
<schema type or whatever>   msgIn;
System.Xml.XmlDocument    msgOut;

(3) code in the Orchestration  – in the getType function you could grab that
string from rules or anywhere.
In an expression shape: (for eg)
MapToApply = System.Type.GetType(“MyMapAssembly.MyMap, MyMapAssembly, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=abfe123ef93cc2aa”);

(4) in a message construct shape for msgOut
// the line below is GOLD where

transform (msgOut) = MapToApplyType(msgIn);


There you have it!!! BTS looks after the finding and loading of the map. transform is
an internal keyword of bts.

Have fun,

The top 3 things SQL DBAs need to know about BizTalk.

The top 3 things SQL DBAs need to know about BizTalk.

The top 3 things SQL DBAs need to know about BizTalk. (In order of importance)

  1. BizTalk Server has its own backup story and SQL DBAs need to become fully acquainted with it. Do not assume that the normalSQL Backup tasks will adequately backup your BizTalk Server. The BizTalk 2006 documentation is comprehensive in this area. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bts06coredocs/html/82fc1af2-1389-4c79-80dc-f2df5656d201.asp
  2. There are several things about the way BizTalk uses SQL Server that are unusual.
    1. http://support.microsoft.com/kb/899000/
    2. /http://support.microsoft.com/kb/912262
    3. The SQL Server Agent must be allowed to run continuously on the server hosting BizTalk databases.
  3. BizTalk uses SQL Server extensively during normal operations. Try to ensure BizTalk and SQL Server are separated by as few network hops as possible.