Exemplo n.º 1
0
        public async Task <EpcisQuery> Read(Stream input, CancellationToken cancellationToken)
        {
            var document = await XmlDocumentParser.Instance.Load(input, cancellationToken);

            if (document.Root.Name.LocalName == "EPCISQueryDocument")
            {
                var element = document.Root.Element("EPCISBody").Elements().FirstOrDefault();

                if (element != null)
                {
                    if (element.Name == XName.Get("GetQueryNames", EpcisNamespaces.Query))
                    {
                        return(new GetQueryNames());
                    }
                    if (element.Name == XName.Get("GetSubscriptionIDs", EpcisNamespaces.Query))
                    {
                        return new GetSubscriptionIds {
                                   QueryName = element.Element("queryName").Value
                        }
                    }
                    ;
                    if (element.Name == XName.Get("GetStandardVersion", EpcisNamespaces.Query))
                    {
                        return(new GetStandardVersion());
                    }
                    if (element.Name == XName.Get("GetVendorVersion", EpcisNamespaces.Query))
                    {
                        return(new GetVendorVersion());
                    }
                    if (element.Name == XName.Get("Poll", EpcisNamespaces.Query))
                    {
                        return(XmlQueryParser.Parse(element));
                    }
                    if (element.Name == XName.Get("Subscribe", EpcisNamespaces.Query))
                    {
                        return(XmlSubscriptionParser.ParseSubscription(element));
                    }
                    if (element.Name == XName.Get("Unsubscribe", EpcisNamespaces.Query))
                    {
                        return(XmlSubscriptionParser.ParseUnsubscription(element));
                    }
                    throw new Exception($"Element not expected: '{element?.Name?.LocalName ?? null}'");
                }

                throw new Exception($"EPCISBody element must contain the query type.");
            }

            throw new Exception($"Element not expected: '{document.Root.Name.LocalName}'");
        }
Exemplo n.º 2
0
        private EpcisQuery ReadRequest(XElement body)
        {
            var element = body.Elements().SingleOrDefault(x => x.Name.NamespaceName == EpcisNamespaces.Query);

            if (element != null)
            {
                if (element.Name == XName.Get("GetQueryNames", EpcisNamespaces.Query))
                {
                    return(new GetQueryNames());
                }
                if (element.Name == XName.Get("GetSubscriptionIDs", EpcisNamespaces.Query))
                {
                    return(new GetSubscriptionIds {
                        QueryName = element.Element("queryName").Value
                    });
                }
                if (element.Name == XName.Get("GetStandardVersion", EpcisNamespaces.Query))
                {
                    return(new GetStandardVersion());
                }
                if (element.Name == XName.Get("GetVendorVersion", EpcisNamespaces.Query))
                {
                    return(new GetVendorVersion());
                }
                if (element.Name == XName.Get("Poll", EpcisNamespaces.Query))
                {
                    return(XmlQueryParser.Parse(element));
                }
                if (element.Name == XName.Get("Subscribe", EpcisNamespaces.Query))
                {
                    return(XmlSubscriptionParser.ParseSubscription(element));
                }
                if (element.Name == XName.Get("Unsubscribe", EpcisNamespaces.Query))
                {
                    return(XmlSubscriptionParser.ParseUnsubscription(element));
                }
                throw new Exception($"Element not expected: '{element?.Name?.LocalName ?? null}'");
            }

            throw new Exception($"Invalid SOAP request: empty Body.");
        }