예제 #1
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);
                }
            }
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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;
     }
 }
        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);
        }
예제 #6
0
        /// <summary>
        /// Populates a body part with content from an XML document.  If no body part exists, a new one
        /// is created.
        /// </summary>
        /// <param name="message">The massage to which the body part will be added.</param>
        /// <param name="part">The existing part</param>
        /// <param name="pc">The pipeline context.</param>
        /// <returns>A message with a body part populated by the XML document content.</returns>
        public static bool PopulateBodyPartFromExistingPart(this IBaseMessage message, IBaseMessagePart part, IPipelineContext pc)
        {
            if (message == null || part == null)
            {
                return(false);
            }

            Func <IBaseMessagePart> clonedPart = () =>
            {
                var newPart = pc.GetMessageFactory().CreateMessagePart();
                newPart.Data = part.GetOriginalDataStream().Clone();
                return(newPart);
            };

            var outPart = part.IsMutable
                ? clonedPart()
                : part.WithStreamAtStart();

            // Add a body part if none exists.
            if (message.BodyPart == null)
            {
                message.AddPart("Body", outPart, true);
            }

            return(true);
        }
예제 #7
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);
            }
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
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);
        }
        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);
        }
예제 #13
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>
        /// <returns></returns>
        internal IBaseMessage CreateMessage(string fileName, string uri, long size,
                                            SftpReceiveProperties.AfterGetActions afterGetAction, string afterGetFilename)
        {
            Stream       stream;
            IBaseMessage message = null;

            try
            {
                TraceMessage("[SftpReceiverEndpoint] Reading file to stream " + fileName);

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


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

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

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

                SetReceivedFileName(message, fileName);

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

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

                // Add the file to the batch
                this.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 (this._useLoadBalancing)
                {
                    DataBaseHelper.CheckInFile(uri, Path.GetFileName(fileName), this._traceFlag);
                }

                return(null);
            }
        }
        /// <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);
                    }
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Copy message parts from source to destination message.
        /// </summary>
        /// <param name="sourceMessage">Source message</param>
        /// <param name="destinationMessage">Destination message</param>
        /// <param name="newBodyPart">New message body part</param>
        private void CopyMessageParts(IBaseMessage sourceMessage, IBaseMessage destinationMessage, IBaseMessagePart newBodyPart)
        {
            string bodyPartName = sourceMessage.BodyPartName;

            for (int c = 0; c < sourceMessage.PartCount; ++c)
            {
                string           partName    = null;
                IBaseMessagePart messagePart = sourceMessage.GetPartByIndex(c, out partName);
                if (partName != bodyPartName)
                {
                    destinationMessage.AddPart(partName, messagePart, false);
                }
                else
                {
                    destinationMessage.AddPart(bodyPartName, newBodyPart, true);
                }
            }
        }
예제 #16
0
        /// <summary>
        ///     Creates a multi-part message from an array
        ///     of streams. The first stream in the array will be marked
        ///     as the message body part
        /// </summary>
        /// <param name="parts">One stream for each part</param>
        /// <returns>The new message</returns>
        public static IBaseMessage Create(params Stream[] parts)
        {
            if (parts == null || parts.Length < 1)
                throw new ArgumentException("Need to specify at least one part", "parts");

            IBaseMessage message = CreateFromStream(parts[0]);
            for (int i = 1; i < parts.Length; i++)
                message.AddPart("part" + i, CreatePartFromStream(parts[i]), false);
            return message;
        }
예제 #17
0
        public static IBaseMessage CreateMessage(IBaseMessageFactory factory, string fileName)
        {
            IBaseMessage message = factory.CreateMessage();

            message.Context = factory.CreateMessageContext();
            IBaseMessagePart part = factory.CreateMessagePart();

            part.Data = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            message.AddPart("body", part, true);
            return(message);
        }
예제 #18
0
        /// <summary>
        /// Adds a new message part to the specified request message which is intended to be used as a response part.
        /// </summary>
        /// <param name="msgFactory">The <see cref="Microsoft.BizTalk.Message.Interop.IBaseMessageFactory"/> factory object providing message part creation capabilities.</param>
        /// <param name="requestMsg">The request message represented by the <see cref="Microsoft.BizTalk.Message.Interop.IBaseMessage"/> object.</param>
        /// <returns>A new message part represented by the <see cref="Microsoft.BizTalk.Message.Interop.IBaseMessagePart"/> object.</returns>
        public static IBaseMessagePart CreateResponsePart(IBaseMessageFactory msgFactory, IBaseMessage requestMsg)
        {
            Guard.ArgumentNotNull(msgFactory, "msgFactory");
            Guard.ArgumentNotNull(requestMsg, "requestMsg");

            IBaseMessagePart responsePart = msgFactory.CreateMessagePart();

            requestMsg.AddPart(Resources.ResponseBodyPartName, responsePart, false);

            return(responsePart);
        }
예제 #19
0
        public static IBaseMessage CreateMessage(IBaseMessageFactory factory, string fileName, StringCollection parts)
        {
            IBaseMessage message = CreateMessage(factory, fileName);

            for (int i = 0; i < parts.Count; i++)
            {
                IBaseMessagePart part = factory.CreateMessagePart();
                part.Data = new FileStream(parts[i], FileMode.Open, FileAccess.Read);
                message.AddPart(string.Format(CultureInfo.CurrentCulture, "part{0}", new object[] { i }), part, false);
            }
            return(message);
        }
예제 #20
0
        /// <summary>
        /// Reads the response message from the server
        /// </summary>
        /// <param name="msg">Response message from the server</param>
        /// <returns>Flag to delete message from the server or not</returns>
        public bool TransmitMessage(IBaseMessage msg)
        {
            // Note: We need to read the stream which will execute the
            // pipeline, we then replace the stream with the one we
            // have created
            IBaseMessagePart bodyPart = msg.BodyPart;
            Stream           s        = null;

            if (bodyPart != null)
            {
                s = bodyPart.GetOriginalDataStream();
            }

            // Create a memory stream to copy the data into
            Stream memStrm = new MemoryStream();

            byte[] buff = new byte[4096];
            int    dataRead = 0, readOffSet = 0, writeOffSet = 0;

            if (s != null)
            {
                s.Seek(0, SeekOrigin.Begin);

                // Copy the data from the src stream
                do
                {
                    dataRead = s.Read(buff, readOffSet, 4096);
                    memStrm.Write(buff, writeOffSet, dataRead);
                } while (dataRead > 0);
            }

            // Create a new message
            IBaseMessage response = BizTalkMessaging._mf.CreateMessage();

            // Copy over the context
            response.Context = msg.Context;

            // Copy over the body part, note, only support single part messages
            IBaseMessagePart messageBodyPart = BizTalkMessaging._mf.CreateMessagePart();

            messageBodyPart.Data = memStrm;

            memStrm.Seek(0, SeekOrigin.Begin);
            response.AddPart(msg.BodyPartName, messageBodyPart, true);

            _msg = response;

            ThreadPool.QueueUserWorkItem(DeleteTransmitMessage, msg);

            // Return false.
            // We'll issue a Batch.DeleteMessage() later.
            return(false);
        }
예제 #21
0
        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);
            }
        }
예제 #22
0
        public static void CopyMessageParts(IPipelineContext pc, IBaseMessage inmsg, IBaseMessage outmsg, IBaseMessagePart bodyPart, bool allowUnrecognizeMessage)
        {
            string bodyPartName = inmsg.BodyPartName;

            for (int i = 0; i < inmsg.PartCount; i++)
            {
                string           partName    = null;
                IBaseMessagePart partByIndex = inmsg.GetPartByIndex(i, out partName);
                if ((partByIndex == null) && !allowUnrecognizeMessage)
                {
                    throw new ArgumentNullException("otherOutPart[" + i + "]");
                }
                if (bodyPartName != partName)
                {
                    outmsg.AddPart(partName, partByIndex, false);
                }
                else
                {
                    outmsg.AddPart(bodyPartName, bodyPart, true);
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Copy over all parts of the message from a source message to a destination message, choosing which part should be the body part
        /// </summary>
        private void CopyMessageParts(IBaseMessage sourceMessage, IBaseMessage destinationMessage, IBaseMessagePart newBodyPart)
        {
            //Explicitly clear the collection in case this has gone through a disassembler with multiple messages and there are leftovers from the last time
            partNames.Clear();
            
            string bodyPartName = sourceMessage.BodyPartName;
            for (int partCounter = 0; partCounter < sourceMessage.PartCount; ++partCounter)
            {
                string partName = null;
                IBaseMessagePart messagePart = sourceMessage.GetPartByIndex(partCounter, out partName);
                partNames.Add(partCounter, partName);

                if (partName != bodyPartName)
                {
                    destinationMessage.AddPart(partName, messagePart, false);
                }
                else
                {
                    destinationMessage.AddPart(bodyPartName, newBodyPart, true);
                }
            }
        }
예제 #24
0
        /// <summary>
        ///     Create a new message with the specified stream as
        ///     the body part.
        /// </summary>
        /// <param name="body">Body of the message</param>
        /// <returns>A new message object</returns>
        public static IBaseMessage CreateFromStream(Stream body)
        {
            if (body == null)
                throw new ArgumentNullException("body");

            IBaseMessage message = _factory.CreateMessage();
            message.Context = _factory.CreateMessageContext();

            IBaseMessagePart bodyPart = CreatePartFromStream(body);

            message.AddPart("body", bodyPart, true);

            return message;
        }
예제 #25
0
        public static IBaseMessage createMsg(params Stream[] parts)
        {
            if (parts == null || parts.Length < 1)
            {
                throw new ArgumentException("Need to specify at least one part", "parts");
            }

            IBaseMessage message = createMessageFromStream(parts[0]);

            for (int i = 1; i < parts.Length; i++)
            {
                message.AddPart("part" + i, getMsgFromStream(parts[i]), false);
            }
            return(message);
        }
        /// <summary>
        /// Create a BizTalk message given the name of a file on disk optionally renaming
        /// the file while the message is being submitted into BizTalk.
        /// </summary>
        /// <param name="srcFilePath">The File to create the message from</param>
        /// <param name="renamedFileName">Optional, if specified the file will be renamed to this value.</param>
        /// <returns>The message to be submitted to BizTalk.</returns>
        private IBaseMessage CreateMessage(string srcFilePath, string renamedFileName)
        {
            Stream fs;
            bool   renamed = false;

            // Open the file
            try
            {
                if (!String.IsNullOrEmpty(renamedFileName))
                {
                    Trace.WriteLine("[DotNetFileReceiverEndpoint] Renaming file " + srcFilePath);
                    File.Move(srcFilePath, renamedFileName);
                    renamed = true;
                    fs      = File.Open(renamedFileName, FileMode.Open, FileAccess.Read, FileShare.None);
                }
                else
                {
                    fs = File.Open(srcFilePath, FileMode.Open, FileAccess.Read, FileShare.None);
                }
            }
            catch (Exception)
            {
                // If we renamed the file, rename it back
                if (renamed)
                {
                    File.Move(renamedFileName, srcFilePath);
                }

                return(null);
            }

            IBaseMessagePart part = this.messageFactory.CreateMessagePart();

            part.Data = fs;
            IBaseMessage message = this.messageFactory.CreateMessage();

            message.AddPart(MESSAGE_BODY, part, true);

            SystemMessageContext context = new SystemMessageContext(message.Context);

            context.InboundTransportLocation = this.properties.Uri;
            context.InboundTransportType     = this.transportType;

            //Write/Promote any adapter specific properties on the message context
            message.Context.Write(DOT_NET_FILE_PROP_REMOTEFILENAME, this.propertyNamespace, (object)srcFilePath);

            return(message);
        }
예제 #27
0
        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);
            }
        }
예제 #28
0
        private static void LoadPart(IBaseMessage msg, XPathNavigator node, string contextFile)
        {
            // don't care about the id because we can't set it anyway
            string name = node.GetAttribute("Name", "");
            string filename = node.GetAttribute("FileName", "");
            string charset = node.GetAttribute("Charset", "");
            string contentType = node.GetAttribute("ContentType", "");
            bool isBody = XmlConvert.ToBoolean(node.GetAttribute("IsBodyPart", ""));

            XmlResolver resolver = new XmlUrlResolver();
            Uri realfile = resolver.ResolveUri(new Uri(contextFile), filename);
            IBaseMessagePart part = CreatePartFromStream(File.OpenRead(realfile.LocalPath));
            part.Charset = charset;
            part.ContentType = contentType;
            msg.AddPart(name, part, isBody);
        }
        private IBaseMessage CreateMessage(IBaseMessageFactory messageFactory, Stream stream, string taskName)
        {
            IBaseMessagePart messagePart = messageFactory.CreateMessagePart();

            messagePart.Data = stream;
            IBaseMessage message = messageFactory.CreateMessage();

            message.AddPart("body", messagePart, true);
            SystemMessageContext context = new SystemMessageContext(message.Context);

            context.InboundTransportLocation = this.uri;
            context.InboundTransportType     = this.transportType;
            message.Context.Write(TaskNameProperty.Name.Name, TaskNameProperty.Name.Namespace, this.properties.Name);
            message.Context.Write(NextScheduleTimeProperty.Name.Name, NextScheduleTimeProperty.Name.Namespace, this.properties.Schedule.GetNextActivationTime());
            return(message);
        }
예제 #30
0
        public void CanCreateMultipartMessage()
        {
            string body = "<body>Some message content</body>";

            IBaseMessage message = MessageHelper.CreateFromString(body);

            Assert.IsNotNull(message);
            Assert.IsNotNull(message.BodyPart);
            Assert.IsNotNull(message.BodyPart.Data);
            Assert.IsTrue(message.BodyPart.Data.Length > 0);

            IBaseMessagePart part1 = MessageHelper.CreatePartFromString(body);

            message.AddPart("part1", part1, false);
            Assert.AreEqual(2, message.PartCount);
            Assert.IsNotNull(message.GetPart("part1"));
        }
예제 #31
0
        //Return message from stream
        public static IBaseMessage createMessageFromStream(Stream body)
        {
            if (body == null)
            {
                throw new ArgumentNullException("body");
            }

            IBaseMessage message = msgfactory.CreateMessage();

            message.Context = msgfactory.CreateMessageContext();

            IBaseMessagePart bodyPart = getMsgFromStream(body);

            message.AddPart("body", bodyPart, true);

            return(message);
        }
예제 #32
0
      private static void LoadPart(IBaseMessage msg, XPathNavigator node, string contextFile)
      {
         // don't care about the id because we can't set it anyway
         string name = node.GetAttribute("Name", "");
         string filename = node.GetAttribute("FileName", "");
         string charset = node.GetAttribute("Charset", "");
         string contentType = node.GetAttribute("ContentType", "");
         bool isBody = XmlConvert.ToBoolean(node.GetAttribute("IsBodyPart", ""));

         XmlResolver resolver = new XmlUrlResolver();
         Uri realfile = resolver.ResolveUri(new Uri(contextFile), filename);
         IBaseMessagePart part = CreatePartFromStream(File.OpenRead(realfile.LocalPath));
         part.Charset = charset;
         part.ContentType = contentType;
         msg.AddPart(name, part, isBody);
      }