当前位置: 首页>>代码示例>>C#>>正文


C# MemoryStream.AsContent方法代码示例

本文整理汇总了C#中System.IO.MemoryStream.AsContent方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.AsContent方法的具体用法?C# MemoryStream.AsContent怎么用?C# MemoryStream.AsContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.MemoryStream的用法示例。


在下文中一共展示了MemoryStream.AsContent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDirectoryGetResponse

        protected override Task<HttpResponseMessage> CreateDirectoryGetResponse(DirectoryInfo info, string localFilePath)
        {
            HttpResponseMessage response = Request.CreateResponse();
            using (var ms = new MemoryStream())
            {
                using (var zip = new ZipArchive(ms, ZipArchiveMode.Create, leaveOpen: true))
                {
                    foreach (FileSystemInfo fileSysInfo in info.EnumerateFileSystemInfos())
                    {
                        DirectoryInfo directoryInfo = fileSysInfo as DirectoryInfo;
                        if (directoryInfo != null)
                        {
                            zip.AddDirectory(new DirectoryInfoWrapper(directoryInfo), fileSysInfo.Name);
                        }
                        else
                        {
                            // Add it at the root of the zip
                            zip.AddFile(fileSysInfo.FullName, String.Empty);
                        }
                    }
                }
                response.Content = ms.AsContent();
            }

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");

            // Name the zip after the folder. e.g. "c:\foo\bar\" --> "bar"
            response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(Path.GetDirectoryName(localFilePath)) + ".zip";
            return Task.FromResult(response);
        }
开发者ID:WeAreMammoth,项目名称:kudu-obsolete,代码行数:31,代码来源:ZipController.cs

示例2: CreateDirectoryGetResponse

        protected override Task<HttpResponseMessage> CreateDirectoryGetResponse(DirectoryInfo info, string localFilePath)
        {
            HttpResponseMessage response = Request.CreateResponse();
            using (var zip = new ZipFile())
            {
                foreach (FileSystemInfo fileSysInfo in info.EnumerateFileSystemInfos())
                {
                    bool isDirectory = (fileSysInfo.Attributes & FileAttributes.Directory) != 0;

                    if (isDirectory)
                    {
                        zip.AddDirectory(fileSysInfo.FullName, fileSysInfo.Name);
                    }
                    else
                    {
                        // Add it at the root of the zip
                        zip.AddFile(fileSysInfo.FullName, "/");
                    }
                }

                using (var ms = new MemoryStream())
                {
                    zip.Save(ms);
                    response.Content = ms.AsContent();
                }
            }

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");

            // Name the zip after the folder. e.g. "c:\foo\bar\" --> "bar"
            response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(Path.GetDirectoryName(localFilePath)) + ".zip";
            return Task.FromResult(response);
        }
开发者ID:BrianVallelunga,项目名称:kudu,代码行数:34,代码来源:ZipController.cs

示例3: GetDiagnostics

        public HttpResponseMessage GetDiagnostics()
        {
            lock (_lockObj)
            {
                var response = new HttpResponseMessage();
                using (var zip = new ZipFile())
                {
                    foreach (var path in _paths)
                    {
                        if (Directory.Exists(path))
                        {
                            zip.AddDirectory(path, Path.GetFileName(path));
                        }
                    }

                    var ms = new MemoryStream();
                    zip.Save(ms);
                    response.Content = ms.AsContent();
                }
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = String.Format("dump-{0:MM-dd-H:mm:ss}.zip", DateTime.UtcNow);
                return response;
            }
        }
开发者ID:loudej,项目名称:kudu,代码行数:25,代码来源:DiagnosticsService.cs

示例4: CreateResponse

        private HttpResponseMessage CreateResponse(MemoryStream stream, string mediaType)
        {
            _tracer.Trace("Writing {0} bytes", stream.Length);

            HttpContent content = stream.AsContent();

            content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
            // REVIEW: Why is it that we do not write an empty Content-Type here, like for InfoRefsController?

            var response = new HttpResponseMessage();
            response.Content = content;
            response.WriteNoCache();
            return response;
        }
开发者ID:rguerreiro,项目名称:kudu,代码行数:14,代码来源:RpcController.cs

示例5: GetLog

        public HttpResponseMessage GetLog()
        {
            lock (_lockObj)
            {
                HttpResponseMessage response = Request.CreateResponse();

                using (var stream = new MemoryStream())
                {
                    using (var zip = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true))
                    {
                        AddFilesToZip(zip);
                        
                    }
                    response.Content = stream.AsContent();
                }

                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = String.Format("dump-{0:MM-dd-H:mm:ss}.zip", DateTime.UtcNow);
                return response;
            }
        }
开发者ID:richardprice,项目名称:kudu,代码行数:22,代码来源:DiagnosticsController.cs

示例6: SmartInfoRefs

        private HttpResponseMessage SmartInfoRefs(string service)
        {
            using (_tracer.Step("InfoRefsService.SmartInfoRefs"))
            {
                var memoryStream = new MemoryStream();

                memoryStream.PktWrite("# service=git-{0}\n", service);
                memoryStream.PktFlush();

                if (service == "upload-pack")
                {
                    //// Initialize the repository from the deployment files (if this is the first commit)
                    //ChangeSet changeSet = _gitServer.Initialize(_configuration, _webRootPath);
                    //_gitServer.AdvertiseUploadPack(memoryStream);

                    //// If we just created the repo, make a 'pseudo' deployment for the initial commit
                    //if (changeSet != null)
                    //{
                    //    _deploymentManager.CreateExistingDeployment(changeSet.Id, _configuration.Username);
                    //}

                    _gitServer.Initialize();
                    _gitServer.AdvertiseUploadPack(memoryStream);
                }
                else if (service == "receive-pack")
                {
                    _gitServer.Initialize();
                    _gitServer.AdvertiseReceivePack(memoryStream);
                }

                _tracer.Trace("Writing {0} bytes", memoryStream.Length);

                HttpContent content = memoryStream.AsContent();

                content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/x-git-{0}-advertisement".With(service));
                // Explicitly set the charset to empty string
                // We do this as certain git clients (jgit) require it to be empty.
                // If we don't set it, then it defaults to utf-8, which breaks jgit's logic for detecting smart http
                content.Headers.ContentType.CharSet = "";

                var responseMessage = new HttpResponseMessage();
                responseMessage.Content = content;
                responseMessage.WriteNoCache();
                return responseMessage;
            }
        }
开发者ID:bhaveshc,项目名称:kudu,代码行数:47,代码来源:InfoRefsController.cs

示例7: SmartInfoRefs

        private HttpResponseMessage SmartInfoRefs(string service)
        {
            using (_tracer.Step("InfoRefsService.SmartInfoRefs"))
            {
                var memoryStream = new MemoryStream();

                memoryStream.PktWrite("# service=git-{0}\n", service);
                memoryStream.PktFlush();

                if (service == "upload-pack")
                {
                    // Initialize the repository from the deployment files (if this is the first commit)
                    _gitServer.Initialize(_configuration, _deploymentTargetPath);
                    _gitServer.AdvertiseUploadPack(memoryStream);
                }
                else if (service == "receive-pack")
                {
                    _gitServer.Initialize(_configuration);
                    _gitServer.AdvertiseReceivePack(memoryStream);
                }

                if (memoryStream.Length < 100)
                {
                    _tracer.TraceWarning("Unexpected number of bytes written. {0} bytes", memoryStream.Length);
                }
                else
                {
                    _tracer.Trace("Writing {0} bytes", memoryStream.Length);
                }

                // TODO: Should we only do this in debug mode?
                _tracer.Trace("Git stream", new Dictionary<string, string>
                {
                    { "type", "gitStream" },
                    { "output", Encoding.UTF8.GetString(memoryStream.ToArray()) }
                });

                HttpContent content = memoryStream.AsContent();

                content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/x-git-{0}-advertisement".With(service));
                // Explicitly set the charset to empty string
                // We do this as certain git clients (jgit) require it to be empty.
                // If we don't set it, then it defaults to utf-8, which breaks jgit's logic for detecting smart http
                content.Headers.ContentType.CharSet = "";

                var responseMessage = new HttpResponseMessage();
                responseMessage.Content = content;
                responseMessage.WriteNoCache();
                return responseMessage;
            }
        }
开发者ID:loudej,项目名称:kudu,代码行数:52,代码来源:InfoRefsService.cs

示例8: CreateResponse

        private HttpResponseMessage CreateResponse(MemoryStream stream, string mediaType)
        {
            _tracer.Trace("Writing {0} bytes", stream.Length);

            // TODO: Should we only do this in debug mode?
            _tracer.Trace("Git stream", new Dictionary<string, string>
            {
                { "type", "gitStream" },
                { "output", Encoding.UTF8.GetString(stream.ToArray()) }
            });

            HttpContent content = stream.AsContent();

            content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
            // REVIEW: Why is it that we do not write an empty Content-Type here, like for InfoRefsController?

            var response = new HttpResponseMessage();
            response.Content = content;
            response.WriteNoCache();
            return response;
        }
开发者ID:loudej,项目名称:kudu,代码行数:21,代码来源:RpcService.cs

示例9: GetLog

        public HttpResponseMessage GetLog()
        {
            lock (_lockObj)
            {
                HttpResponseMessage response = Request.CreateResponse();
                using (var zip = new ZipFile())
                {
                    foreach (var path in _paths)
                    {
                        if (Directory.Exists(path))
                        {
                            if (path.EndsWith(Constants.LogFilesPath))
                            {
                                var dir = new DirectoryInfo(path);
                                foreach (var info in dir.GetFileSystemInfos())
                                {
                                    if (info is DirectoryInfo)
                                    {
                                        // excluding FREB as it contains user sensitive data such as authorization header
                                        if (!info.Name.StartsWith("W3SVC", StringComparison.OrdinalIgnoreCase))
                                        {
                                            zip.AddDirectory(info.FullName, Path.Combine(dir.Name, info.Name));
                                        }
                                    }
                                    else
                                    {
                                        zip.AddFile(info.FullName, dir.Name);
                                    }
                                }
                            }
                            else
                            {
                                zip.AddDirectory(path, Path.GetFileName(path));
                            }
                        }
                        else if (File.Exists(path))
                        {
                            zip.AddFile(path, String.Empty);
                        }
                    }

                    var ms = new MemoryStream();
                    zip.Save(ms);
                    response.Content = ms.AsContent();
                }
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = String.Format("dump-{0:MM-dd-H:mm:ss}.zip", DateTime.UtcNow);
                return response;
            }
        }
开发者ID:lookworld,项目名称:kudu,代码行数:51,代码来源:DiagnosticsController.cs

示例10: SmartInfoRefs

        private HttpResponseMessage SmartInfoRefs(string service)
        {
            using (_tracer.Step("InfoRefsService.SmartInfoRefs"))
            {
                using (var memoryStream = new MemoryStream())
                {
                    memoryStream.PktWrite("# service=git-{0}\n", service);
                    memoryStream.PktFlush();

                    if (service == "upload-pack")
                    {
                        _gitServer.AdvertiseUploadPack(memoryStream);
                    }
                    else if (service == "receive-pack")
                    {
                        _gitServer.AdvertiseReceivePack(memoryStream);
                    }

                    _tracer.Trace("Writing {0} bytes", memoryStream.Length);

                    HttpContent content = memoryStream.AsContent();

                    content.Headers.ContentType =
                        new MediaTypeHeaderValue("application/x-git-{0}-advertisement".With(service));
                    // Explicitly set the charset to empty string
                    // We do this as certain git clients (jgit) require it to be empty.
                    // If we don't set it, then it defaults to utf-8, which breaks jgit's logic for detecting smart http
                    content.Headers.ContentType.CharSet = "";

                    var responseMessage = new HttpResponseMessage();
                    responseMessage.Content = content;
                    responseMessage.WriteNoCache();
                    return responseMessage;
                }
            }
        }
开发者ID:GregPerez83,项目名称:kudu,代码行数:36,代码来源:InfoRefsController.cs


注:本文中的System.IO.MemoryStream.AsContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。