예제 #1
0
        public async Task <Request> Read(Stream input, CancellationToken cancellationToken)
        {
            var document = await XmlDocumentParser.Instance.Load(input, cancellationToken);

            if (document.Root.Name == XName.Get("EPCISDocument", EpcisNamespaces.Capture))
            {
                return(new CaptureRequest
                {
                    Header = ParseHeader(document.Root),
                    EventList = XmlEventsParser.ParseEvents(document.Root.XPathSelectElement("EPCISBody/EventList").Elements().ToArray()),
                    MasterDataList = XmlMasterDataParser.ParseMasterDatas(document.Root.XPathSelectElement("EPCISHeader/extension/EPCISMasterData/VocabularyList")?.Elements()?.ToArray() ?? new XElement[0]),
                });
            }
            else if (document.Root.Name == XName.Get("EPCISQueryDocument", EpcisNamespaces.Query)) // Subscription result
            {
                return(ParseCallback(document));
            }
            else if (document.Root.Name == XName.Get("EPCISMasterDataDocument", EpcisNamespaces.MasterData))
            {
                return(new CaptureRequest
                {
                    Header = ParseHeader(document.Root),
                    MasterDataList = XmlMasterDataParser.ParseMasterDatas(document.Root.Element("EPCISBody").Element("VocabularyList").Elements("Vocabulary"))
                });
            }

            throw new Exception($"Document with root '{document.Root.Name.ToString()}' is not expected here.");
        }
예제 #2
0
        private Request ParseCallback(XDocument document)
        {
            switch (document.Root.Element("EPCISBody").Elements().First().Name.LocalName)
            {
            case "QueryTooLargeException":
                return(new EpcisQueryCallbackException
                {
                    Header = ParseHeader(document.Root),
                    SubscriptionName = document.Root.Element("EPCISBody").Element(XName.Get("QueryTooLargeException", EpcisNamespaces.Query)).Element("subscriptionID").Value,
                    Reason = document.Root.Element("EPCISBody").Element(XName.Get("QueryTooLargeException", EpcisNamespaces.Query)).Element("reason").Value,
                    CallbackType = QueryCallbackType.ImplementationException
                });

            case "ImplementationException":
                return(new EpcisQueryCallbackException
                {
                    Header = ParseHeader(document.Root),
                    SubscriptionName = document.Root.Element("EPCISBody").Element(XName.Get("ImplementationException", EpcisNamespaces.Query)).Element("subscriptionID").Value,
                    Reason = document.Root.Element("EPCISBody").Element(XName.Get("ImplementationException", EpcisNamespaces.Query)).Element("reason").Value,
                    CallbackType = QueryCallbackType.ImplementationException
                });

            case "QueryResults":
                return(new EpcisQueryCallbackDocument
                {
                    Header = ParseHeader(document.Root),
                    SubscriptionName = document.Root.Element("EPCISBody").Element(XName.Get("QueryResults", EpcisNamespaces.Query)).Element("subscriptionID").Value,
                    EventList = XmlEventsParser.ParseEvents(document.Root.Element("EPCISBody").Element(XName.Get("QueryResults", EpcisNamespaces.Query)).Element("resultsBody").Element("EventList").Elements().ToArray())
                });
            }

            throw new Exception($"Document with root '{document.Root.Name.ToString()}' is not expected here.");
        }
예제 #3
0
        public Request Read(Stream input)
        {
            var document = XDocument.Load(input);

            if (document.Root.Name == XName.Get("EPCISDocument", EpcisNamespaces.Capture))
            {
                return(new EpcisEventDocument
                {
                    CreationDate = DateTime.Parse(document.Root.Attribute("creationDate").Value, CultureInfo.InvariantCulture),
                    SchemaVersion = document.Root.Attribute("schemaVersion").Value,
                    EventList = XmlEventsParser.ParseEvents(document.Root.XPathSelectElement("EPCISBody/EventList").Elements().ToArray())
                });
            }
            // TODO: handle masterdata document.
            //else if (document.Root.Name == XName.Get("EPCISMasterDataDocument", EpcisNamespaces.Capture))
            //{
            //    return new EpcisMasterdataDocument();
            //}

            throw new Exception($"Document with root '{document.Root.Name.ToString()}' is not expected here.");
        }