private IDocument GenerateFeed(FeedType feedType, Feed feed, ContextConfig path, IExecutionContext context) { // Get the output path FilePath outputPath = path?.Invoke <FilePath>(context, "while getting output path"); if (outputPath == null) { return(null); } if (!outputPath.IsRelative) { throw new ArgumentException("The feed output path must be relative"); } // Generate the feed and document MemoryStream stream = new MemoryStream(); FeedSerializer.SerializeXml(feedType, feed, stream); stream.Position = 0; return(context.GetDocument(stream, new MetadataItems { new MetadataItem(Keys.RelativeFilePath, outputPath), new MetadataItem(Keys.WritePath, outputPath) })); }
private string SerializeFeedEntryToXml(FeedEntry obj, FeedSerializer serializer) { if (null == obj) { return(null); } try { String xml = null; MemoryStream memoryStream = new MemoryStream(); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); serializer.SaveToStream(obj, memoryStream, null); xml = UTF8ByteArrayToString(memoryStream.ToArray()); return(xml); } catch { //Debug.WriteLine(e); return(null); } }
private async Task <IDocument> GenerateFeedAsync(FeedType feedType, Feed feed, FilePath path, IExecutionContext context) { // Get the output path if (path == null) { return(null); } if (!path.IsRelative) { throw new ArgumentException("The feed output path must be relative"); } // Generate the feed and document using (Stream contentStream = await context.GetContentStreamAsync()) { FeedSerializer.SerializeXml(feedType, feed, contentStream); return(context.CreateDocument(path, context.GetContentProvider(contentStream))); } }
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; }
private string SerializeFeedEntryToXml(FeedEntry obj, FeedSerializer serializer) { if (null == obj) return null; try { String xml = null; MemoryStream memoryStream = new MemoryStream(); XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); serializer.SaveToStream(obj, memoryStream, null); xml = UTF8ByteArrayToString(memoryStream.ToArray()); return xml; } catch { //Debug.WriteLine(e); return null; } }