|
| 1 | +namespace PipelineComponents.OperationPromotion |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using System.IO; |
| 5 | + using System.Text; |
| 6 | + using System.Drawing; |
| 7 | + using System.Resources; |
| 8 | + using System.Reflection; |
| 9 | + using System.Diagnostics; |
| 10 | + using System.Collections; |
| 11 | + using System.ComponentModel; |
| 12 | + using Microsoft.BizTalk.Message.Interop; |
| 13 | + using Microsoft.BizTalk.Component.Interop; |
| 14 | + using Microsoft.BizTalk.Component; |
| 15 | + using Microsoft.BizTalk.Messaging; |
| 16 | + using Microsoft.BizTalk.Streaming; |
| 17 | + |
| 18 | + |
| 19 | + [ComponentCategory(CategoryTypes.CATID_PipelineComponent)] |
| 20 | + [System.Runtime.InteropServices.Guid("80fb5b06-89b8-4518-ac6b-4ee4a1ef145a")] |
| 21 | + [ComponentCategory(CategoryTypes.CATID_Encoder)] |
| 22 | + public class CBRIdocOperationPromotionDecode : Microsoft.BizTalk.Component.Interop.IComponent, IBaseComponent, IPersistPropertyBag, IComponentUI |
| 23 | + { |
| 24 | + |
| 25 | + private System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("PipelineComponents.OperationPromotion.CBRIdocOperationPromotionDecode", Assembly.GetExecutingAssembly()); |
| 26 | + |
| 27 | + private string _MessageTypeStrIgnore; |
| 28 | + |
| 29 | + public string MessageTypeStrIgnore |
| 30 | + { |
| 31 | + get |
| 32 | + { |
| 33 | + return _MessageTypeStrIgnore; |
| 34 | + } |
| 35 | + set |
| 36 | + { |
| 37 | + _MessageTypeStrIgnore = value; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + #region IBaseComponent members |
| 42 | + /// <summary> |
| 43 | + /// Name of the component |
| 44 | + /// </summary> |
| 45 | + [Browsable(false)] |
| 46 | + public string Name |
| 47 | + { |
| 48 | + get |
| 49 | + { |
| 50 | + return resourceManager.GetString("COMPONENTNAME", System.Globalization.CultureInfo.InvariantCulture); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Version of the component |
| 56 | + /// </summary> |
| 57 | + [Browsable(false)] |
| 58 | + public string Version |
| 59 | + { |
| 60 | + get |
| 61 | + { |
| 62 | + return resourceManager.GetString("COMPONENTVERSION", System.Globalization.CultureInfo.InvariantCulture); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Description of the component |
| 68 | + /// </summary> |
| 69 | + [Browsable(false)] |
| 70 | + public string Description |
| 71 | + { |
| 72 | + get |
| 73 | + { |
| 74 | + return resourceManager.GetString("COMPONENTDESCRIPTION", System.Globalization.CultureInfo.InvariantCulture); |
| 75 | + } |
| 76 | + } |
| 77 | + #endregion |
| 78 | + |
| 79 | + #region IPersistPropertyBag members |
| 80 | + /// <summary> |
| 81 | + /// Gets class ID of component for usage from unmanaged code. |
| 82 | + /// </summary> |
| 83 | + /// <param name="classid"> |
| 84 | + /// Class ID of the component |
| 85 | + /// </param> |
| 86 | + public void GetClassID(out System.Guid classid) |
| 87 | + { |
| 88 | + classid = new System.Guid("80fb5b06-89b8-4518-ac6b-4ee4a1ef145a"); |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// not implemented |
| 93 | + /// </summary> |
| 94 | + public void InitNew() |
| 95 | + { |
| 96 | + } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// Loads configuration properties for the component |
| 100 | + /// </summary> |
| 101 | + /// <param name="pb">Configuration property bag</param> |
| 102 | + /// <param name="errlog">Error status</param> |
| 103 | + public virtual void Load(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, int errlog) |
| 104 | + { |
| 105 | + object val = null; |
| 106 | + val = this.ReadPropertyBag(pb, "MessageTypeStrIgnore"); |
| 107 | + if ((val != null)) |
| 108 | + { |
| 109 | + this._MessageTypeStrIgnore = ((string)(val)); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + /// <summary> |
| 114 | + /// Saves the current component configuration into the property bag |
| 115 | + /// </summary> |
| 116 | + /// <param name="pb">Configuration property bag</param> |
| 117 | + /// <param name="fClearDirty">not used</param> |
| 118 | + /// <param name="fSaveAllProperties">not used</param> |
| 119 | + public virtual void Save(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, bool fClearDirty, bool fSaveAllProperties) |
| 120 | + { |
| 121 | + this.WritePropertyBag(pb, "MessageTypeStrIgnore", this.MessageTypeStrIgnore); |
| 122 | + } |
| 123 | + |
| 124 | + #region utility functionality |
| 125 | + /// <summary> |
| 126 | + /// Reads property value from property bag |
| 127 | + /// </summary> |
| 128 | + /// <param name="pb">Property bag</param> |
| 129 | + /// <param name="propName">Name of property</param> |
| 130 | + /// <returns>Value of the property</returns> |
| 131 | + private object ReadPropertyBag(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, string propName) |
| 132 | + { |
| 133 | + object val = null; |
| 134 | + try |
| 135 | + { |
| 136 | + pb.Read(propName, out val, 0); |
| 137 | + } |
| 138 | + catch (System.ArgumentException ) |
| 139 | + { |
| 140 | + return val; |
| 141 | + } |
| 142 | + catch (System.Exception e) |
| 143 | + { |
| 144 | + throw new System.ApplicationException(e.Message); |
| 145 | + } |
| 146 | + return val; |
| 147 | + } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Writes property values into a property bag. |
| 151 | + /// </summary> |
| 152 | + /// <param name="pb">Property bag.</param> |
| 153 | + /// <param name="propName">Name of property.</param> |
| 154 | + /// <param name="val">Value of property.</param> |
| 155 | + private void WritePropertyBag(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, string propName, object val) |
| 156 | + { |
| 157 | + try |
| 158 | + { |
| 159 | + pb.Write(propName, ref val); |
| 160 | + } |
| 161 | + catch (System.Exception e) |
| 162 | + { |
| 163 | + throw new System.ApplicationException(e.Message); |
| 164 | + } |
| 165 | + } |
| 166 | + #endregion |
| 167 | + #endregion |
| 168 | + |
| 169 | + #region IComponentUI members |
| 170 | + /// <summary> |
| 171 | + /// Component icon to use in BizTalk Editor |
| 172 | + /// </summary> |
| 173 | + [Browsable(false)] |
| 174 | + public IntPtr Icon |
| 175 | + { |
| 176 | + get |
| 177 | + { |
| 178 | + return ((System.Drawing.Bitmap)(this.resourceManager.GetObject("COMPONENTICON", System.Globalization.CultureInfo.InvariantCulture))).GetHicon(); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + /// <summary> |
| 183 | + /// The Validate method is called by the BizTalk Editor during the build |
| 184 | + /// of a BizTalk project. |
| 185 | + /// </summary> |
| 186 | + /// <param name="obj">An Object containing the configuration properties.</param> |
| 187 | + /// <returns>The IEnumerator enables the caller to enumerate through a collection of strings containing error messages. These error messages appear as compiler error messages. To report successful property validation, the method should return an empty enumerator.</returns> |
| 188 | + public System.Collections.IEnumerator Validate(object obj) |
| 189 | + { |
| 190 | + // example implementation: |
| 191 | + // ArrayList errorList = new ArrayList(); |
| 192 | + // errorList.Add("This is a compiler error"); |
| 193 | + // return errorList.GetEnumerator(); |
| 194 | + return null; |
| 195 | + } |
| 196 | + #endregion |
| 197 | + |
| 198 | + #region IComponent members |
| 199 | + /// <summary> |
| 200 | + /// Implements IComponent.Execute method. |
| 201 | + /// </summary> |
| 202 | + /// <param name="pc">Pipeline context</param> |
| 203 | + /// <param name="inmsg">Input message</param> |
| 204 | + /// <returns>Original input message</returns> |
| 205 | + /// <remarks> |
| 206 | + /// IComponent.Execute method is used to initiate |
| 207 | + /// the processing of the message in this pipeline component. |
| 208 | + /// </remarks> |
| 209 | + public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg) |
| 210 | + { |
| 211 | + /************************************************************************************************************************* |
| 212 | + * This component will read the MessageType from the Message Context Properties. * |
| 213 | + * BTS.MessageType: Specifies the type of the message. The message type is defined as a concatenation of document * |
| 214 | + * schema namespace and document root node: http://<MyNamespace>#<MyRootNode>. * |
| 215 | + * and will promote the Operation property based on the content on the Root node "<MyRootNode>" specified on the * |
| 216 | + * message type "http://<MyNamespace>#<MyRootNode>" of the message. * |
| 217 | + * * |
| 218 | + * Ex: Message Type = "http://schemas.integration.com#GetClientInfo" * |
| 219 | + * Operation will be defined as "GetClientInfo" * |
| 220 | + ************************************************************************************************************************/ |
| 221 | + |
| 222 | + // Note: |
| 223 | + // System properties are mostly used internally by BizTalk Messaging Engine and its components. |
| 224 | + // In general, changing the values set by the engine for those properties is not recommended, because it may affect |
| 225 | + // the execution logic of the engine. However, there are a large number of properties that you can change. |
| 226 | + |
| 227 | + string msgType = Convert.ToString(inmsg.Context.Read("MessageType", |
| 228 | + "http://schemas.microsoft.com/BizTalk/2003/system-properties")); |
| 229 | + |
| 230 | + string operation = msgType.Replace(_MessageTypeStrIgnore, ""); |
| 231 | + operation = operation.Substring(0, operation.IndexOf('/')); |
| 232 | + |
| 233 | + inmsg.Context.Promote("Operation", "http://schemas.microsoft.com/BizTalk/2003/system-properties", |
| 234 | + operation); |
| 235 | + |
| 236 | + return inmsg; |
| 237 | + } |
| 238 | + #endregion |
| 239 | + } |
| 240 | +} |
0 commit comments