Exemple #1
0
        public void Execute(ref Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
        {
            dynamic        transformMetaData;
            SchemaMetadata sourceSchemaMetadata;
            string         schemaName;
            SchemaMetadata targetSchemaMetadata;

            try
            {
                transformMetaData    = TransformMetaData.For(mapType);
                sourceSchemaMetadata = transformMetaData.SourceSchemas[0];
                schemaName           = sourceSchemaMetadata.SchemaName;
                targetSchemaMetadata = transformMetaData.TargetSchemas[0];
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Exception encountered while trying to instantiate map {0}, exception details - {1}", mapName, e.Message));
            }

            if (validateSourceSchema == TransformationSourceSchemaValidation.ValidateSourceSchema || validateSourceSchema == TransformationSourceSchemaValidation.ValidateSourceSchemaIfKnown)
            {
                object property = inmsg.Context.Read(BizTalkGlobalPropertySchemaEnum.MessageType.ToString(), ContextPropertyNamespaces._BTSPropertyNamespace);

                if (property == null)
                {
                    if (validateSourceSchema == TransformationSourceSchemaValidation.ValidateSourceSchema)
                    {
                        throw new Exception("Unable to read source messageType while performing transformation against map " + mapName);
                    }
                }
                else
                {
                    string messageType = property.ToString();

                    if (!string.IsNullOrEmpty(messageType))
                    {
                        if (string.Compare(messageType, schemaName, false, CultureInfo.CurrentCulture) != 0)
                        {
                            throw new Exception(String.Format("Transformation mismatch exception for map {0}, was expecting source schema to be {1} but was actually {2}.", mapName, schemaName, messageType));
                        }
                    }
                }
            }

            try
            {
                dynamic transform = transformMetaData.Transform2;
                Stream  output    = new VirtualStream();

                TraceManager.PipelineComponent.TraceInfo("{0} - Applying transformation {1} to the message", callToken, mapName);
                TraceManager.PipelineComponent.TraceInfo("{0} - Message is being transformed from message type {1} to message type {2}", callToken, schemaName, targetSchemaMetadata.SchemaName);

                //TODO figure out what is suppose to go in this null object instead of null.
                transform.Transform(inmsg.BodyPart.GetOriginalDataStream(), null, output);
                output.Position = 0;
                pc.ResourceTracker.AddResource(output);

                inmsg.BodyPart.Data = output;
                inmsg.Context.Write(BizTalkGlobalPropertySchemaEnum.SchemaStrongName.ToString(), ContextPropertyNamespaces._BTSPropertyNamespace, null);
                inmsg.Context.Promote(BizTalkGlobalPropertySchemaEnum.MessageType.ToString(), ContextPropertyNamespaces._BTSPropertyNamespace, targetSchemaMetadata.SchemaName);
            }
            catch (Exception e)
            {
                throw new Exception("Exception encountered while trying to execute map - " + e.Message);
            }
        }
Exemple #2
0
        public static void ArchivetoStorage(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, string FullFilePath, bool ReadFullContext)
        {
            StringBuilder          SBContext = new StringBuilder();
            ReadOnlySeekableStream stream    = new ReadOnlySeekableStream(inmsg.BodyPart.GetOriginalDataStream());
            Stream sourceStream = inmsg.BodyPart.GetOriginalDataStream();
            List <JsonContextProperty> jsonContextpropertylist = new List <JsonContextProperty>();

            if (!sourceStream.CanSeek)
            {
                ReadOnlySeekableStream seekableStream = new ReadOnlySeekableStream(sourceStream);

                inmsg.BodyPart.Data = seekableStream;

                sourceStream = inmsg.BodyPart.Data;
            }

            if (inmsg.BodyPart != null)
            {
                string        json          = "NA";
                VirtualStream virtualStream = new VirtualStream(sourceStream);
                //ArchiveToFileLocation(virtualStream, FullFilePath);
                //virtualStream.Seek(0, SeekOrigin.Begin);
                inmsg.BodyPart.Data = virtualStream;


                if (ReadFullContext == true)
                {
                    IBaseMessageContext ctx = inmsg.Context;
                    string name;
                    string nspace;

                    for (int loop = 0; loop < ctx.CountProperties; loop++)
                    {
                        ctx.ReadAt(loop, out name, out nspace);
                        string value = ctx.Read(name, nspace).ToString();
                        jsonContextpropertylist.Add(new JsonContextProperty()
                        {
                            Name      = name,
                            NameSpace = nspace,
                            Value     = value
                        });
                    }
                    json = JsonConvert.SerializeObject(jsonContextpropertylist);
                }
                string InterchangeID = inmsg.Context.Read("InterchangeID", "http://schemas.microsoft.com/BizTalk/2003/system-properties").ToString();
                string ServiceName   = "NA";
                if (inmsg.Context.Read("ReceivePortID", "http://schemas.microsoft.com/BizTalk/2003/system-properties") != null)
                {
                    ServiceName = inmsg.Context.Read("ReceiveLocationName", "http://schemas.microsoft.com/BizTalk/2003/system-properties").ToString();
                }
                else if (inmsg.Context.Read("SPID", "http://schemas.microsoft.com/BizTalk/2003/system-properties") != null)
                {
                    ServiceName = inmsg.Context.Read("SPName", "http://schemas.microsoft.com/BizTalk/2003/system-properties").ToString();
                }

                string msgId = inmsg.MessageID.ToString();

                SqlConnection Conn = new SqlConnection("Server=BT360DEV34\\MSSQLSERVER1;Database=B360_BAM;Integrated Security=True;");


                SqlCommand command = new SqlCommand(
                    "INSERT INTO [dbo].[CustomTrackTbl] " +
                    "([ActivityID] " +
                    ",[CorrelationID] " +
                    ",[StartTime] " +
                    ",[EndTime] " +
                    ",[ServiceName] " +
                    ",[MsgContext] " +
                    ",[StreamMsgPayload] " +
                    ",[RawMsgPayload] " +
                    ",[Status] " +
                    ",[MessageArchiveLocation])" +
                    "VALUES(@ActivityID,@CorrelationID,@StartTime,@EndTime,@ServiceName,@MsgContext,@StreamMsgPayload,@RawMsgPayload,@Status,@MessageArchiveLocation)", Conn);

                command.Parameters.Add("@ActivityID", SqlDbType.VarChar).Value    = msgId;
                command.Parameters.Add("@CorrelationID", SqlDbType.VarChar).Value = InterchangeID;
                command.Parameters.Add("@StartTime", SqlDbType.VarChar).Value     = DateTime.Now.ToString();
                command.Parameters.Add("@EndTime", SqlDbType.VarChar).Value       = DateTime.Now.ToString();
                command.Parameters.Add("@ServiceName", SqlDbType.VarChar).Value   = ServiceName;
                command.Parameters.Add("@MsgContext", SqlDbType.VarChar).Value    = json;
                sourceStream.Position = 0;
                command.Parameters.Add("@StreamMsgPayload", SqlDbType.Binary).Value        = sourceStream;
                command.Parameters.Add("@RawMsgPayload", SqlDbType.VarChar).Value          = "NA";
                command.Parameters.Add("@Status", SqlDbType.VarChar, 255).Value            = "Success";
                command.Parameters.Add("@MessageArchiveLocation", SqlDbType.VarChar).Value = FullFilePath;

                Conn.Open();
                command.ExecuteNonQuery();
                Conn.Close();
            }
        }
Exemple #3
0
 public void Execute(ref Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
 {
     inmsg = PipelineExecutionHelper.Execute(component, inmsg, pc);
 }
Exemple #4
0
 public void Execute(ref Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
 {
     if (xmlFactsApplicationStage == XMLFactsApplicationStageEnum.Explicit)
     {
         TypedXMLDocumentWrapper.ApplyTypedXMLDocument(document, inmsg, pc, callToken);
     }
 }
Exemple #5
0
        public void Execute(ref Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
        {
            var stream = new MessageModificationTranslatorStream(inmsg.BodyPart.GetOriginalDataStream(), _messageModificationDetails, callToken);

            inmsg.BodyPart.Data = stream;
            pc.ResourceTracker.AddResource(stream);
        }
Exemple #6
0
        /// <summary>
        /// Static method to apply a TypedXMLDocument to a BizTalk message body
        /// </summary>
        /// <param name="document"></param>
        /// <param name="inmsg"></param>
        /// <param name="pc"></param>
        /// <param name="callToken"></param>
        public static void ApplyTypedXMLDocument(TypedXmlDocument document, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc, string callToken)
        {
            TraceManager.PipelineComponent.TraceInfo("{0} - Applying typed XML document (overwriting current message body)", callToken);

            XmlDocument   doc = (XmlDocument)document.Document;
            VirtualStream ms  = new VirtualStream();

            doc.Save(ms);
            ms.Position         = 0;
            inmsg.BodyPart.Data = ms;

            // Add the new message body part's stream to the Pipeline Context's resource tracker so that it will be disposed off correctly
            pc.ResourceTracker.AddResource(ms);
        }
Exemple #7
0
 /// <summary>
 /// Instantiate the TypedXMLDocumentWrapper passing in the original message body stream
 /// </summary>
 /// <param name="DocumentStream"></param>
 public TypedXMLDocumentWrapper(Stream DocumentStream, Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
 {
     this.documentStream = DocumentStream;
     this.pc             = pc;
     hasBeenSet          = false;
 }
Exemple #8
0
        public void Execute(ref Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
        {
            StringBuilder outboundHeadersBuilder = new StringBuilder();

            foreach (KeyValuePair <string, string> kp in outboundHTTPHeadersCollection)
            {
                outboundHeadersBuilder.AppendFormat("{0}: {1}", kp.Key, kp.Value);
                outboundHeadersBuilder.Append(Environment.NewLine);
            }

            string outboundHeaders = outboundHeadersBuilder.ToString();

            TraceManager.PipelineComponent.TraceInfo(callToken + " - Adding outbound HTTP headers to the message with the below value " + Environment.NewLine + outboundHeaders);
            inmsg.Context.Write(BizTalkWCFPropertySchemaEnum.HttpHeaders.ToString(), ContextPropertyNamespaces._WCFPropertyNamespace, outboundHeaders);
            inmsg.Context.Write(BizTalkGlobalPropertySchemaEnum.IsDynamicSend.ToString(), ContextPropertyNamespaces._BTSPropertyNamespace, true);
        }