The component code has 4 blocks:
/// <summary> /// Implements IComponent.Execute method. /// </summary> /// <param name="pContext">Pipeline context</param> /// <param name="pInMsg">Input message</param> /// <returns>Original input message</returns> /// <remarks> /// IComponent.Execute method is used to initiate /// the processing of the message in this pipeline component. /// </remarks> IBaseMessage Microsoft.BizTalk.Component.Interop.IComponent.Execute(IPipelineContext pContext, IBaseMessage pInMsg) { EventLog.WriteEntry("H19", "STARTED...V2.3", System.Diagnostics.EventLogEntryType.SuccessAudit); bool IsValidVal = false; string outVal = string.Empty; string XmlData = string.Empty; IBaseMessagePart bodyPart = pInMsg.BodyPart; System.IO.StreamReader sr = new System.IO.StreamReader(bodyPart.Data); XmlData = sr.ReadToEnd(); // IF EDI Ack then return as it is if (string.Equals(XmlData, string.Empty) || XmlData.Contains("X12_997_Root") || XmlData.Contains("X12_TA1_Root")) return pInMsg; EventLog.WriteEntry("H19", "SourceValues=" + this._SourceValue + ", TargetValue=" + this._TargetValue, System.Diagnostics.EventLogEntryType.SuccessAudit); IsValidVal = HimUtility.XML.IsValidateValue(XmlData, this._SourceNodeXpath, this._SourceValue, this._TargetNodeXpath, this._TargetValue, out outVal); if (!IsValidVal) { StringBuilder sb = new StringBuilder("Invalid value "); sb.Append(outVal); sb.Append(" at node "); sb.Append(HimUtility.XML.GetNodeFromXpath(this._TargetNodeXpath)); sb.Append(Environment.NewLine); sb.Append("-----------------------------------------------------"); sb.Append(Environment.NewLine); sb.Append(HimUtility.XML.GetNodeFromXpath(this._SourceNodeXpath)); sb.Append(" value= "); sb.Append(this._SourceValue); sb.Append(" then "); sb.Append(HimUtility.XML.GetNodeFromXpath(this._TargetNodeXpath)); sb.Append(" node value must be ="); sb.Append(this._TargetValue); if (this._FailedAction == FS.Error) { EventLog.WriteEntry("H19", "Data Validation Failed!!", System.Diagnostics.EventLogEntryType.Error); Exception Inner = new Exception(sb.ToString()); Exception ex = new Exception("Data Validation Failed!!", Inner); ex.Source = this.Name; throw ex; } else if (this._FailedAction == FS.Warring) { EventLog.WriteEntry("H19", "Data Validation Failed!!" + Environment.NewLine + sb.ToString(), System.Diagnostics.EventLogEntryType.Warning); } else { EventLog.WriteEntry("H19", "Data Validation Failed!!" + Environment.NewLine + sb.ToString(), System.Diagnostics.EventLogEntryType.Information); } } //Return message System.IO.MemoryStream strm = new System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes(XmlData)); strm.Position = 0; bodyPart.Data = strm; pContext.ResourceTracker.AddResource(strm); return pInMsg; }
/// <summary>
/// Implements IComponent.Execute method.
/// </summary>
/// <param name="pContext">Pipeline context</param>
/// <param name="pInMsg">Input message</param>
/// <returns>Original input message</returns>
/// <remarks>
/// IComponent.Execute method is used to initiate
/// the processing of the message in this pipeline component.
/// </remarks>
IBaseMessage Microsoft.BizTalk.Component.Interop.IComponent.Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
EventLog.WriteEntry(
"H19"
,
"STARTED...V2.3"
, System.Diagnostics.EventLogEntryType.SuccessAudit);
bool
IsValidVal =
false
;
string
outVal =
.Empty;
XmlData =
IBaseMessagePart bodyPart = pInMsg.BodyPart;
System.IO.StreamReader sr =
new
System.IO.StreamReader(bodyPart.Data);
XmlData = sr.ReadToEnd();
// IF EDI Ack then return as it is
if
(
.Equals(XmlData,
.Empty) || XmlData.Contains(
"X12_997_Root"
) || XmlData.Contains(
"X12_TA1_Root"
))
return
pInMsg;
"SourceValues="
+
this
._SourceValue +
", TargetValue="
._TargetValue, System.Diagnostics.EventLogEntryType.SuccessAudit);
IsValidVal = HimUtility.XML.IsValidateValue(XmlData,
._SourceNodeXpath,
._SourceValue,
._TargetNodeXpath,
._TargetValue,
out
outVal);
(!IsValidVal)
StringBuilder sb =
StringBuilder(
"Invalid value "
);
sb.Append(outVal);
sb.Append(
" at node "
sb.Append(HimUtility.XML.GetNodeFromXpath(
._TargetNodeXpath));
sb.Append(Environment.NewLine);
"-----------------------------------------------------"
._SourceNodeXpath));
" value= "
._SourceValue);
" then "
" node value must be ="
._TargetValue);
._FailedAction == FS.Error)
"Data Validation Failed!!"
, System.Diagnostics.EventLogEntryType.Error);
Exception Inner =
Exception(sb.ToString());
Exception ex =
Exception(
, Inner);
ex.Source =
.Name;
throw
ex;
}
else
._FailedAction == FS.Warring)
+ Environment.NewLine + sb.ToString(), System.Diagnostics.EventLogEntryType.Warning);
+ Environment.NewLine + sb.ToString(), System.Diagnostics.EventLogEntryType.Information);
//Return message
System.IO.MemoryStream strm =
System.IO.MemoryStream(ASCIIEncoding.Default.GetBytes(XmlData));
strm.Position = 0;
bodyPart.Data = strm;
pContext.ResourceTracker.AddResource(strm);
namespace HimUtility{ public class XML { /// <summary> /// Validate Second nodes value base on first node values /// </summary> /// <param name="XmlData">Inner/Outer XML data as string</param> /// <param name="SrcXpath">Xpath of First node</param> /// <param name="SrcVal">Colun (;) seperated value of First node</param> /// <param name="TrgXpath">Xpath of Second node</param> /// <param name="TrgVal">Colun (;) seperated value of Second node</param> /// <param name="outVal">Out parameter, return the failed seconf node value</param> /// <returns></returns> public static bool IsValidateValue(string XmlData, string SrcXpath, string SrcVal, string TrgXpath, string TrgVal, out string outVal) { bool IsValid = false; outVal = string.Empty; XmlDocument Xdoc = new XmlDocument(); Xdoc.LoadXml(XmlData); XPathNavigator nav = Xdoc.CreateNavigator(); XPathNodeIterator NodeIter; //Getting First node Values string[] FN = SrcVal.ToUpper().Split(';'); Hashtable htSrvVal = new Hashtable(); foreach (string s in FN) htSrvVal.Add(s, s); //Getting Second Nodes Values string[] SN = TrgVal.ToUpper().Split(';'); Hashtable htTrgVal = new Hashtable(); foreach (string s in SN) htTrgVal.Add(s, s); //Get XML Value of xmlVal XPathExpression expr; expr = nav.Compile(SrcXpath); // Compile a standard XPath expression string xmlVal = nav.SelectSingleNode(expr).InnerXml.ToUpper(); // If 1st value is true then check corresponding valid values if (htSrvVal.ContainsKey(xmlVal)) { NodeIter = nav.Select(TrgXpath); while (NodeIter.MoveNext()) { outVal = NodeIter.Current.Value.ToUpper(); IsValid = htTrgVal.ContainsKey(outVal); if (!IsValid) return false; Console.WriteLine("TrgVal Title: {0} IsValid: {1}", NodeIter.Current.Value, IsValid); } } else { return true; } return IsValid; } /// <summary> /// Get node name from Xpath expression /// </summary> /// <param name="SrcXpath"></param> /// <returns></returns> public static string GetNodeFromXpath(string SrcXpath) { string NodeName = string.Empty; char[] c = { (char)39 }; string[] tmp = SrcXpath.Split(c); if (tmp.Length > 4) NodeName = tmp[tmp.Length - 4];//True for EDI Schems else NodeName = tmp[tmp.Length];//For normal Schems's Xpath return NodeName; } }}
namespace
HimUtility
public
class
XML
/// Validate Second nodes value base on first node values
/// <param name="XmlData">Inner/Outer XML data as string</param>
/// <param name="SrcXpath">Xpath of First node</param>
/// <param name="SrcVal">Colun (;) seperated value of First node</param>
/// <param name="TrgXpath">Xpath of Second node</param>
/// <param name="TrgVal">Colun (;) seperated value of Second node</param>
/// <param name="outVal">Out parameter, return the failed seconf node value</param>
/// <returns></returns>
static
IsValidateValue(
XmlData,
SrcXpath,
SrcVal,
TrgXpath,
TrgVal,
outVal)
IsValid =
XmlDocument Xdoc =
XmlDocument();
Xdoc.LoadXml(XmlData);
XPathNavigator nav = Xdoc.CreateNavigator();
XPathNodeIterator NodeIter;
//Getting First node Values
[] FN = SrcVal.ToUpper().Split(
';'
Hashtable htSrvVal =
Hashtable();
foreach
s
in
FN)
htSrvVal.Add(s, s);
//Getting Second Nodes Values
[] SN = TrgVal.ToUpper().Split(
Hashtable htTrgVal =
SN)
htTrgVal.Add(s, s);
//Get XML Value of xmlVal
XPathExpression expr;
expr = nav.Compile(SrcXpath);
// Compile a standard XPath expression
xmlVal = nav.SelectSingleNode(expr).InnerXml.ToUpper();
// If 1st value is true then check corresponding valid values
(htSrvVal.ContainsKey(xmlVal))
NodeIter = nav.Select(TrgXpath);
while
(NodeIter.MoveNext())
outVal = NodeIter.Current.Value.ToUpper();
IsValid = htTrgVal.ContainsKey(outVal);
(!IsValid)
Console.WriteLine(
"TrgVal Title: {0} IsValid: {1}"
, NodeIter.Current.Value, IsValid);
true
IsValid;
/// Get node name from Xpath expression
/// <param name="SrcXpath"></param>
GetNodeFromXpath(
SrcXpath)
NodeName =
char
[] c = { (
)39 };
[] tmp = SrcXpath.Split(c);
(tmp.Length > 4)
NodeName = tmp[tmp.Length - 4];
//True for EDI Schems
NodeName = tmp[tmp.Length];
//For normal Schems's Xpath
NodeName;
Browse then select
Creating Dropdown on component configuration: Just create enum on component
public enum FS { Information = 1, Warring = 2, Error = 3 }
And it will shows as Dropdown on component properties
While creating this component and searching for some thing got Online Xpath testing site http://xpath.online-toolz.com/tools/xpath-editor.php
I tookd help from Biztalk pipeline component wizard (http://btsplcw.codeplex.com/releases/view/26930)
Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.
Maheshkumar S Tiwari edited Revision 4. Comment: corrected typo error
Maheshkumar S Tiwari edited Revision 3. Comment: Added code block and Tag
Maheshkumar S Tiwari edited Revision 2. Comment: Title casing,added tags, added see also and minor edit