當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。