コード例 #1
0
        public static Stream CreatePackageStream(string baseAddress, ODataPackage package)
        {
            var writerSettings = new ODataMessageWriterSettings()
            {
                Indent          = true, // pretty printing
                CheckCharacters = false,
                BaseUri         = new Uri("http://localhost:12345"),
                Version         = ODataVersion.V3
            };

            writerSettings.SetContentType(ODataFormat.Atom);

            var responseMessage = new MemoryResponseMessage();
            var writer          = new ODataMessageWriter(responseMessage, writerSettings);

            var feedWriter = writer.CreateODataEntryWriter();

            feedWriter.WriteStart(MapPackageToEntry(baseAddress, package));
            feedWriter.WriteEnd();
            feedWriter.Flush();

            var stream = responseMessage.GetStream();

            stream.Seek(0, SeekOrigin.Begin);

            return(stream);
        }
コード例 #2
0
        public static Stream CreatePackagesStream(string baseUrl, IInternalPackageRepository packageRepository, string baseAddress, IEnumerable <IInternalPackage> packages, int feedId, int total)
        {
            var writerSettings = new ODataMessageWriterSettings()
            {
                Indent          = true,
                CheckCharacters = false,
                BaseUri         = new Uri(baseUrl),
                Version         = ODataVersion.V3
            };

            writerSettings.SetContentType(ODataFormat.Atom);

            var responseMessage = new MemoryResponseMessage();
            var writer          = new ODataMessageWriter(responseMessage, writerSettings);

            var feedWriter = writer.CreateODataFeedWriter();

            feedWriter.WriteStart(new ODataFeed()
            {
                Id = "Packages", Count = total
            });


            var pks = packages.Select(pk => new ODataPackage(pk));

            foreach (var package in pks)
            {
                feedWriter.WriteStart(MapPackageToEntry(baseAddress, package));
                feedWriter.WriteEnd();
            }

            feedWriter.WriteEnd();
            feedWriter.Flush();

            var stream = responseMessage.GetStream();

            stream.Seek(0, SeekOrigin.Begin);

            return(stream);
        }