コード例 #1
0
        void IAssemblerComponent.AddDocument(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            if (this.GetFault(pInMsg) != null)
            {
                qOutputMsgs.Enqueue(pInMsg);
            }
            else
            {
                MultipartMessageDefinition tempMessage = MultipartMessageManager.GenerateFromMessage(pInMsg);

                StringWriter  sw  = new StringWriter();
                XmlSerializer ser = new XmlSerializer(typeof(MultipartMessageDefinition), Constants.SUBMISSION_NAMESPACE);
                ser.Serialize(sw, tempMessage);
                byte[]       arrByte    = System.Text.Encoding.UTF8.GetBytes(sw.ToString().Replace("utf-16", "utf-8")); //GetBytes(sw.ToString().Replace("utf-16", "utf-8")); //GetBytes(sw.ToString());
                MemoryStream tempStream = new MemoryStream(arrByte);
                tempStream.Seek(0, SeekOrigin.Begin);

                IBaseMessage     outMsg  = pContext.GetMessageFactory().CreateMessage();
                IBaseMessagePart outPart = pContext.GetMessageFactory().CreateMessagePart();
                outPart.Data    = tempStream;
                outPart.Charset = "utf-8";
                outMsg.AddPart("ConstructedPart", outPart, true);
                //outMsg.BodyPart.Data = tempStream;

                outMsg.Context = pInMsg.Context;
                outMsg.Context.Promote(BTSProperties.messageType.Name.Name, BTSProperties.messageType.Name.Namespace, "http://BizWTF.Mocking.Schemas.Submission#MultipartMessage");


                qOutputMsgs.Enqueue(outMsg);
                pContext.ResourceTracker.AddResource(tempStream);
            }
        }
        /// <summary>
        /// Implements IComponent.Execute method.
        /// </summary>
        /// <param name="pc">Pipeline context</param>
        /// <param name="inmsg">Input message.</param>
        /// <returns>Processed input message with appended or prepended data.</returns>
        /// <remarks>
        /// Converts xsl-fo transformed messages to pdf
        /// </remarks>
        public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
        {
            IBaseMessagePart bodyPart = inmsg.BodyPart;

            if (bodyPart.Data != null)
            {
                VirtualStream vtstm = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk);

                FonetDriver driver = FonetDriver.Make();
                driver.CloseOnExit = false;//important for biztalk to work ... set position = 0

                PdfRendererOptions options = new PdfRendererOptions();
                options.Title        = Title;
                options.Subject      = Subject;
                options.UserPassword = Password;

                driver.Options = options;

                Stream stm = bodyPart.GetOriginalDataStream();
                stm.Seek(0, SeekOrigin.Begin);

                driver.Render(stm, vtstm);

                vtstm.Seek(0, SeekOrigin.Begin);

                bodyPart.Data = vtstm;
            }
            return(inmsg);
        }
コード例 #3
0
        private IBaseMessage BuildBTSMessage(IPipelineContext pContext, IBaseMessageContext sourceContext, List <Part> partList)
        {
            IBaseMessage     newMessage = pContext.GetMessageFactory().CreateMessage();
            IBaseMessagePart msgPart    = pContext.GetMessageFactory().CreateMessagePart();

            newMessage.Context = sourceContext;
            foreach (Part part in partList)
            {
                if (part.Data != null)
                {
                    msgPart.Charset     = "utf-8";
                    msgPart.ContentType = part.ContentType;
                    msgPart.Data        = GetPartStream(part.Data);
                    newMessage.AddPart(part.PartName, msgPart, part.IsBodyPart);
                }
                else
                {
                    System.IO.MemoryStream memStrm = new MemoryStream();
                    StreamWriter           sw      = new StreamWriter(memStrm);
                    sw.Write(part.RawData);
                    sw.Flush();
                    memStrm.Position = 0;

                    msgPart.ContentType = part.ContentType;
                    msgPart.Data        = memStrm;
                    newMessage.AddPart(part.PartName, msgPart, part.IsBodyPart);
                }
            }
            return(newMessage);
        }
コード例 #4
0
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            XmlDocument sourceDoc = new XmlDocument();

            pInMsg.BodyPart.Data.Position = 0;
            sourceDoc.Load(pInMsg.BodyPart.Data);


            XmlDocument outputDoc = Tools.ApplyXSLTransform(sourceDoc, TransformResources.MAP_ToMockService);

            byte[]       arrByte    = System.Text.Encoding.UTF8.GetBytes(outputDoc.OuterXml.Replace("utf-16", "utf-8"));
            MemoryStream tempStream = new MemoryStream(arrByte);

            tempStream.Seek(0, SeekOrigin.Begin);


            IBaseMessage     outMsg      = pContext.GetMessageFactory().CreateMessage();
            IBaseMessagePart bodyMsgPart = pContext.GetMessageFactory().CreateMessagePart();

            bodyMsgPart.Data    = tempStream;
            bodyMsgPart.Charset = "utf-8";
            outMsg.AddPart("body", bodyMsgPart, true);

            outMsg.Context = pInMsg.Context;
            outMsg.Context.Promote(BTSProperties.messageType.Name.Name, BTSProperties.messageType.Name.Namespace, "http://NWT.Mocking.Services#SubmitMessage");


            pContext.ResourceTracker.AddResource(tempStream);
            return(outMsg);
        }
コード例 #5
0
        /// <summary>
        /// copies all message parts part of the inbound message onto the outbound message
        /// </summary>
        /// <param name="pc">the <see cref="IPipelineContext"/> this message belongs to</param>
        /// <param name="inmsg">the inbound message</param>
        /// <param name="outmsg">the outbound message</param>
        /// <param name="bodyPart">the body part</param>
        /// <param name="allowUnrecognizeMessage">whether to allow unrecognized messages</param>
        public static void CopyMessageParts(
            IPipelineContext pc,
            IBaseMessage inmsg,
            IBaseMessage outmsg,
            IBaseMessagePart bodyPart,
            bool allowUnrecognizeMessage)
        {
            string text1 = inmsg.BodyPartName;

            for (int num1 = 0; num1 < inmsg.PartCount; num1++)
            {
                string           text2 = null;
                IBaseMessagePart part1 = inmsg.GetPartByIndex(num1, out text2);
                if ((part1 == null) && !allowUnrecognizeMessage)
                {
                    throw new ArgumentNullException("otherOutPart[" + num1 + "]");
                }
                if (text1 != text2)
                {
                    outmsg.AddPart(text2, part1, false);
                }
                else
                {
                    outmsg.AddPart(text1, bodyPart, true);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Creates IBaseMessage objects from array of streams
        /// </summary>
        /// <param name="mf">Reference to BizTalk message factory object</param>
        /// <param name="url">Address of receive location where this message will be submitted to</param>
        /// <param name="data">Payloads for each message</param>
        /// <returns>Array of BizTalk message objects</returns>
        public static IBaseMessage[] CreateMessages(IBaseMessageFactory mf, string url, Stream[] data)
        {
            IBaseMessagePart    part = null;
            IBaseMessageContext ctx  = null;

            IBaseMessage[]       msgs = null;
            SystemMessageContext smc  = null;

            msgs = new IBaseMessage[data.Length];

            for (int c = 0; c < data.Length; c++)
            {
                // Create a new message
                msgs[c]   = mf.CreateMessage();
                part      = mf.CreateMessagePart();
                part.Data = data[c];
                ctx       = msgs[c].Context;
                msgs[c].AddPart("body", part, true);

                // Set the system context properties
                smc = new SystemMessageContext(ctx);
                if (null != url)
                {
                    smc.InboundTransportLocation = url;
                }
            }

            return(msgs);
        }
コード例 #7
0
        /// <summary>
        /// Creates IBaseMessage object from string
        /// </summary>
        /// <param name="mf">Reference to BizTalk message factory object</param>
        /// <param name="url">Address of receive location where this message will be submitted</param>
        /// <param name="data">Payload of the message</param>
        /// <returns>BizTalk message object</returns>
        public static IBaseMessage CreateMessage(IBaseMessageFactory mf, string url, string data)
        {
            IBaseMessagePart     part = null;
            IBaseMessageContext  ctx  = null;
            IBaseMessage         msg  = null;
            SystemMessageContext smc  = null;

            // Write the data to a new stream...
            StreamWriter sw = new StreamWriter(new MemoryStream());

            sw.Write(data);
            sw.Flush();
            sw.BaseStream.Seek(0, SeekOrigin.Begin);

            // Create a new message
            msg       = mf.CreateMessage();
            part      = mf.CreateMessagePart();
            part.Data = sw.BaseStream;
            ctx       = msg.Context;
            msg.AddPart("body", part, true);

            // Set the system context properties
            smc = new SystemMessageContext(ctx);
            if (null != url)
            {
                smc.InboundTransportLocation = url;
            }

            return(msg);
        }
コード例 #8
0
        /// <summary>
        /// Creates an array of IBaseMessage objects from array of strings
        /// </summary>
        /// <param name="mf">Reference to BizTalk message factory object</param>
        /// <param name="url">Address of receive location where this message will be submitted to</param>
        /// <param name="data">Payloads for each message</param>
        /// <returns>Array of BizTalk message objects</returns>
        public static IBaseMessage[] CreateMessages(IBaseMessageFactory mf, string url, string[] data)
        {
            IBaseMessagePart    part = null;
            IBaseMessageContext ctx  = null;

            IBaseMessage[]       msgs = null;
            SystemMessageContext smc  = null;

            msgs = new IBaseMessage[data.Length];

            for (int c = 0; c < data.Length; c++)
            {
                // Write the data to a new stream...
                StreamWriter sw = new StreamWriter(new MemoryStream());
                sw.Write(data[c]);
                sw.Flush();
                sw.BaseStream.Seek(0, SeekOrigin.Begin);

                // Create a new message
                msgs[c]   = mf.CreateMessage();
                part      = mf.CreateMessagePart();
                part.Data = sw.BaseStream;
                ctx       = msgs[c].Context;
                msgs[c].AddPart("body", part, true);

                // Set the system context properties
                smc = new SystemMessageContext(ctx);
                if (null != url)
                {
                    smc.InboundTransportLocation = url;
                }
            }

            return(msgs);
        }
コード例 #9
0
ファイル: MessageHelper.cs プロジェクト: radtek/DevOps
        /// <summary>
        /// Obtains a byte array representation of an IBaseMessagePart. The underlying message stream is read in
        /// order to populate the byte array.
        /// </summary>
        /// <param name="pipelineContext">The pipeline context.</param>
        /// <param name="messagePart">The message part.</param>
        /// <returns>A byte array representation of the IBaseMessagePart.</returns>
        public static byte[] MessageToByteArray(IPipelineContext pipelineContext, IBaseMessagePart messagePart)
        {
            byte[] buffer     = null;
            Stream dataStream = null;

            try
            {
                dataStream = GetReadOnlySeekableDataStream(pipelineContext, messagePart);
                if (dataStream.Position != 0L)
                {
                    dataStream.Position = 0L;
                }
                byte[] bufferFromStream = new byte[dataStream.Length];
                int    count            = dataStream.Read(bufferFromStream, 0, bufferFromStream.Length);
                buffer = bufferFromStream;
            }
            catch (Exception)
            {
                // Ignore exceptions here. If the document can not be read into a byte array then the method returns null.
            }
            finally
            {
                if (dataStream != null && dataStream.CanSeek)
                {
                    dataStream.Position = 0L;
                }
            }
            return(buffer);
        }
コード例 #10
0
ファイル: Utility.cs プロジェクト: HydAu/QLBizTalk2013
        internal static IBaseMessage CloneMessage(IBaseMessage inmsg, IPipelineContext pc)
        {
            IBaseMessageFactory messageFactory = pc.GetMessageFactory();

            var outmsg = messageFactory.CreateMessage();

            outmsg.Context = PipelineUtil.CloneMessageContext(inmsg.Context);

            // Generate new empty message body part, we will retain nothing from the old
            IBaseMessagePart body = messageFactory.CreateMessagePart();

            if ((inmsg != null) && (inmsg.BodyPart != null))
            {
                body.PartProperties = PipelineUtil.CopyPropertyBag(inmsg.BodyPart.PartProperties, messageFactory);
            }

            // This is what the XmlWriter will end up generating, and what appears in the
            // directive at the top of the file
            body.Charset     = "UTF-8";
            body.ContentType = "text/xml";
            body.Data        = null;

            CloneParts(pc, inmsg, outmsg, body);

            return(outmsg);
        }
コード例 #11
0
        private IBaseMessage CreateMessage(Shared.Components.Entry message)
        {
            MemoryStream mem = new MemoryStream(UTF8Encoding.UTF8.GetBytes(message.Content));

            IBaseMessageFactory factory = this.transportProxy.GetMessageFactory();
            IBaseMessagePart    part    = factory.CreateMessagePart();

            part.Data = mem;

            IBaseMessage msg = factory.CreateMessage();

            msg.AddPart("body", part, true);

            //  We must add these context properties
            SystemMessageContext context = new SystemMessageContext(msg.Context);

            context.InboundTransportLocation = this.uri;
            context.InboundTransportType     = this.transportType;
            //Set ActionOnFailure to zero in the context property of each messaqe that you do not want BizTalk Server to suspend on a processing exception.
            //Failure to set this property allows BizTalk Server to fall back to its default behavior
            //of suspending the message on a processing exception.
            //context.ActionOnFailure = 0;

            //we could promote entity id and updated, msg.Context.Promote(ns, message.Id
            return(msg);
        }
コード例 #12
0
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            string errorMessage;

            if (!Validate(out errorMessage))
            {
                throw new ArgumentException(errorMessage);
            }

            String value = null;

            IBaseMessagePart bodyPart = pInMsg.BodyPart;

            Stream                 inboundStream          = bodyPart.GetOriginalDataStream();
            VirtualStream          virtualStream          = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk);
            ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream);

            XmlTextReader   xmlTextReader   = new XmlTextReader(readOnlySeekableStream);
            XPathCollection xPathCollection = new XPathCollection();
            XPathReader     xPathReader     = new XPathReader(xmlTextReader, xPathCollection);

            xPathCollection.Add(XPath);

            while (xPathReader.ReadUntilMatch())
            {
                if (xPathReader.Match(0))
                {
                    if (xPathReader.NodeType == XmlNodeType.Attribute)
                    {
                        value = xPathReader.GetAttribute(xPathReader.Name);
                    }
                    else
                    {
                        value = xPathReader.ReadString();
                    }

                    if (PromoteProperty)
                    {
                        pInMsg.Context.Promote(new ContextProperty(PropertyPath), value);
                    }
                    else
                    {
                        pInMsg.Context.Write(new ContextProperty(PropertyPath), value);
                    }

                    break;
                }
            }

            if (string.IsNullOrEmpty(value) && ThrowIfNoMatch)
            {
                throw new InvalidOperationException("The specified XPath did not exist or contained an empty value.");
            }

            readOnlySeekableStream.Position = 0;
            pContext.ResourceTracker.AddResource(readOnlySeekableStream);
            bodyPart.Data = readOnlySeekableStream;

            return(pInMsg);
        }
コード例 #13
0
        IBaseMessage IComponent.Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            Trace.WriteLine("DotNetTypesToJsonConverter Pipeline - Entered Execute()");
            Trace.WriteLine("DotNetTypesToJsonConverter Pipeline - TypeName is set to: " + TypeName);

            IBaseMessagePart bodyPart = pInMsg.BodyPart;

            if (bodyPart != null)
            {
                Stream originalStream = bodyPart.GetOriginalDataStream();
                if (originalStream != null)
                {
                    Type myClassType = Type.GetType(TypeName);

                    object reqObj = PcHelper.FromXml(originalStream, myClassType);

                    string jsonText = JsonConvert.SerializeObject(reqObj, myClassType, Formatting.None,
                                                                  new JsonSerializerSettings());
                    Trace.WriteLine("DotNetTypesToJsonConverter output: " + jsonText);

                    byte[] outBytes = Encoding.ASCII.GetBytes(jsonText);

                    var memStream = new MemoryStream();
                    memStream.Write(outBytes, 0, outBytes.Length);
                    memStream.Position = 0;

                    bodyPart.Data = memStream;
                    pContext.ResourceTracker.AddResource(memStream);
                }
            }
            Trace.WriteLine("DotNetTypesToJsonConverter Pipeline - Exited Execute()");
            return(pInMsg);
        }
コード例 #14
0
        /// <summary>
        /// Returns an XmlDocument over the message part content.
        /// </summary>
        /// <param name="messagePart">A pipeline messagePart part.</param>
        /// <returns>An XML document.</returns>
        public static XmlDocument AsXmlDocument(this IBaseMessagePart messagePart)
        {
            var bodyXml = new XmlDocument();

            // Preserve whitespace to render document as original by default
            bodyXml.PreserveWhitespace = true;

            if (messagePart.Data == null)
            {
                return(bodyXml);
            }

            var currentPosition = messagePart.Data.Position;

            messagePart.WithStreamAtStart();

            try
            {
                bodyXml.Load(messagePart.Data);
            }
            catch (XmlException)
            {
                return(new XmlDocument());
            }

            messagePart.Data.Seek(currentPosition, SeekOrigin.Begin);
            return(bodyXml);
        }
        private IBaseMessage CreateMessage(BrokeredMessage message)
        {
            Stream stm = message.GetBody <Stream>();


            IBaseMessageFactory factory = this.transportProxy.GetMessageFactory();
            IBaseMessagePart    part    = factory.CreateMessagePart();

            part.Data = stm;



            IBaseMessage msg = factory.CreateMessage();

            msg.AddPart("body", part, true);

            //  We must add these context properties
            SystemMessageContext context = new SystemMessageContext(msg.Context);

            context.InboundTransportLocation = this.uri;
            context.InboundTransportType     = this.transportType;

            msg.Context.Promote("SequenceNumber", this.propertyNamespace, message.SequenceNumber.ToString());

            return(msg);
        }
コード例 #16
0
        /// <summary>
        /// Remove outer nodes from the message part content and leave the body.
        /// </summary>
        /// <param name="messagePart">The message part</param>
        /// <param name="bodyContainerXPath">The XPath specifying the body of the message.</param>
        /// <returns>The message part with the envelope removed.</returns>
        public static IBaseMessagePart RemoveEnvelope(this IBaseMessagePart messagePart, string bodyContainerXPath)
        {
            if (string.IsNullOrEmpty(bodyContainerXPath))
            {
                return(messagePart);
            }

            var bodyXml = messagePart.AsXmlDocument();

            // Assign content back to part
            var contentStream    = new MemoryStream();
            var sw               = new StreamWriter(contentStream);
            var selectSingleNode = bodyXml.SelectSingleNode(bodyContainerXPath);

            if (selectSingleNode != null)
            {
                sw.Write(selectSingleNode.FirstChild.OuterXml);
            }

            sw.Flush();
            contentStream.StreamAtStart();

            messagePart.Data = contentStream;
            return(messagePart);
        }
コード例 #17
0
        /// <summary>
        /// Create the output message when validation errors are captured
        /// </summary>
        /// <param name="pContext">Pipeline context</param>
        /// <param name="pInMsg">Input message in  the pipeline</param>
        /// <param name="errorStream">Stream for the Validation Errors</param>
        /// <param name="requestId">Request Id</param>
        /// <returns></returns>
        public static IBaseMessage CreateOutPutMessage(IPipelineContext pContext, IBaseMessage pInMsg, VirtualStream errorStream, string requestId)
        {
            VirtualStream seekableStream = new VirtualStream(pInMsg.BodyPart.GetOriginalDataStream());

            seekableStream.Position = 0;
            errorStream.Position    = 0;
            VirtualStream outMsgStream = CreateValidationErrorMessage(seekableStream, errorStream, requestId);

            outMsgStream.Position = 0;

            IBaseMessageFactory messageFactory  = pContext.GetMessageFactory();
            IBaseMessage        pOutMsg         = messageFactory.CreateMessage();
            IBaseMessagePart    pOutMsgBodyPart = messageFactory.CreateMessagePart();
            IBasePropertyBag    pOutPb          = PipelineUtil.CopyPropertyBag(pInMsg.BodyPart.PartProperties, messageFactory);

            pOutMsg.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);

            pOutMsgBodyPart.Charset     = Constants.BodyPartCharSet;
            pOutMsgBodyPart.ContentType = Constants.BodyPartContentType;
            pOutMsgBodyPart.Data        = outMsgStream;
            string outMessageType = string.Format("{0}#{1}", Constants.AIBPValidationErrorNameSpace, Constants.AIBPValidationErrorRootNode);

            pOutMsg.Context.Promote(Constants.MessageTypePropName, Constants.SystemPropertiesNamespace, outMessageType);

            pOutMsg.AddPart("Body", pOutMsgBodyPart, true);

            // Add resources to the resource tracker to be disposed of at correct time
            pContext.ResourceTracker.AddResource(seekableStream);
            pContext.ResourceTracker.AddResource(outMsgStream);
            pContext.ResourceTracker.AddResource(errorStream);
            return(pOutMsg);
        }
コード例 #18
0
        public object Clone()
        {
            int partCount = this.PartCount;
            IBaseMessageFactory factory  = new MessageFactory();
            IBaseMessage        message  = factory.CreateMessage();
            Message             message2 = (Message)message;

            message2.messageId = this.MessageID;
            IBaseMessageContext oldCtx = this.Context;

            if (oldCtx != null)
            {
                IBaseMessageContext context2 = PipelineUtil.CloneMessageContext(oldCtx);
                message.Context = context2;
            }
            Exception errorInfo = this.GetErrorInfo();

            if (errorInfo != null)
            {
                message.SetErrorInfo(errorInfo);
            }
            string bodyPartName = this.BodyPartName;

            for (int i = 0; i < partCount; i++)
            {
                string           str2;
                IBaseMessagePart partByIndex = this.GetPartByIndex(i, out str2);
                IBaseMessagePart part        = ((MessagePart)partByIndex).CopyMessagePart(factory);
                message.AddPart(str2, part, bodyPartName == str2);
            }
            return(message);
        }
コード例 #19
0
        private string GetFileName(IBaseMessagePart part)
        {
            var    receivedFileNameProperty = new ContextProperty(FileProperties.ReceivedFileName);
            var    receivedFileName         = part.PartProperties.Read(receivedFileNameProperty.PropertyName, receivedFileNameProperty.PropertyNamespace) as string;
            string fileName;
            string extension = string.Empty;

            if (!string.IsNullOrEmpty(receivedFileName))
            {
                fileName = receivedFileName;
            }
            else
            {
                if (!string.IsNullOrEmpty(part.ContentType))
                {
                    extension = MimeUtils.GetFileExtensionForMimeType(part.ContentType);
                }
                else if (!string.IsNullOrEmpty(DefaultZipEntryFileExtension))
                {
                    extension = string.Concat(".", DefaultZipEntryFileExtension);
                }


                fileName = Guid.NewGuid() + extension;
            }

            return(fileName);
        }
コード例 #20
0
        /// <summary>
        /// Synchronously executes the task using the specified <see cref="RuntimeTaskExecutionContext"/> execution context object.
        /// </summary>
        /// <param name="context">The execution context.</param>
        public override void Run(RuntimeTaskExecutionContext context)
        {
            var callToken = TraceManager.CustomComponent.TraceIn();

            IBaseMessageFactory msgFactory     = context.PipelineContext.GetMessageFactory();
            IBaseMessage        responseMsg    = msgFactory.CreateMessage();
            IBaseMessageContext responseMsgCtx = msgFactory.CreateMessageContext();
            IBaseMessageContext requestMsgCtx  = context.Message.Context;

            responseMsg.Context = responseMsgCtx;

            if (BizTalkUtility.ContainsResponsePart(context.Message))
            {
                IBaseMessagePart responsePart = BizTalkUtility.GetResponsePart(context.Message);
                responseMsg.AddPart(context.Message.BodyPartName, responsePart, true);
            }
            else
            {
                responseMsg.AddPart(context.Message.BodyPartName, context.Message.BodyPart, true);
            }

            responseMsgCtx.Promote(EpmRRCorrelationToken.Name.Name, EpmRRCorrelationToken.Name.Namespace, requestMsgCtx.Read(EpmRRCorrelationToken.Name.Name, EpmRRCorrelationToken.Name.Namespace));
            responseMsgCtx.Promote(RouteDirectToTP.Name.Name, RouteDirectToTP.Name.Namespace, true);
            responseMsgCtx.Promote(CorrelationToken.Name.Name, CorrelationToken.Name.Namespace, requestMsgCtx.Read(CorrelationToken.Name.Name, CorrelationToken.Name.Namespace));
            responseMsgCtx.Promote(ReqRespTransmitPipelineID.Name.Name, ReqRespTransmitPipelineID.Name.Namespace, requestMsgCtx.Read(ReqRespTransmitPipelineID.Name.Name, ReqRespTransmitPipelineID.Name.Namespace));
            responseMsgCtx.Write(ReceivePipelineResponseConfig.Name.Name, ReceivePipelineResponseConfig.Name.Namespace, requestMsgCtx.Read(ReceivePipelineResponseConfig.Name.Name, ReceivePipelineResponseConfig.Name.Namespace));

            context.Message = responseMsg;

            TraceManager.CustomComponent.TraceOut(callToken);
        }
コード例 #21
0
        private string GetFileName(IBaseMessagePart part)
        {
            var receivedFileNameProperty = new ContextProperty(FileProperties.ReceivedFileName);
            var receivedFileName = part.PartProperties.Read(receivedFileNameProperty.PropertyName, receivedFileNameProperty.PropertyNamespace) as string;
            string fileName;
            string extension = string.Empty;
            if (!string.IsNullOrEmpty(receivedFileName))
            {
                fileName = receivedFileName;
            }
            else
            {
                if (!string.IsNullOrEmpty(part.ContentType))
                {
                    extension = MimeUtils.GetFileExtensionForMimeType(part.ContentType);
                }
                else if (!string.IsNullOrEmpty(DefaultZipEntryFileExtension))
                {
                    extension = string.Concat(".",DefaultZipEntryFileExtension);
                }

                fileName = Guid.NewGuid() + extension;
            }

            return fileName;
        }
コード例 #22
0
 public static void CloneAndAddMessageParts(IPipelineContext pipelineContext, IBaseMessage sourceMessage, IBaseMessage destinationMessage)
 {
     if (pipelineContext == null)
     {
         throw new ArgumentNullException("pipelineContext");
     }
     if (sourceMessage == null)
     {
         throw new ArgumentNullException("sourceMessage");
     }
     if (destinationMessage == null)
     {
         throw new ArgumentNullException("destinationMessage");
     }
     try
     {
         string bodyPartName = sourceMessage.BodyPartName;
         for (int index = 0; index < sourceMessage.PartCount; ++index)
         {
             string           partName    = (string)null;
             IBaseMessagePart partByIndex = sourceMessage.GetPartByIndex(index, out partName);
             IBaseMessagePart part        = MessageHelper.CloneMessagePart(pipelineContext, partByIndex);
             bool             bBody       = string.Compare(partName, bodyPartName, true, CultureInfo.CurrentCulture) == 0;
             destinationMessage.AddPart(partName, part, bBody);
         }
     }
     catch (Exception ex)
     {
         DECore.TraceProvider.Logger.TraceError(ex);
         throw;
     }
 }
コード例 #23
0
        public void SubmitMessage(IBaseMessage message, object userData = null)
        {
            if (_submitResponseMessageArray != null)
            {
                throw new InvalidOperationException("SubmitResponseMessage and SubmitMessage operations cannot be in the same batch");
            }

            // We need to have data (body part) to handle batch failures.
            IBaseMessagePart bodyPart = message.BodyPart;

            if (bodyPart == null)
            {
                throw new InvalidOperationException("The message doesn't contain body part");
            }

            Stream stream = bodyPart.GetOriginalDataStream();

            if (stream == null || stream.CanSeek == false)
            {
                throw new InvalidOperationException("Cannot submit empty body or body with non-seekable stream");
            }

            _transportBatch.SubmitMessage(message);
            if (null == _submitArray)
            {
                _submitArray = new List <BatchMessage>();
            }
            _submitArray.Add(new BatchMessage(message, userData));

            _workToBeDone = true;
        }
コード例 #24
0
        /// <summary>
        /// (1) Gets the file from the sftp host
        /// (2) Creates a IBaseMessage
        /// (3) Sets varius properties such as uri, messagepart, transporttype etc
        /// (4) Adds the message to the batch
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="uri"></param>
        /// <param name="size"></param>
        /// <param name="afterGetAction"></param>
        /// <param name="afterGetFilename"></param>
        /// <returns></returns>
        internal IBaseMessage CreateMessage(string fileName, string uri, long size,
                                            SftpReceiveProperties.AfterGetActions afterGetAction, string afterGetFilename)
        {
            try
            {
                TraceMessage("[SftpReceiverEndpoint] Reading file to stream " + fileName);

                // Retrieves the message from sftp server.
                var stream = _sftp.Get(fileName);
                stream.Position = 0;


                // Creates new message
                IBaseMessageFactory messageFactory = _transportProxy.GetMessageFactory();
                IBaseMessagePart    part           = messageFactory.CreateMessagePart();
                part.Data = stream;
                var message = messageFactory.CreateMessage();
                message.AddPart(MessageBody, part, true);

                // Setting metadata
                SystemMessageContext context =
                    new SystemMessageContext(message.Context)
                {
                    InboundTransportLocation = uri,
                    InboundTransportType     = _transportType
                };

                // Write/Promote any adapter specific properties on the message context
                message.Context.Write(Remotefilename, _propertyNamespace, fileName);

                SetReceivedFileName(message, fileName);

                message.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/" +
                                      _transportType.ToLower() + "-properties", fileName);

                message.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", fileName);

                // Add the file to the batch
                Files.Add(new BatchMessage(message, fileName, BatchOperationType.Submit, afterGetAction, afterGetFilename));

                // Greg Sharp: Let the caller set this as the file size may be stale
                // Add the size of the file to the stream
                //if (message.BodyPart.Data.CanWrite)
                //    message.BodyPart.Data.SetLength(size);

                return(message);
            }
            catch (Exception ex)
            {
                TraceMessage("[SftpReceiverEndpoint] Error Adding file [" + fileName + "]to batch. Error: " + ex.Message);

                if (_useLoadBalancing)
                {
                    DataBaseHelper.CheckInFile(uri, Path.GetFileName(fileName), _traceFlag);
                }

                return(null);
            }
        }
コード例 #25
0
 /// <summary>
 /// Helper method to consume the part stream
 /// </summary>
 /// <param name="part">Part to consume</param>
 public static void ConsumeStream(IBaseMessagePart part)
 {
     if (part == null)
     {
         throw new ArgumentNullException("part");
     }
     ConsumeStream(part.Data);
 }
コード例 #26
0
        /// <summary>
        /// called by the messaging engine when a new message arrives
        /// </summary>
        /// <param name="pc">the pipeline context</param>
        /// <param name="inmsg">the actual message</param>
        public void Disassemble(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
        {
            //
            // TODO: implement message retrieval logic
            IBaseMessagePart Body = inmsg.BodyPart;

            if (Body != null)
            {
                Stream originalStream = Body.GetOriginalDataStream();
                if (originalStream != null)
                {
                    var xml         = XElement.Load(originalStream);
                    var rootElement = xml.Name;
                    // Child elements from source file to split by.
                    var childNodes = xml.Descendants(this.DescendantElement);

                    // This is the total number of elements to be sliced up into
                    // separate files.
                    int cnt = childNodes.Count();

                    var skip   = 0;
                    var take   = this.BatchSize;
                    var fileno = 0;

                    // Split elements into chunks and save to disk.
                    while (skip < cnt)
                    {
                        // Extract portion of the xml elements.
                        var c1 = childNodes
                                 .Skip(skip)
                                 .Take(take);

                        // Setup number of elements to skip on next iteration.
                        skip += take;
                        // File sequence no for split file.
                        fileno += 1;
                        // Filename for split file.
                        // Create a partial xml document.
                        XElement frag = new XElement(rootElement, c1);
                        // Save to disk.
                        var newStream = new MemoryStream();
                        frag.Save(newStream);
                        newStream.Position = 0;
                        pc.ResourceTracker.AddResource(newStream);
                        IBaseMessage newmsg = pc.GetMessageFactory().CreateMessage();
                        newmsg.AddPart("Body", pc.GetMessageFactory().CreateMessagePart(), true);
                        newmsg.BodyPart.Data = newStream;
                        newmsg.Context       = PipelineUtil.CloneMessageContext(inmsg.Context);
                        //outMsg.Context.Promote("MessageType",  "http://schemas.microsoft.com/BizTalk/2003/system-properties",      "Namespace#Root");
                        var msgtype = (string.IsNullOrEmpty(rootElement.Namespace.NamespaceName)?"" : rootElement.Namespace.NamespaceName + "#") + rootElement.LocalName;
                        newmsg.Context.Write("MessageType", "http://schemas.microsoft.com/BizTalk/2003/system-properties", msgtype);
                        newmsg.Context.Promote("MessageType", "http://schemas.microsoft.com/BizTalk/2003/system-properties", msgtype);

                        _msgs.Enqueue(newmsg);
                    }
                }
            }
        }
コード例 #27
0
ファイル: UnzipComponent.cs プロジェクト: choonkeun/BizTalk
        public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            IBaseMessagePart bodyPart = pInMsg.BodyPart;

            if (bodyPart != null)
            {
                Stream originalStream = bodyPart.GetOriginalDataStream();

                if (originalStream != null)
                {
                    using (ZipInputStream zipInputStream = new ZipInputStream(originalStream))
                    {
                        if (_password != null && _password.Length > 0)
                        {
                            zipInputStream.Password = _password;
                        }

                        ZipEntry entry = zipInputStream.GetNextEntry();

                        while (entry != null)
                        {
                            MemoryStream memStream = new MemoryStream();
                            byte[]       buffer    = new Byte[1024];

                            int bytesRead = 1024;
                            while (bytesRead != 0)
                            {
                                bytesRead = zipInputStream.Read(buffer, 0, buffer.Length);
                                memStream.Write(buffer, 0, bytesRead);
                            }

                            string fileName  = entry.FileName.ToString();   //file name in zip file
                            string extension = Path.GetExtension(fileName);

                            IBaseMessage outMessage;
                            outMessage = pContext.GetMessageFactory().CreateMessage();
                            outMessage.AddPart("Body", pContext.GetMessageFactory().CreateMessagePart(), true);
                            memStream.Position       = 0;
                            outMessage.BodyPart.Data = memStream;


                            IBaseMessageContext context = pInMsg.Context;
                            string receivePortName      = context.Read("ReceivePortName", "http://schemas.microsoft.com/BizTalk/2003/system-properties").ToString();
                            string fullPath             = context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();
                            string filePath             = Path.GetDirectoryName(fullPath);

                            outMessage.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);
                            outMessage.Context.Promote("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", fileName);
                            outMessage.Context.Promote("ReceivePortName", "http://schemas.microsoft.com/BizTalk/2003/system-properties", receivePortName);

                            _qOutMessages.Enqueue(outMessage);

                            entry = zipInputStream.GetNextEntry();
                        }
                    }
                }
            }
        }
コード例 #28
0
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            String value   = null;
            bool   suspend = false;

            IBaseMessagePart bodyPart = pInMsg.BodyPart;



            Stream                 inboundStream          = bodyPart.GetOriginalDataStream();
            VirtualStream          virtualStream          = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk);
            ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream);

            XmlTextReader   xmlTextReader   = new XmlTextReader(readOnlySeekableStream);
            XPathCollection xPathCollection = new XPathCollection();
            XPathReader     xPathReader     = new XPathReader(xmlTextReader, xPathCollection);

            xPathCollection.Add(XPath);

            while (xPathReader.ReadUntilMatch())
            {
                if (xPathReader.Match(0))
                {
                    if (xPathReader.NodeType == XmlNodeType.Attribute)
                    {
                        value = xPathReader.GetAttribute(xPathReader.Name);
                    }
                    else
                    {
                        value = xPathReader.ReadString();
                    }

                    break;
                }
            }


            suspend = ScriptExpressionHelper.ValidateExpression(value, Expression);

            if (suspend)
            {
                readOnlySeekableStream.Position = 0;
                pContext.ResourceTracker.AddResource(readOnlySeekableStream);
                bodyPart.Data = readOnlySeekableStream;
                pInMsg.Context.Write("SuspendAsNonResumable", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);
                pInMsg.Context.Write("SuppressRoutingFailureDiagnosticInfo", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);

                throw new Exception(String.Format("Expression {0} {1} did not evaluate to true", value, Expression));
            }
            else
            {
                pInMsg = null;
            }


            return(pInMsg);
        }
コード例 #29
0
ファイル: MessageHelper.cs プロジェクト: ninocrudele/SnapGate
        /// <summary>
        ///     Creates a new message part
        /// </summary>
        /// <param name="body">Body of the part</param>
        /// <returns>The new part</returns>
        public static IBaseMessagePart CreatePartFromStream(Stream body)
        {
            if (body == null)
                throw new ArgumentNullException("body");

            IBaseMessagePart part = _factory.CreateMessagePart();
            part.Data = body;
            return part;
        }
コード例 #30
0
ファイル: MessageHelper.cs プロジェクト: ninocrudele/SnapGate
 /// <summary>
 ///     Helper method to read back a stream as a string
 /// </summary>
 /// <param name="part">Part to consume</param>
 public static String ReadString(IBaseMessagePart part)
 {
     if (part == null)
         throw new ArgumentNullException("part");
     Encoding enc = Encoding.UTF8;
     if (!String.IsNullOrEmpty(part.Charset))
         enc = Encoding.GetEncoding(part.Charset);
     return ReadString(part.Data, enc);
 }
コード例 #31
0
        public static object Read(this IBaseMessagePart part, ContextProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            return(part.PartProperties.Read(property.PropertyName, property.PropertyNamespace));
        }
コード例 #32
0
        public void AddPart(string partName, IBaseMessagePart part, bool bBody)
        {
            if (bBody)
            {
                this._bodyPartName = partName;
                this._bodyPart = part;
            }

            this._partDictionary[partName] = part;
        }
コード例 #33
0
ファイル: Utility.cs プロジェクト: HydAu/QLBizTalk2013
        private static void CloneParts(IPipelineContext pc, IBaseMessage inmsg, IBaseMessage outmsg, IBaseMessagePart bodyPart)
        {
            for (int i = 0; i < inmsg.PartCount; i++)
            {
                string partName = null;

                IBaseMessagePart currentPart = inmsg.GetPartByIndex(i, out partName);

                if (currentPart == null) continue;

                outmsg.AddPart(partName, partName == inmsg.BodyPartName ? bodyPart : currentPart, partName == inmsg.BodyPartName);
            }
        }
コード例 #34
0
 /// <summary>
 /// Helper method to consume the part stream
 /// </summary>
 /// <param name="part">Part to consume</param>
 public static void ConsumeStream(IBaseMessagePart part)
 {
    if ( part == null )
       throw new ArgumentNullException("part");
    ConsumeStream(part.Data);
 }
コード例 #35
0
 internal IBaseMessage WithPart(string partName, IBaseMessagePart part, bool bBody)
 {
     this.AddPart(partName, part, bBody);
     return this;
 }
コード例 #36
0
 /// <summary>
 /// Helper method to read back a stream as a string
 /// </summary>
 /// <param name="part">Part to consume</param>
 public static String ReadString(IBaseMessagePart part)
 {
    if ( part == null )
       throw new ArgumentNullException("part");
    Encoding enc = Encoding.UTF8;
    if ( !String.IsNullOrEmpty(part.Charset) )
       enc = Encoding.GetEncoding(part.Charset);
    return ReadString(part.Data, enc);
 }