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


C# HttpListenerContext.Finish方法代码示例

本文整理汇总了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);
            }
	    }
开发者ID:Qorpent,项目名称:qorpent.integration,代码行数:28,代码来源:UsonHandler.cs

示例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();
				    }

				}
				
			}
		}
开发者ID:Qorpent,项目名称:qorpent.integration,代码行数:39,代码来源:StaticFileHandler.cs

示例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");
		}
开发者ID:Qorpent,项目名称:qorpent.integration,代码行数:53,代码来源:WikiHandler.cs

示例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");
				}
			}
		}
开发者ID:Qorpent,项目名称:qorpent.integration,代码行数:26,代码来源:UsonHandler.cs

示例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);
			}
		}
开发者ID:Qorpent,项目名称:qorpent.integration,代码行数:17,代码来源:UsonHandler.cs

示例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\"}");
		}
开发者ID:Qorpent,项目名称:qorpent.integration,代码行数:13,代码来源:UsonHandler.cs

示例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);
		}
开发者ID:Qorpent,项目名称:qorpent.integration,代码行数:12,代码来源:StaticHandler.cs


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