public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            if (!Enabled)
            {
                return(pInMsg);
            }
            string errorMessage;

            if (!Validate(out errorMessage))
            {
                throw new ArgumentException(errorMessage);
            }
            var contentReader = new ContentReader();

            var       data          = pInMsg.BodyPart.GetOriginalDataStream();
            const int bufferSize    = 0x280;
            const int thresholdSize = 0x100000;

            if (!data.CanSeek || !data.CanRead)
            {
                data = new ReadOnlySeekableStream(data, new VirtualStream(bufferSize, thresholdSize), bufferSize);
                pContext.ResourceTracker.AddResource(data);
            }
            if (contentReader.IsXmlContent(data))
            {
                var    encoding   = contentReader.Encoding(data);
                string nodeFormat = ShowPropertyInfoAsNodes ?
                                    "<property><name>{0}</name><namespace>{1}</namespace><promoted>{2}</promoted><value>{3}</value></property>"
                    : "<property name=\"{0}\" namespace=\"{1}\" promoted=\"{2}\">{3}</property>";
                string msgctx = "", propName, propNS;
                object retval;
                if (string.IsNullOrEmpty(SelectedProperties))
                {
                    for (int i = 0; i < pInMsg.Context.CountProperties; i++)
                    {
                        retval  = pInMsg.Context.ReadAt(i, out propName, out propNS);
                        msgctx += string.Format(nodeFormat, propName, propNS, pInMsg.Context.IsPromoted(propName, propNS), retval);
                    }
                }
                else
                {
                    var selectedProps = SelectedProperties.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < selectedProps.Length; i++)
                    {
                        var property = new ContextProperty(selectedProps[i]);
                        retval = pInMsg.Context.Read(property);
                        if (retval != null)
                        {
                            msgctx += string.Format(nodeFormat, property.PropertyName, property.PropertyNamespace, pInMsg.Context.IsPromoted(property), retval);
                        }
                    }
                }
                msgctx = "<messagecontext>" + msgctx + "</messagecontext>";

                data = new CommentInjector(data, msgctx, encoding);
                data = new ReadOnlySeekableStream(data, new VirtualStream(bufferSize, thresholdSize), bufferSize);
                pContext.ResourceTracker.AddResource(data);
                pInMsg.BodyPart.Data = data;
            }
            else
            {
                data.Seek(0, SeekOrigin.Begin);
                pInMsg.BodyPart.Data = data;
            }
            return(pInMsg);
        }
Пример #2
0
 private void When_CreateInjector()
 {
     this.cinj = new CommentInjector(program.User.Annotations);
 }