/// <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;
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
        private IBaseMessage BuildResponseMessage(IBaseMessage message, IBaseMessageContext context, LoopBackTransmitProperties props)
        {
            Guid callToken  = TraceManager.CustomComponent.TraceIn();
            long startScope = TraceManager.CustomComponent.TraceStartScope("BuildResponseMessage", callToken);

            IBaseMessageFactory messageFactory = _transportProxy.GetMessageFactory();
            IBaseMessage        btsResponse    = messageFactory.CreateMessage();

            TraceManager.CustomComponent.TraceInfo("PropertyCopy: {0}", props.PropertyCopy);
            if (props.PropertyCopy)
            {
                btsResponse.Context = PipelineUtil.CloneMessageContext(context);
            }
            TraceManager.CustomComponent.TraceInfo("CustomPropertyCopy: {0}", props.CustomPropertyCopy);
            if (props.CustomPropertyCopy)
            {
                btsResponse.Context = messageFactory.CreateMessageContext();
                for (int i = 0; i < context.CountProperties; i++)
                {
                    string strName;
                    string strNamespace;
                    object oValue = context.ReadAt(i, out strName, out strNamespace);
                    if (!strNamespace.StartsWith("http://schemas.microsoft.com/BizTalk"))
                    {
                        if (context.IsPromoted(strName, strNamespace))
                        {
                            TraceManager.CustomComponent.TraceInfo("Promoted into context: {1}#{0}={2}", strName, strNamespace, oValue);
                            btsResponse.Context.Promote(strName, strNamespace, oValue);
                        }
                        else
                        {
                            TraceManager.CustomComponent.TraceInfo("Copied into context: {1}#{0}={2}", strName, strNamespace, oValue);
                            btsResponse.Context.Write(strName, strNamespace, oValue);
                        }
                    }
                }
            }
            TraceManager.CustomComponent.TraceInfo("PartCount: {0}", message.PartCount);
            for (int i = 0; i < message.PartCount; i++)
            {
                string        str;
                VirtualStream stream = new VirtualStream();
                StreamReader  rdr    = new StreamReader(message.GetPartByIndex(i, out str).GetOriginalDataStream(), true);
                StreamWriter  wrtr   = new StreamWriter(stream, rdr.CurrentEncoding);
                wrtr.Write(rdr.ReadToEnd());
                rdr.Close();
                wrtr.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                IBaseMessagePart part = messageFactory.CreateMessagePart();
                if (props.PropertyCopy)
                {
                    part.Charset        = message.GetPart(str).Charset;
                    part.ContentType    = message.GetPart(str).ContentType;
                    part.PartProperties = PipelineUtil.CopyPropertyBag(message.GetPart(str).PartProperties, messageFactory);
                }
                btsResponse.AddPart(str, part, message.GetPart(str).PartID.Equals(message.BodyPart.PartID));
                btsResponse.GetPart(str).Data = stream;
            }

            TraceManager.CustomComponent.TraceEndScope("BuildResponseMessage", startScope, callToken);
            TraceManager.CustomComponent.TraceOut(callToken);

            return(btsResponse);
        }