示例#1
0
        public override async Task <Message> HandleMessage(Message msg)
        {
            XmlReader reader;

            if (msg is XMLMessage)
            {
                reader = ((XMLMessage)msg).GetReader();
            }
            else if (msg is IStreamMessage)
            {
                reader = XmlReader.Create(await((IStreamMessage)msg).GetStream());
            }
            else if (msg is IStringMessage)
            {
                reader = XmlReader.Create(new StringReader(((IStringMessage)msg).Value));
            }
            else
            {
                return(null);
            }

            return(await Task.Run <Message>(() =>
            {
                try
                {
                    // Chain XmlReaders together to handle XIncludes, plugins
                    // and macro expansion.
                    // A pipeline within a pipeline within a pipeline.

                    XIncludingReader includingReader = new XIncludingReader(reader);
                    XPluginReader pluginReader = new XPluginReader(includingReader);
                    XDownstreamReader downstreamReader = new XDownstreamReader(pluginReader);
                    XUpstreamReader upstreamReader = new XUpstreamReader(downstreamReader);

                    var deserialiser = new XMeeplangDeserialiser();
                    var tree = deserialiser.Deserialise(upstreamReader);

                    return new DeserialisedPipeline
                    {
                        DerivedFrom = msg,
                        Tree = tree
                    };
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "{0} thrown when deserialising pipeline definition: {1}", ex.GetType().Name, ex.Message);
                    return null;
                }
            }));
        }