Using BizTalk CrossReferencing API for parameters

BizTalk has a nice feature called cross-referencing which is meant to cross-reference values between two or more systems. Usually this functionality shall be used in mappings through the cross-reference functoids. However CrossReferencing also provides a CrossReferencing Class that can be used directly in orchestration expressions or helper class libraries. This gives you the interesting opportunity to use the cross-referencing database tables to store parameters for your BizTalk applications in one place.

Below is an example of how you can implement a Parameter class that can be used in an orchestration:

using System;
using System.Data.SqlClient;
using Microsoft.BizTalk.CrossReferencing;

namespace Helpers
{
	public static class Parameters
	{
		private const string valXRef = "Helpers.Parameters";
		private const string valAppType = "MyApplication";

		internal static SqlConnection CreateDbConnection()
		{
			SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
			builder.DataSource = CrossReferencing.GetAppValue(valXRef, valAppType, "Server");
			builder.InitialCatalog = CrossReferencing.GetAppValue(valXRef, valAppType, "Database");
			builder.IntegratedSecurity = true;

			SqlConnection connection = new SqlConnection(builder.ConnectionString);
			connection.Open();

			return connection;
		}

		public static bool GoLeft
		{
			get
			{
				string val = CrossReferencing.GetAppValue(valXRef, valAppType, "GoLeft");
				return String.IsNullOrEmpty(val) ? false : Convert.ToBoolean(val);
			}
		}

		public static TimeSpan TimeOut
		{
			get
			{
				string val = CrossReferencing.GetAppValue(valXRef, valAppType, "TimeOut");
				return TimeSpan.FromSeconds(String.IsNullOrEmpty(val) ? 30 : Convert.ToDouble(val));
			}
		}
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: