コード例 #1
0
ファイル: RedisCache.cs プロジェクト: ewin66/SAE
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="kvs"></param>
        /// <param name="timeSpan"></param>
        /// <returns></returns>
        public Task <bool> AddAsync <T>(IDictionary <string, T> kvs, TimeSpan?timeSpan = default(TimeSpan?))
        {
            var result = true;

            return(Task.Run(async() =>
            {
                await this.GetDataBase(async db =>
                {
                    foreach (var kv in kvs)
                    {
                        _log.Debug($"添加:{kv.Key}");
                        result = await db.StringSetAsync(kv.Key,
                                                         _jsonConvertor.Serialize(kv.Value),
                                                         timeSpan);
                        if (!result)
                        {
                            break;
                        }
                    }
                });
            }).ContinueWith(t =>
            {
                return result;
            }));
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              IJsonConvertor jsonConvertor,
                              IFileDecorator fileDecorator)
        {
            app.UseStatusCodePages()
            .UseStaticFiles();

            app.Map("/upload", builder =>
            {
                builder.Run(async context =>
                {
                    var result = new StandardResult();
                    if (context.Request?.Form?.Files == null || context.Request.Form.Files.Count <= 0)
                    {
                        result.StatusCode = StatusCode.RequestInvalid;
                        result.Message    = "请上传文件!";
                    }
                    else
                    {
                        List <FileDecorator> fileDecorators = new List <FileDecorator>();
                        foreach (var fileContext in context.Request.Form.Files.Select(f => new FileContext(f.FileName, f.OpenReadStream(), context)))
                        {
                            await fileDecorator.Decorate(fileContext);
                        }
                        result.Body = fileDecorators;
                    }
                    await context.Response.WriteAsync(jsonConvertor.Serialize(result));
                });
            });
        }
コード例 #3
0
ファイル: HttpRestTest.cs プロジェクト: ewin66/SAE
        private async Task OutPutResult(System.Net.Http.HttpResponseMessage response)
        {
            var resultModel = await response.AsModelAsync <object>();

            var resultStream = await response.AsStreamAsync();

            var resultString = await response.AsStringAsync();

            var json = _jsonConvertor.Serialize(resultModel);

            var bytes = new byte[resultStream.Length];

            await resultStream.ReadAsync(bytes, 0, bytes.Length);

            _outpub.WriteLine("Model:" + json);

            _outpub.WriteLine("Stream:" + Encoding.UTF8.GetString(bytes));

            _outpub.WriteLine("String:" + _jsonConvertor.Serialize(resultString));

            Assert.Equal(json, resultString.Trim());
        }