public dynamic Execute(dynamic parameters, INancyModule module) { NuGetODataModelBuilderODataPackage builder = new NuGetODataModelBuilderODataPackage(); builder.Build(); IODataResponseMessage message = new MemoryResponseMessage(); ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings(); using (var msgWriter = new ODataMessageWriter(message, writerSettings, builder.Model)) { msgWriter.WriteMetadataDocument(); var msgStream = message.GetStream(); msgStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(msgStream); string text = reader.ReadToEnd(); return(new Response { ContentType = "application/xml; charset=utf-8", Contents = contentStream => { var byteData = Encoding.UTF8.GetBytes(text); contentStream.Write(byteData, 0, byteData.Length); msgStream.Dispose(); reader.Dispose(); } }); } }
public dynamic Execute(dynamic parameters, INancyModule module) { NuGetODataModelBuilderODataPackage builder = new NuGetODataModelBuilderODataPackage(); builder.Build(); IODataResponseMessage message = new MemoryResponseMessage(); ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings(); var url = module.Request.Url.ToString(); if (!url.EndsWith("/")) { url += "/"; } writerSettings.BaseUri = new Uri(url); using (var msgWriter = new ODataMessageWriter(message, writerSettings, builder.Model)) { var workspace = new ODataWorkspace { Collections = new List <ODataResourceCollectionInfo> { new ODataResourceCollectionInfo { Name = "Packages", Url = new Uri("Packages", UriKind.Relative) } } }; msgWriter.WriteServiceDocument(workspace); var msgStream = message.GetStream(); msgStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(msgStream); string text = reader.ReadToEnd(); return(new Response { ContentType = "application/xml; charset=utf-8", Contents = contentStream => { var byteData = Encoding.UTF8.GetBytes(text); contentStream.Write(byteData, 0, byteData.Length); msgStream.Dispose(); reader.Dispose(); } }); } }
protected virtual dynamic ProcessResponse(INancyModule module, IFeed feed, IInternalPackage package) { bool endsWithSlash = _portalConfig.ListenPrefixes.EndsWith("/"); var baseAddress = string.Format("{0}{1}feeds/{2}/api/v2/", _portalConfig.ListenPrefixes, endsWithSlash ? "" : "/", feed.Name); NuGetODataModelBuilderODataPackage builder = new NuGetODataModelBuilderODataPackage(); builder.Build(); var writerSettings = new ODataMessageWriterSettings() { Indent = true, CheckCharacters = false, BaseUri = new Uri(baseAddress), Version = ODataVersion.V3 }; writerSettings.SetContentType(ODataFormat.Atom); var responseMessage = new MemoryResponseMessage(); var writer = new ODataMessageWriter(responseMessage, writerSettings); var entryWriter = writer.CreateODataEntryWriter(); entryWriter.WriteStart(ODataPackages.MapPackageToEntry(baseAddress, new ODataPackage(package))); entryWriter.WriteEnd(); var msgStream = responseMessage.GetStream(); msgStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(msgStream); string text = reader.ReadToEnd(); return(new Response { ContentType = "application/atom+xml; charset=utf-8", Contents = contentStream => { var byteData = Encoding.UTF8.GetBytes(text); contentStream.Write(byteData, 0, byteData.Length); } }); }