public void DoWork(IRequest request) { if (request.ContentType != Sage.Common.Syndication.MediaType.Atom) { throw new RequestException("Atom content type expected"); } //read feed string resourceKindName = _requestContext.ResourceKind.ToString(); SyncFeed feed = new SyncFeed(); XmlReader reader = XmlReader.Create(request.Stream); feed.ReadXml(reader, ResourceKindHelpers.GetPayloadType(_requestContext.ResourceKind)); /* iterate through all entries and store result information */ ISyncResultInfoStore syncResultInfoStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetSyncResultStore(_requestContext.SdataContext); int noOfEntries = feed.Entries.Count; string endpoint = string.Empty; try { endpoint = new RequestContext(new Sage.Common.Syndication.SDataUri(feed.Id)).OriginEndPoint; } catch { } SyncResultEntryInfo[] syncResultEntries = new SyncResultEntryInfo[noOfEntries]; for (int i = 0; i < noOfEntries; i++) { SyncFeedEntry entry = (SyncFeedEntry)feed.Entries[i]; string httpMethod = entry.HttpMethod; int httpStatus = -1; if (Enum.IsDefined(typeof(HttpStatusCode), entry.HttpStatusCode.ToString())) { httpStatus = (int)Enum.Parse(typeof(HttpStatusCode), entry.HttpStatusCode.ToString(), true); } string httpLocation = entry.HttpLocation; string httpMessage = entry.HttpMessage; string diagnosisXml = XmlSerializationHelpers.SerializeObjectToXml(entry.Diagnoses); string payloadXml = XmlSerializationHelpers.SerializeObjectToXml(entry.Payload); syncResultEntries[i] = new SyncResultEntryInfo(httpMethod, httpStatus, httpLocation, httpMessage, diagnosisXml, payloadXml, DateTime.Now, endpoint); } syncResultInfoStore.Add(resourceKindName, syncResultEntries); }
public void LogResults(Feed <FeedEntry> targetFeed) { // input stream MUST be of type ATOM if (_request.ContentType != Sage.Common.Syndication.MediaType.Atom) { throw new RequestException("Atom content type expected"); } string resourceKindName; ISyncResultInfoStore syncResultInfoStore; string EndPoint; int noOfEntries; // the number of entries retrived ffrom input feed and that will be stored string runName; string runStamp; // Retrieve the resourceKindName resourceKindName = _requestContext.ResourceKind.ToString(); // Retrieve a reference to the synchronisation result store syncResultInfoStore = NorthwindAdapter.StoreLocator.GetSyncResultStore(_requestContext.SdataContext); // Read query parameters if (!_requestContext.SdataUri.QueryArgs.TryGetValue("runName", out runName)) { runName = null; } if (!_requestContext.SdataUri.QueryArgs.TryGetValue("runStamp", out runStamp)) { runName = null; } syncResultInfoStore.SetRunName(runName); syncResultInfoStore.SetRunStamp(runStamp); // Retrieve the EndPoint that will be stored into the result store // The EndPoint is the base url of the requst that returned the sync target feed. // Here: the EndPoint is parsed from ID tag of the feed EndPoint = string.Empty; try { EndPoint = new RequestContext(new Sage.Common.Syndication.SDataUri(targetFeed.Id)).OriginEndPoint; } catch { /* MS: Why do we not expect an EndPoint here ??? */ } // Create a list of result entries and add them to the result storage noOfEntries = targetFeed.Entries.Count; SyncResultEntryInfo[] syncResultEntries = new SyncResultEntryInfo[noOfEntries]; FeedSerializer serializer = (FeedSerializer)_request.Serializer; FeedEntry entry; string httpMethod = null; int httpStatus = 0; string httpLocation = null; string httpMessage = null; string diagnosisXml = null; string payloadXml = null; DateTime stamp = DateTime.Now; for (int i = 0; i < noOfEntries; i++) { entry = targetFeed.Entries[i]; if (entry != null) { httpMethod = entry.HttpMethod; httpStatus = -1; if (Enum.IsDefined(typeof(HttpStatusCode), entry.HttpStatusCode.ToString())) { httpStatus = (int)Enum.Parse(typeof(HttpStatusCode), entry.HttpStatusCode.ToString(), true); } httpLocation = entry.HttpLocation; httpMessage = entry.HttpMessage; payloadXml = this.SerializeFeedEntryToXml(entry, serializer); stamp = entry.Updated.ToLocalTime(); } if (entry.Diagnoses != null && entry.Diagnoses.Count > 0) { diagnosisXml = this.SerializeObjectToXml(entry.Diagnoses[0]); } syncResultEntries[i] = new SyncResultEntryInfo(httpMethod, httpStatus, httpLocation, httpMessage, diagnosisXml, payloadXml, stamp, EndPoint); } // add entries to result storage syncResultInfoStore.Add(resourceKindName, syncResultEntries); _request.Response.StatusCode = HttpStatusCode.OK; }