Skip to content
markus-olsson edited this page May 31, 2012 · 6 revisions

Quickstart

In order to acccess tracked objects the first thing you have to do is create an instance of the BizTalkTrackingDb class. In order to initialize an instance you need to provide the connection string to the DTA db.

Creating a database connection

var db = new BizTalkTrackingDb(options.ConnectionString);

The credentials used to connect to the database needs EXECUTE permission to the following stored procedures (depending on what tracking data you plan to extract of course)

  • ops_LoadTrackedMessages
  • ops_LoadTrackedPartByID,
  • ops_LoadTrackedParts
  • ops_LoadTrackedMessageContext
  • ops_LoadTrackedPartFragment

Retrieving a tracked message by id

var message = db.LoadMessage(new Guid("{58aa5e93-36d1-485b-a6bc-a27a666a5b38}"));

Export the tracked contents of the body part to file

using (var fs = File.OpenWrite("messagebody.out"))
    message.BodyPart.WriteTo(fs, false);`

The WriteTo method is a convenience-method which loads the needed fragments from database, converts them from message part fragment format to the original format and concatenats all decoded fragments into the given stream. The second parameter indicates whether or not the BizTalkTrackedMessagePart should cache the retrieved fragments in memory. Specifying false makes WriteTo behave like a stream which writes to the output stream as soon as it retrieves data from the stored procedure while holding no reference to the data afterwards (making it efficient when exporting large messages to file).

List all tracked messages in the db

foreach(var message in db.LoadMessages()) {
    Console.WriteLine(message.MessageId);
}

Will load messages from both spools. There's an overload allowing you to specify which spool to read from.

Retrieve a property from the message context of a tracked message

var message = db.LoadMessage(new Guid("{58aa5e93-36d1-485b-a6bc-a27a666a5b38}"));
var context = db.LoadTrackedMessageContext(message.MessageId, message.SpoolId);

String receivedFileName;

if(context.TryGetProperty("http://schemas.microsoft.com/BizTalk/2003/file-properties", "ReceivedFileName", out receivedFileName)
    Console.WriteLine(receivedFileName); // "C:\In\Test.xml"

// Or with LINQ (if you're certain the property exists and that there's no namespace conflicts)
Console.WriteLine(context.First(p => p.Name == "ReceivedFileName"));