Sage.Integration.Northwind.Feeds.SyncFeedEntry.ReadXml C# (CSharp) Method

ReadXml() public method

public ReadXml ( System reader, Type payloadType ) : void
reader System
payloadType System.Type
return void
        public void ReadXml(System.Xml.XmlReader reader, Type payloadType)
        {
            GuidConverter guidConverter = new GuidConverter();
            if ((reader.NodeType == System.Xml.XmlNodeType.Element)
                && (reader.LocalName == "entry")
                && (reader.NamespaceURI == Namespaces.atomNamespace))
            {
                bool reading = true;
                while (reading)
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        switch (reader.LocalName)
                        {
                            case "title":
                                reading = reader.Read();
                                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                                    this.Title = reader.Value;
                                break;
                            case "id":
                                reading = reader.Read();
                                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                                    this.Id = reader.Value;
                                break;

                            case "uuid":
                                reading = reader.Read();
                                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                                {
                                    string uuidString = reader.Value;

                                    this.Uuid = (Guid)guidConverter.ConvertFromString(uuidString);
                                }
                                break;

                            case "httpStatus":
                                reading = reader.Read();
                                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                                    this.HttpStatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), reader.Value);
                                break;

                            case "httpMessage":
                                reading = reader.Read();
                                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                                    this.HttpMessage = reader.Value;
                                break;

                            case "location":
                                reading = reader.Read();
                                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                                    this.HttpLocation = reader.Value;
                                break;

                            case "httpMethod":
                                reading = reader.Read();
                                if (reader.NodeType == System.Xml.XmlNodeType.Text)
                                    this.HttpMethod = reader.Value;
                                break;

                            case "payload":
                                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(payloadType);
                                object obj = serializer.Deserialize(reader);
                                if (obj is PayloadBase)
                                    this.Payload = obj as PayloadBase;
                                break;

                            case "syncState":
                                System.Xml.Serialization.XmlSerializer syncStateSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SyncState));
                                object obj1 = syncStateSerializer.Deserialize(reader);
                                if (obj1 is SyncState)
                                    this.SyncState = obj1 as SyncState;
                                break;
                            case "link":

                                if (reader.HasAttributes)
                                {
                                    SyncFeedEntryLink link = new SyncFeedEntryLink();
                                    while (reader.MoveToNextAttribute())
                                    {
                                        if (reader.LocalName.Equals("payloadpath", StringComparison.InvariantCultureIgnoreCase))
                                            link.PayloadPath = reader.Value;
                                        if (reader.LocalName.Equals("rel", StringComparison.InvariantCultureIgnoreCase))
                                            link.LinkRel = reader.Value;
                                        if (reader.LocalName.Equals("type", StringComparison.InvariantCultureIgnoreCase))
                                            link.LinkType = reader.Value;
                                        if (reader.LocalName.Equals("title", StringComparison.InvariantCultureIgnoreCase))
                                            link.Title = reader.Value;
                                        if (reader.LocalName.Equals("uuid", StringComparison.InvariantCultureIgnoreCase))
                                            link.Uuid = reader.Value;
                                        if (reader.LocalName.Equals("href", StringComparison.InvariantCultureIgnoreCase))
                                            link.Href = reader.Value;
                                    }

                                    this.SyncLinks.Add(link);

                                }
                                break;
                            case "linked":
                                System.Xml.Serialization.XmlSerializer linkedSerializer = new System.Xml.Serialization.XmlSerializer(typeof(LinkedElement));
                                object linkedObj = linkedSerializer.Deserialize(reader);
                                if (linkedObj is LinkedElement)
                                    this.Linked = linkedObj as LinkedElement;
                                break;

                            default:
                                reading = reader.Read();
                                break;
                        }

                    }
                    else
                    {
                        if ((reader.NodeType == System.Xml.XmlNodeType.EndElement)
                            && (reader.LocalName == "entry"))
                            reading = false;
                        else
                            reading = reader.Read();
                    }
                }
            }
        }

Usage Example

コード例 #1
0
        public void DoWork(IRequest request)
        {
            // only atom entry supported!!!
            if (request.ContentType != Sage.Common.Syndication.MediaType.AtomEntry)
                throw new RequestException("Atom entry content type expected");

            // deserialize the request stream to a SyncFeedEntry
            SyncFeedEntry entry = new SyncFeedEntry();
            XmlReader reader = XmlReader.Create(request.Stream);
            reader.MoveToContent();
            entry.ReadXml(reader, typeof(SyncDigestPayload));

            if (null == entry.Linked)
                throw new RequestException("Invalid content: element 'linked' missing");

            // Parse the resource url to get the local id.
            // Additionally we check for equality of the urls of the request url and
            // in the linked element up to the resourceKind.

            string requestEndpointUrl = _requestContext.OriginEndPoint;
            RequestContext entryResourceAsRequestContext = new RequestContext(new Sage.Common.Syndication.SDataUri(entry.Linked.Resource));    // TODO: not really nice here.
            string linkedResourceUrl = entryResourceAsRequestContext.OriginEndPoint;

            if (!string.Equals(requestEndpointUrl, linkedResourceUrl, StringComparison.InvariantCultureIgnoreCase))
                throw new RequestException("Request url and linked entry resource not matching.");

            string resourceKindName = _requestContext.ResourceKind.ToString();
            string localId = entryResourceAsRequestContext.SdataUri.CollectionPredicate;
            Guid uuid = entry.Linked.Uuid;

            // store a new correlation entry to the sync store
            ICorrelatedResSyncInfoStore correlatedResSyncInfoStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(_requestContext.SdataContext);

            ResSyncInfo newResSyncInfo = new ResSyncInfo(uuid, requestEndpointUrl, 0, string.Empty, DateTime.Now);
            CorrelatedResSyncInfo newInfo = new CorrelatedResSyncInfo(localId, newResSyncInfo);
            correlatedResSyncInfoStore.Add(resourceKindName, newInfo);

            // Set the response values
            SyncFeed feed = new SyncFeed();
            feed.FeedType = FeedType.LinkedSingle;

            SyncFeedEntry feedEntry = new SyncFeedEntry();
            feedEntry.Title = FeedMetadataHelpers.BuildLinkedEntryTitle(_requestContext, uuid);
            feedEntry.Id = FeedMetadataHelpers.BuildLinkedEntryUrl(_requestContext, uuid);
            feedEntry.Updated = newInfo.ResSyncInfo.ModifiedStamp;
            feedEntry.Published = newInfo.ResSyncInfo.ModifiedStamp;
            feedEntry.Linked = entry.Linked;

            feed.Entries.Add(feedEntry);

            request.Response.Serializer = new SyncFeedSerializer();
            request.Response.Feed = (IFeed)feed;
            request.Response.ContentType = MediaType.AtomEntry;

            request.Response.StatusCode = System.Net.HttpStatusCode.Created;
            request.Response.Protocol.SendUnknownResponseHeader("location", FeedMetadataHelpers.BuildLinkedEntryUrl(_requestContext, uuid));
        }
All Usage Examples Of Sage.Integration.Northwind.Feeds.SyncFeedEntry::ReadXml