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


C# Nancy.Response类代码示例

本文整理汇总了C#中Nancy.Response的典型用法代码示例。如果您正苦于以下问题:C# Response类的具体用法?C# Response怎么用?C# Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Response类属于Nancy命名空间,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteBucket

        private Response DeleteBucket(string bucket)
        {
            storage.DeleteBucket(bucket);

              var response = new Response { StatusCode = HttpStatusCode.NoContent };
              return response;
        }
开发者ID:nrazon,项目名称:S3Emulator,代码行数:7,代码来源:BucketModule.cs

示例2: AddObject

        private Response AddObject(string bucket, string key, Stream stream)
        {
            if (Request.Url.Query == "?acl")
              {
            return new Response { StatusCode = HttpStatusCode.OK };
              }

              var content = stream.Copy(configuration.MaxBytesPerSecond);

              var s3Object = new S3Object
              {
            Bucket = bucket,
            Key = key,
            ContentType = Request.Headers.ContentType,
            CreationDate = DateTime.UtcNow,
            Content = () => content,
            ContentMD5 = content.GenerateMD5CheckSum(),
            Size = content.Length
              };

              storage.AddObject(s3Object);

              var response = new Response { StatusCode = HttpStatusCode.OK };
              response.WithHeader("ETag", string.Format("\"{0}\"", s3Object.ContentMD5));
              return response;
        }
开发者ID:yadazula,项目名称:S3Emulator,代码行数:26,代码来源:S3ObjectModule.cs

示例3: RequiresClaims

        /// <summary>
        /// Gets a request hook for checking claims
        /// </summary>
        /// <param name="claims">Required claims</param>
        /// <returns>Before hook delegate</returns>
        public static Func<NancyContext, Response> RequiresClaims(IEnumerable<string> claims)
        {
            return (ctx) =>
                {
                    var failResponse = new Response() { StatusCode = HttpStatusCode.Forbidden };

                    object userClaimsObject;

                    if (!ctx.Items.TryGetValue(CLAIMS_KEY, out userClaimsObject))
                    {
                        return failResponse;
                    }

                    var userClaims = userClaimsObject as IEnumerable<string>;
                    if (userClaims == null)
                    {
                        return failResponse;
                    }

                    if (claims.Any(claim => !userClaims.Contains(claim)))
                    {
                        return failResponse;
                    }

                    return null;
                };
        }
开发者ID:ToJans,项目名称:Nancy,代码行数:32,代码来源:Security.cs

示例4: Should_set_a_cookie_with_name_and_value

 public void Should_set_a_cookie_with_name_and_value()
 {
     var response = new Response();
     response.AddCookie("itsover", "9000");
     response.Cookies.Count.ShouldEqual(1);
     response.Cookies[0].ShouldEqual("itsover", "9000", null, null, null);
 }
开发者ID:sequoiar,项目名称:Nancy,代码行数:7,代码来源:ResponseFixture.cs

示例5: AsNancyResponse

        public static Response AsNancyResponse(this OutgoingWebResponse openauthResponse)
        {
            var response = new Response();

            var statusCode = HttpStatusCode.InternalServerError;
            string statusCodeName = null;
            if (openauthResponse.Status == System.Net.HttpStatusCode.Redirect)
            {
                statusCodeName = HttpStatusCode.TemporaryRedirect.ToString();
            }
            else
            {
                statusCodeName = openauthResponse.Status.ToString();
            }

            if (!Enum.TryParse<HttpStatusCode>(statusCodeName, out statusCode))
            {
                throw new Exception("Unknown Status Code: " + openauthResponse.Status.ToString());
            }
            response.StatusCode = statusCode;

            var headers = new Dictionary<string, string>();
            foreach(var key in openauthResponse.Headers.AllKeys)
            {
                headers.Add(key, openauthResponse.Headers[key]);
            }
            response.Headers = headers;

            var body = Encoding.UTF8.GetBytes(openauthResponse.Body);
            response.Contents = stream => stream.Write(body, 0, body.Length);

            return response;
        }
开发者ID:CollapsedTotoProductionCommittee,项目名称:CollapsedToto,代码行数:33,代码来源:Utils.cs

示例6: CompressResponse

        private Response CompressResponse(Request request, Response response)
        {
            if (!response.ContentType.Contains("image")
                && request.Headers.AcceptEncoding.Any(x => x.Contains("gzip"))
                && (!response.Headers.ContainsKey("Content-Encoding") || response.Headers["Content-Encoding"] != "gzip"))
            {
                var data = new MemoryStream();
                response.Contents.Invoke(data);
                data.Position = 0;
                if (data.Length < 1024)
                {
                    response.Contents = stream =>
                    {
                        data.CopyTo(stream);
                        stream.Flush();
                    };
                }
                else
                {
                    response.Headers["Content-Encoding"] = "gzip";
                    response.Contents = s =>
                    {
                        var gzip = new GZipStream(s, CompressionMode.Compress, true);
                        data.CopyTo(gzip);
                        gzip.Close();
                    };
                }
            }

            return response;
        }
开发者ID:Kiljoymccoy,项目名称:NzbDrone,代码行数:31,代码来源:GZipPipeline.cs

示例7: ExportToCSV

        public static Response ExportToCSV()
        {
            var calls = SupportCall.ToList();

            var response = new Response();

            response.Headers.Add("Content-Disposition", "attachment; filename=ExportedData" + DateTime.Now.ToString("dd MMM yyyy HH mm") + ".csv");


            response.Contents = stream =>
            {
                StreamWriter sw = new StreamWriter(stream);


                sw.Write("Internal Reference, Customer, Customer Reference, Customer Site, Customer Site Location, Assigned To, Product, Status, Created By, CreatedTime, Note Type, Note Sub Type, Note Text, Time Spent, Created By, Created Date Time");
                sw.Write(sw.NewLine);
                foreach (var call in calls)
                {
                    var notes = Note.LoadFromCall(call.RecordID);
                    foreach (var note in notes.OrderByDescending(x => x.CreatedDateTime).ThenByDescending(x => x.NoteType))
                    {
                        sw.Write(call.InternalReference);
                        sw.Write(",");
                        sw.Write(call.CustomerName);
                        sw.Write(",");
                        sw.Write(call.CustomerReference);
                        sw.Write(",");
                        sw.Write(call.CustomerSiteName);
                        sw.Write(",");
                        sw.Write(call.CustomerSiteLocationName);
                        sw.Write(",");
                        sw.Write(call.AssignedTo);
                        sw.Write(",");
                        sw.Write(call.ProductName);
                        sw.Write(",");
                        sw.Write(call.Status);
                        sw.Write(",");
                        sw.Write(call.CreatedBy);
                        sw.Write(",");
                        sw.Write(call.CreatedDateTime);
                        sw.Write(",");
                        sw.Write(note.NoteType);
                        sw.Write(",");
                        sw.Write(note.NoteSubType);
                        sw.Write(",");
                        sw.Write(note.NoteText);
                        sw.Write(",");
                        sw.Write(note.TimeSpent);
                        sw.Write(",");
                        sw.Write(note.CreatedBy);
                        sw.Write(",");
                        sw.Write(note.CreatedDateTime);
                        sw.Write(sw.NewLine);
                    }

                }
                sw.Close();
            };
            return response;
        }
开发者ID:MHAWeb,项目名称:MachSecure.SCM,代码行数:60,代码来源:ExportModule.cs

示例8: CreateDinner

        private Response CreateDinner()
        {
            var dinner = this.Bind<Dinner>();
            nerdDinners.Dinners.Add(dinner);
            try
            {
                nerdDinners.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                var message = ex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage;
                var response = new Response
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Contents = stream =>
                                   {
                                       using (var writer = new StreamWriter(stream) { AutoFlush = true })
                                       {
                                           writer.WriteLine(message);
                                       }
                                   }
                };
                return response;
            }

            return new Response();
        }
开发者ID:ChadMcCallum,项目名称:NerdDinnerRevolutions,代码行数:27,代码来源:DinnerService.cs

示例9: AuthenticateModule

        public AuthenticateModule()
            : base("/api")
        {
            Post["/AuthenticateUser"] = parameters =>
                {
                    var bind = this.Bind<LoginRequest>();

                    //do something with request.Username and request.Password.

                    var response = new Response
                        {
                            StatusCode = HttpStatusCode.OK
                        };

                    response.AddCookie("valid", bind.Username, DateTime.Now.AddMinutes(5));
                    return response;
                };
            Get["/LogOff"] = parameters =>
                {
                    var response = new Response
                        {
                            StatusCode = HttpStatusCode.OK
                        };

                    //clear the cookie
                    response.AddCookie("valid", null, DateTime.Now.AddYears(-5));
                    return response;
                };
        }
开发者ID:markcoleman,项目名称:AngularBlogPost,代码行数:29,代码来源:AuthenticateModule.cs

示例10: _initResponse

		//	Kept seperate, as I guess more CSVs will be needed
		private static Response _initResponse()
		{
			Response response = new Response();
			response.Headers.Add("Content-Disposition", "attachment; filename=ExportedDate" + DateTime.Now.ToString("dd MMM yyyy HH mm") + ".csv");
			response.ContentType = "application/octet-stream";
			return response;
		}
开发者ID:MHAWeb,项目名称:MachSecure.CentralWebService,代码行数:8,代码来源:CSVExporter.cs

示例11: HandleExceptions

        private static Response HandleExceptions(Exception err, NancyContext ctx)
        {
            logger.Error("Failed {0} with {1}", ctx.Request.Path, err);
            var result = new Response { ReasonPhrase = err.Message };

            if (err is NotImplementedException)
            {
                result.StatusCode = HttpStatusCode.NotImplemented;
            }
            else if (err is UnauthorizedAccessException)
            {
                result.StatusCode = HttpStatusCode.Unauthorized;
            }
            else if (err is ArgumentException)
            {
                result.StatusCode = HttpStatusCode.BadRequest;
            }
            else
            {
                // An unexpected exception occurred!
                result.StatusCode = HttpStatusCode.InternalServerError;
            }

            return result;
        }
开发者ID:kevintavog,项目名称:OpenStreetMapCache,代码行数:25,代码来源:ApiBootstrapper.cs

示例12: AuthModule

        public AuthModule()
            : base("/api")
        {
            Post["/authenticate"] = x => {
                var bind = this.Bind<LoginRequest>();

                UserManager<User> manager = new UserManager<User>(new UserStore());

                var user = manager.Find(bind.Username, bind.Password);

                if (user == null)
                {
                    return new Response
                    {
                        StatusCode = HttpStatusCode.Unauthorized
                    };
                }
                else
                {
                    var response = new Response
                    {
                        StatusCode = HttpStatusCode.OK
                    };
                    return response.WithCookie("sq-valid", user.UserName, DateTime.Now.AddMinutes(5));
                }
            };

            Get["/logout"] = x => {
                var response = new Response
                {
                    StatusCode = HttpStatusCode.OK
                };
                return response.WithCookie("sq-valid", null, DateTime.Now.AddYears(-5));
            };
        }
开发者ID:fugaku,项目名称:StockQuote,代码行数:35,代码来源:AuthModule.cs

示例13: AddBucket

        private Response AddBucket(string bucketName)
        {
            var bucket = new Bucket { Id = bucketName, CreationDate = DateTime.UtcNow };
              storage.AddBucket(bucket);

              var response = new Response { StatusCode = HttpStatusCode.OK };
              return response;
        }
开发者ID:nrazon,项目名称:S3Emulator,代码行数:8,代码来源:BucketModule.cs

示例14: Should_set_a_cookie_with_name_and_value_and_expiry

 public void Should_set_a_cookie_with_name_and_value_and_expiry()
 {
     var response = new Response();
     var date = DateTime.Now;
     response.AddCookie("itsover", "9000", date);
     response.Cookies.Count.ShouldEqual(1);
     response.Cookies[0].ShouldEqual("itsover", "9000", date, null, null);
 }
开发者ID:sequoiar,项目名称:Nancy,代码行数:8,代码来源:ResponseFixture.cs

示例15: Should_set_a_cookie_with_everything

 public void Should_set_a_cookie_with_everything()
 {
     var response = new Response();
     var date = DateTime.Now;
     response.AddCookie("itsover", "9000", date, "life", "/andeverything");
     response.Cookies.Count.ShouldEqual(1);
     response.Cookies[0].ShouldEqual("itsover", "9000", date, "life", "/andeverything");
 }
开发者ID:sequoiar,项目名称:Nancy,代码行数:8,代码来源:ResponseFixture.cs


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