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


C# DreamMessage.ToStream方法代码示例

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


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

示例1: Upload_Helper

 private Yield Upload_Helper(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     using(var stream = request.ToStream()) {
         var total = 0;
         var buffer = new byte[1024 * 1024];
         while(total < request.ContentLength) {
             Result<int> read;
             yield return read = stream.Read(buffer, 0, buffer.Length, new Result<int>());
             //int read = stream.Read(buffer, 0, buffer.Length);
             if(read.Value == 0) {
                 break;
             }
             total += read.Value;
             //fake some latency
             yield return AsyncUtil.Sleep(TimeSpan.FromMilliseconds(1));
         }
         _log.DebugFormat("read {0}/{1} bytes", total, request.ContentLength);
         if(total != request.ContentLength) {
             throw new DreamBadRequestException(string.Format("was supposed to read {0} bytes, only read {1}", request.ContentLength, total));
         }
     }
     response.Return(DreamMessage.Ok());
 }
开发者ID:heran,项目名称:DReAM,代码行数:23,代码来源:PlugTests.cs

示例2: HandleInvoke


//.........这里部分代码省略.........
                    if(!HandleResponse(activity, e, null, response)) {
                        _log.ErrorExceptionMethodCall(e, "[email protected]", verb, uri);
                        try {
                            httpRequest.Abort();
                        } catch { }
                    }
                    yield break;
                }
                activity("pre yield BeginGetRequestStream");
                yield return async.Catch();
                activity("post yield BeginGetRequestStream");

                // send request
                Stream outStream;
                try {
                    activity("pre EndGetRequestStream");
                    outStream = httpRequest.EndGetRequestStream(async.Value);
                    activity("pre EndGetRequestStream");
                } catch(Exception e) {
                    activity("pre HandleResponse 2");
                    if(!HandleResponse(activity, e, null, response)) {
                        _log.ErrorExceptionMethodCall(e, "[email protected]", verb, uri);
                        try {
                            httpRequest.Abort();
                        } catch { }
                    }
                    yield break;
                }

                // copy data
                using(outStream) {
                    Result<long> res;
                    activity("pre yield CopyStream");
                    yield return res = request.ToStream().CopyTo(outStream, request.ContentLength, new Result<long>(TimeSpan.MaxValue)).Catch();
                    activity("post yield CopyStream");
                    if(res.HasException) {
                        activity("pre HandleResponse 3");
                        if(!HandleResponse(activity, res.Exception, null, response)) {
                            _log.ErrorExceptionMethodCall(res.Exception, "[email protected]", verb, uri);
                            try {
                                httpRequest.Abort();
                            } catch { }
                        }
                        yield break;
                    }
                }
            }
            request = null;

            // wait for response
            async = new Result<IAsyncResult>(response.Timeout);
            try {
                activity("pre BeginGetResponse");
                httpRequest.BeginGetResponse(async.Return, null);
                activity("post BeginGetResponse");
            } catch(Exception e) {
                activity("pre HandleResponse 4");
                if(!HandleResponse(activity, e, null, response)) {
                    _log.ErrorExceptionMethodCall(e, "[email protected]", verb, uri);
                    try {
                        httpRequest.Abort();
                    } catch { }
                }
                yield break;
            }
            activity("pre yield BeginGetResponse");
开发者ID:danice,项目名称:DReAM,代码行数:67,代码来源:HttpPlugEndpoint.cs

示例3: HandleInvoke


//.........这里部分代码省略.........
                    if(!HandleResponse(activity, e, null, response)) {
                        _log.ErrorExceptionMethodCall(e, "[email protected]", verb, uri);
                        try {
                            httpRequest.Abort();
                        } catch { }
                    }
                    yield break;
                }
                activity("pre yield BeginGetRequestStream");
                yield return async.Catch();
                activity("post yield BeginGetRequestStream");

                // send request
                Stream outStream;
                try {
                    activity("pre EndGetRequestStream");
                    outStream = httpRequest.EndGetRequestStream(async.Value);
                    activity("pre EndGetRequestStream");
                } catch(Exception e) {
                    activity("pre HandleResponse 2");
                    if(!HandleResponse(activity, e, null, response)) {
                        _log.ErrorExceptionMethodCall(e, "[email protected]", verb, uri);
                        try {
                            httpRequest.Abort();
                        } catch { }
                    }
                    yield break;
                }

                // copy data
                using(outStream) {
                    Result<long> res;
                    activity("pre yield CopyStream");
                    yield return res = request.ToStream().CopyTo(outStream, request.ContentLength, new Result<long>(TimeSpan.MaxValue)).Catch();
                    activity("post yield CopyStream");
                    if(res.HasException) {
                        activity("pre HandleResponse 3");
                        if(!HandleResponse(activity, res.Exception, null, response)) {
                            _log.ErrorExceptionMethodCall(res.Exception, "[email protected]", verb, uri);
                            try {
                                httpRequest.Abort();
                            } catch { }
                        }
                        yield break;
                    }
                }
            }
            request = null;

            // wait for response
            async = new Result<IAsyncResult>(response.Timeout);
            try {
                activity("pre BeginGetResponse");
                httpRequest.BeginGetResponse(async.Return, null);
                activity("post BeginGetResponse");
            } catch(Exception e) {
                activity("pre HandleResponse 4");
                if(!HandleResponse(activity, e, null, response)) {
                    _log.ErrorExceptionMethodCall(e, "[email protected]", verb, uri);
                    try {
                        httpRequest.Abort();
                    } catch { }
                }
                yield break;
            }
            activity("pre yield BeginGetResponse");
开发者ID:melder,项目名称:DReAM,代码行数:67,代码来源:HttpPlugEndpoint.cs

示例4: PutFile

        public Yield PutFile(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            string filepath = GetPath(context);
            string folderpath = Path.GetDirectoryName(filepath);
            double ttl = context.GetParam("ttl", 0.0);
            TimeSpan? timeToLive = null;
            if(ttl > 0.0) {
                timeToLive = TimeSpan.FromSeconds(ttl);
            }
            if(Directory.Exists(filepath)) {

                // filepath is actually an existing directory
                response.Return(DreamMessage.Conflict("there exists a directory at the specified file path"));
                yield break;
            }

            // create folder if need be
            if(!Directory.Exists(folderpath)) {
                Directory.CreateDirectory(folderpath);
            }

            // save request stream in target file
            DreamMessage result;
            try {
                request.ToStream().CopyToFile(filepath, request.ContentLength);
                WriteMeta(filepath, timeToLive, null);
                result = DreamMessage.Ok();
            } catch(DirectoryNotFoundException) {
                result = DreamMessage.NotFound("directory not found");
            } catch(PathTooLongException) {
                result = DreamMessage.BadRequest("path too long");
            } catch(NotSupportedException) {
                result = DreamMessage.BadRequest("not supported");
            }
            response.Return(result);
            yield break;
        }
开发者ID:heran,项目名称:DReAM,代码行数:37,代码来源:StorageService.cs

示例5: PutFile

 public Yield PutFile(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     var filepath = GetPath(context);
     var ttl = context.GetParam("ttl", 0.0);
     TimeSpan? timeToLive = null;
     if(ttl > 0.0) {
         timeToLive = TimeSpan.FromSeconds(ttl);
     }
     try {
         _s3Client.PutFile(filepath, new AwsS3FileHandle {
             Stream = request.ToStream(),
             Size = request.ContentLength,
             MimeType = request.ContentType,
             TimeToLive = timeToLive
         });
         response.Return(DreamMessage.Ok());
     } catch(Exception e) {
         throw new DreamBadRequestException(e.Message);
     }
     yield break;
 }
开发者ID:danice,项目名称:DReAM,代码行数:21,代码来源:S3StorageService.cs


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