implementations.cs
来自「ajax patterns 这是关于ajax设计模式方面的原代码」· CS 代码 · 共 86 行
CS
86 行
/*
Copyright 2006 Christian Gross http://www.devspace.com
From the book Ajax Patterns and Best Practices
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Web;
namespace Devspace.Ajax.CacheController.Books {
public class LibrarianHandler : IHttpHandler {
private string GetISBNFromURL(String URL) {
return "";
}
private Book GetBookDetails(String isbn) {
return null;
}
private void GenerateGetContent( HttpResponse resp, Book book) {
}
private void GeneratePutContent( HttpResponse resp, Book book) {
}
private Book GetDetailsFromRequest( HttpRequest req) {
return null;
}
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
HttpRequest req = context.Request;
HttpResponse resp = context.Response;
if (req.HttpMethod == "GET") {
string isbn = GetISBNFromURL( req.Path);
try {
String etagvalue = req.Headers.Get( "If-Match");
Librarian librarian = LibrarianBuilder.create(etagvalue);
Book book = librarian.CheckOutBook(isbn);
if (etagvalue != null && book.GetHashCode() == int.Parse( etagvalue)) {
resp.StatusCode = 304;
resp.Status = "Not modified";
return;
}
resp.AddHeader("ETag", book.GetHashCode().ToString());
GenerateGetContent(resp, book);
}
catch (Exception ex) {
throw new HttpParseException("LibrarianServlet generated error", ex);
}
}
else if( req.HttpMethod == "POST") {
try {
Librarian librarian = LibrarianBuilder.create("nothing");
Book book = GetDetailsFromRequest(req);
librarian.CheckInBook(book);
GeneratePutContent(resp, book);
}
catch (Exception ex) {
throw new HttpParseException("LibrarianServlet generated error", ex);
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?