public SFReturnCode ProcessRequest(HttpListenerContext context) { UrlHelper urlHelper = new UrlHelper(context.Request.Url); CommandResult parseResult = urlHelper.ParseResult; SFReturnCode result; if (urlHelper.ParseResult == CommandResult.Success) { try { this._scriptEngineer.ExecuteScript(urlHelper.ScriptName, urlHelper.Parameters); result = new SFReturnCode(1, EnumHelper.GetEnumDescription(CommandResult.Success)); return result; } catch (FileNotFoundException var_2_5D) { result = new SFReturnCode(5, EnumHelper.GetEnumDescription(CommandResult.NoExistsMethod)); return result; } catch (TimeoutException var_3_74) { result = new SFReturnCode(9, EnumHelper.GetEnumDescription(CommandResult.DoFunctionTooLongTimeProtect)); return result; } catch (SFReturnCode sFReturnCode) { result = sFReturnCode; return result; } catch (Exception var_5_96) { result = new SFReturnCode(7, EnumHelper.GetEnumDescription(CommandResult.ExcuteFunctionFailed)); return result; } } result = new SFReturnCode((int)parseResult, EnumHelper.GetEnumDescription(parseResult)); return result; }
private void ProcessHttpRequest(IAsyncResult iaServer) { HttpListener httpListener = iaServer.AsyncState as HttpListener; HttpListenerContext httpListenerContext = null; try { httpListenerContext = httpListener.EndGetContext(iaServer); Logger.Info("接收请求" + httpListenerContext.Request.Url.ToString()); if (this._isRuning) { Logger.Info("正在处理请求,已忽略请求" + httpListenerContext.Request.Url.ToString()); HttpServer.RetutnResponse(httpListenerContext, this._httpImplanter.CreateReturnResult(httpListenerContext, new SFReturnCode(8, EnumHelper.GetEnumDescription(CommandResult.ServerIsBusy)))); httpListener.BeginGetContext(new AsyncCallback(this.ProcessHttpRequest), httpListener); return; } this._isRuning = true; httpListener.BeginGetContext(new AsyncCallback(this.ProcessHttpRequest), httpListener); } catch { Logger.Warning("服务器已关闭!"); return; } string scriptName = new UrlHelper(httpListenerContext.Request.Url).ScriptName; SFReturnCode result = this._httpImplanter.ProcessRequest(httpListenerContext); byte[] resultBytes = this._httpImplanter.CreateReturnResult(httpListenerContext, result); HttpServer.RetutnResponse(httpListenerContext, resultBytes); GC.Collect(); this._isRuning = false; }