One of my company’s Client has a huge BizTalk Infrastructure and there are lot of orchestrations in different projects and each orchestration has it’s own AppDomain as per their standard and configuration of each AppDomain is contained within another configuration file which have configurations like Application Blocks settings, Cache Settings etc and if this configuration is invalid or location path is incorrect it cause biztalk host to stop

Following is an example of one such configuration within BizTalk Config.

<AppDomainSpecs>

<AppDomainSpec Name=”ABC.IHUB.Orchestrations” SecondsIdleBeforeShutdown=”-1″ SecondsEmptyBeforeShutdown=”12000″>

<BaseSetup><ConfigurationFile>D:\ABC.ProcessMerge.Orchestrations.dll.config</ConfigurationFile></BaseSetup>

</AppDomainSpec>

</AppDomainSpecs>

Above example has just one app domain. Consider having 100+ AppDomains and if there is problem in one configuration it would take a lot of manual effort to find issue in the configuration. We actually faced this issue. We were afraid of even thinking of checking all configurations manually so we wrote a utility validate the configuration to some extent. We will keep on updating this utility to make it more robust like one feature I was thinking that it should validate against configuration schema that could be pretty useful as well. Anyways below is the code for the utility

Code of the Utility

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Xml;

using System.IO;

namespace BTSConfigValidator

{


class Program

{

static string CurrentFile = string.Empty;

static string Errors = string.Empty;

static void Main(string[] args)

{

if (args.Length <= 0)//checking if commandline param exists

{

Console.WriteLine(“Commandline Parameter Missing …”);

Console.WriteLine(“Please enter valid path of BiztalkNTSvc.exe.config”);

}

else if (!File.Exists(args[0]))//checking if BiztalkNTSvc file exists

{

Console.WriteLine(“Please enter valid path of BiztalkNTSvc file ..”);

Console.WriteLine(args[0]);

}

else

{

XmlDocument btsConfig = new XmlDocument();

btsConfig.Load(args[0]); //loading configuration in XML document

XmlNodeList nodes = btsConfig.SelectNodes(“//AppDomainSpec/BaseSetup/ConfigurationFile”); // selecting app domain nodes

XmlReader validator = null;

XmlReaderSettings settings = new XmlReaderSettings();

//setting XML validator configuration

settings.CheckCharacters = true;

settings.CloseInput = true;

settings.ConformanceLevel = ConformanceLevel.Document;

settings.IgnoreComments = true;

settings.ValidationType = ValidationType.DTD;

try

{

foreach (XmlNode node in nodes)//loop through each app domain

{

CurrentFile = node.InnerXml;//loading path of appdomain configuration file

validator = XmlReader.Create(CurrentFile, settings);

while (validator.Read()) //reading XML file to validate

{

} validator.Close();

}

if (string.IsNullOrEmpty(Errors))

Console.WriteLine(“All Configuration Files are valid found no Exception”);

else

{

Console.WriteLine(“Found Few Exceptions Please see detail”);

Console.WriteLine(Errors);

}

}

catch (System.IO.DirectoryNotFoundException dnf)

{

Console.WriteLine(“Following file is not found Please check the Path…”);

Console.WriteLine(CurrentFile);

}

catch (System.IO.IOException ioe)

{

Console.WriteLine(ioe.ToString());

}

catch (Exception ex)

{

Console.WriteLine(“Exception in following file Please check detail…”);

Console.WriteLine(“File Name:- “ + CurrentFile);

Console.WriteLine(“Exception Message :- “ + ex.Message);

if (validator != null)

if (validator.ReadState != ReadState.Closed)

validator.Close();

}

}

Console.WriteLine(“Press Enter to Exit…….”);

Console.ReadLine();

}

}

}

Advertisements