Пример #1
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.");
        }
Пример #2
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.");
        }
Пример #3
0
        public static void ParseReadPoint(this XElement element, EpcisEvent Event)
        {
            Event.ReadPoint = element.Element("id").Value;

            foreach (var innerElement in element.Elements().Where(x => x.Name.Namespace != XNamespace.None))
            {
                Event.CustomFields.Add(XmlEventsParser.ParseCustomField(innerElement, Event, FieldType.ReadPointExtension));
            }
        }
Пример #4
0
        public static void ParseBusinessLocation(this XElement element, EpcisEvent Event)
        {
            foreach (var innerElement in element.Elements().Where(x => !new[] { "id", "corrective" }.Contains(x.Name.LocalName)))
            {
                Event.CustomFields.Add(XmlEventsParser.ParseCustomField(innerElement, Event, FieldType.BusinessLocationExtension));
            }

            Event.BusinessLocation = element.Element("id").Value;
        }
Пример #5
0
        public static ErrorDeclaration ToErrorDeclaration(this XElement element, EpcisEvent Event)
        {
            foreach (var innerElement in element.Elements().Where(x => !new[] { "id", "corrective" }.Contains(x.Name.LocalName)))
            {
                Event.CustomFields.Add(XmlEventsParser.ParseCustomField(innerElement, Event, FieldType.ErrorDeclarationExtension));
            }

            var declarationTime = DateTime.Parse(element.Element("declarationTime").Value, CultureInfo.InvariantCulture);

            return(new ErrorDeclaration {
                DeclarationTime = declarationTime, Reason = element.Element("reason").Value
            });
        }
Пример #6
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.");
        }