本文整理汇总了C#中System.Net.HttpListenerContext.Finish方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerContext.Finish方法的具体用法?C# HttpListenerContext.Finish怎么用?C# HttpListenerContext.Finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpListenerContext
的用法示例。
在下文中一共展示了HttpListenerContext.Finish方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunTrace
private void RunTrace(HttpListenerContext callcontext) {
try {
var sb = new StringBuilder();
var sw = Stopwatch.StartNew();
var parameters = PrepareParameters(callcontext);
sw.Stop();
sb.AppendLine("Prepare: " + sw.Elapsed);
sw = Stopwatch.StartNew();
var result = _handler(parameters);
sw.Stop();
sb.AppendLine("Execute: "+sw.Elapsed);
sw = Stopwatch.StartNew();
var uson = result.ToUson();
sw.Stop();
sb.AppendLine("Usonify: " + sw.Elapsed);
sw = Stopwatch.StartNew();
var json = uson.ToJson();
sw.Stop();
sb.AppendLine("Jsonify: " + sw.Elapsed);
sw = Stopwatch.StartNew();
json = new JsonSerializer().Serialize("", result);
sw.Stop();
sb.AppendLine("Jsonify 2: " + sw.Elapsed);
callcontext.Finish(sb.ToString());
} catch (Exception ex) {
callcontext.Finish(ex.ToString(), "text/plain", 500);
}
}
示例2: Run
/// <summary>
///
/// </summary>
/// <param name="server"></param>
/// <param name="callcontext"></param>
/// <param name="callbackEndPoint"></param>
/// <param name="cancel"></param>
public void Run(IHostServer server, HttpListenerContext callcontext, string callbackEndPoint, CancellationToken cancel){
var abspath = callcontext.Request.Url.AbsolutePath;
if (string.IsNullOrWhiteSpace(abspath) || abspath == "/") {
abspath = DefaultPage;
}
var staticdescriptor = server.Static.Get(abspath, callcontext);
if (null == staticdescriptor){
callcontext.Finish("no file found", "text/plain; charset=utf-8", status: 404);
return;
}
var filetime = callcontext.SetLastModified(staticdescriptor.GetLastVersion());
if (filetime <= callcontext.GetIfModifiedSince())
{
callcontext.Finish("", status: 304);
}
else
{
callcontext.Response.AddHeader("Qorpent-Disposition",staticdescriptor.FullName);
if (staticdescriptor.IsFixedContent){
callcontext.Finish(staticdescriptor.FixedContent, staticdescriptor.MimeType + "; charset=utf-8");
}
else{
using (var s = staticdescriptor.Open()) {
callcontext.Finish(s, staticdescriptor.MimeType + "; charset=utf-8");
s.Close();
}
}
}
}
示例3: Run
/// <summary>
///
/// </summary>
/// <param name="server"></param>
/// <param name="callcontext"></param>
/// <param name="callbackEndPoint"></param>
/// <param name="cancel"></param>
public void Run(IHostServer server, HttpListenerContext callcontext, string callbackEndPoint, CancellationToken cancel){
var code = callcontext.Request.Url.Query.Replace("?", "");
string wikicode = "*** страница с данным кодом не найдена ***";
string tpl = "<html><body>${wikipage}</body></html>";
var wikidesc = server.Static.Get(code + ".wiki",withextensions:true);
if (null == wikidesc){
wikidesc = server.Static.Get(code,withextensions:true);
}
if (null != wikidesc)
{
using (var s = wikidesc.Open())
{
using (var r = new StreamReader(s)){
wikicode = r.ReadToEnd();
}
if (!wikidesc.FullName.EndsWith(".wiki")){
if (wikidesc.FullName.EndsWith(".bxl") || wikidesc.FullName.EndsWith(".bxls") || wikidesc.FullName.EndsWith(".bsproj")){
wikicode = "[[code]]\r\n" + wikicode + "\r\n[[/code]]\r\n[[script-last type=bxl]]";
}
else if (wikidesc.FullName.EndsWith(".js") || wikidesc.FullName.EndsWith(".css") ||
wikidesc.FullName.EndsWith(".cs")){
wikicode = "[[code]]\r\n" + wikicode + "\r\n[[/code]]";
}
else{
wikicode = wikicode.Replace("\r\n", "\r\n\r\n ");
}
wikicode = "= Файл: [href:" + wikidesc.FullName + "]\r\n\r\n" + wikicode;
}
}
}
var tpldesc = server.Static.Get( "wiki.html");
if (null != tpldesc)
{
using (var s = tpldesc.Open())
{
using (var r = new StreamReader(s))
{
tpl = r.ReadToEnd();
}
}
}
var wikipage = tpl.Replace("${wikipage}", wikicode);
callcontext.Finish(wikipage,mimeType:"text/html");
}
示例4: AsynchronousEnd
private void AsynchronousEnd(HttpListenerContext callcontext){
if (null == currentAsyncCall)
{
callcontext.Finish("no asynchronous task ever started", "text/plain", 500);
}
currentAsyncCall.Wait();
if (currentAsyncCall.IsFaulted)
{
callcontext.Finish("last call to async fail with " + currentAsyncCall.Exception, "text/plain", 500);
}
else if (currentAsyncCall.IsCanceled)
{
callcontext.Finish("last call to async was cancelled", "text/plain", 500);
}
else
{
if (callcontext.Request.Url.AbsolutePath.EndsWith("/xml"))
{
callcontext.Finish(((UObj)currentAsyncCall.Result).ToXmlString(), "text/xml");
}
else
{
callcontext.Finish(((UObj)currentAsyncCall.Result).ToJson(), "application/json");
}
}
}
示例5: RunSynchronous
private void RunSynchronous(HttpListenerContext callcontext){
try{
var parameters = PrepareParameters(callcontext);
var obj = _handler(parameters);
var result = obj.ToUson();
if (callcontext.Request.Url.AbsolutePath.EndsWith("/xml")){
callcontext.Finish(result.ToXmlString(), "text/xml");
}
else{
callcontext.Finish(result.ToJson(), "application/json");
}
}
catch (Exception ex){
callcontext.Finish(ex.ToString(), "text/plain", 500);
}
}
示例6: AsynchronousBegin
private void AsynchronousBegin(HttpListenerContext callcontext){
if (null != currentAsyncCall){
if (!currentAsyncCall.IsCompleted){
callcontext.Finish("{\"state\":\"run\"}");
return;
}
}
var parameters = PrepareParameters(callcontext);
currentAsyncCall = Task.Run(() => _handler(parameters));
callcontext.Finish("{\"state\":\"start\"}");
}
示例7: Run
/// <summary>
/// Выполняет указанный запрос
/// </summary>
/// <param name="server"></param>
/// <param name="callcontext"></param>
/// <param name="callbackEndPoint"></param>
/// <param name="cancel"></param>
public void Run(IHostServer server, HttpListenerContext callcontext, string callbackEndPoint, CancellationToken cancel)
{
callcontext.Response.ContentEncoding = Encoding.UTF8;
callcontext.Finish(_content,_mime,_status);
}