public override void Process() { string simp = Req.Params["simp"]; if (simp == null) { throw new ApiException(400, "Missing 'simp' parameter."); } string trad = Req.Params["trad"]; if (trad == null) { throw new ApiException(400, "Missing 'trad' parameter."); } string pinyin = Req.Params["pinyin"]; if (pinyin == null) { throw new ApiException(400, "Missing 'pinyin' parameter."); } string trg = Req.Params["trg"]; if (trg == null) { throw new ApiException(400, "Missing 'trg' parameter."); } string note = Req.Params["note"]; if (note == null) { throw new ApiException(400, "Missing 'note' parameter."); } Result res = new Result { Success = true }; SqlDict.SimpleBuilder builder = null; try { builder = new SqlDict.SimpleBuilder(0); CedictEntry entry = SqlDict.BuildEntry(simp, trad, pinyin, trg); builder.NewEntry(entry, note); } catch (Exception ex) { DiagLogger.LogError(ex); res.Success = false; } finally { if (builder != null) { builder.Dispose(); } } // Tell our caller Res = res; }
void Application_Error(object sender, EventArgs e) { HttpContext context = HttpContext.Current; DiagLogger.LogError("Unhandled exception; details follow in next entry"); Exception ex = context.Server.GetLastError().GetBaseException(); DiagLogger.LogError(ex); }
/// <summary> /// Pre-processes scripts from DB.Scripts.txt. /// Builds and stores connection string from site config. /// </summary> static DB() { try { init(out connectionString); } catch (Exception ex) { DiagLogger.LogError(ex); throw; } }
/// <summary> /// Processes the request. /// </summary> public void ProcessRequest(HttpContext context) { try { // Get our action. Throws 4XX errors if need be. // 400: Bad request // 403: Forbidden (when calling stuff without prior authentication; also on failed login). ApiAction action = ApiAction.CreateAction(context); // Process the request. Throws whatever if things go south. // 4XX // 500: Internal server error. action.Process(); // Writes 200 response to stream. Shouldn't throw. action.SendResponse(); } catch (ApiException ex) { #if DEBUG context.Response.AddHeader("Access-Control-Allow-Origin", "*"); context.Response.AddHeader("Access-Control-Allow-Headers", "*"); context.Response.AddHeader("Access-Control-Allow-Credentials", "true"); #endif context.Response.ContentType = "text/plain"; context.Response.StatusCode = ex.StatusCode; context.Response.Charset = "utf-8"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(ex.Message); context.Response.Flush(); } catch (Exception ex) { DiagLogger.LogError(ex); #if DEBUG context.Response.AddHeader("Access-Control-Allow-Origin", "*"); context.Response.AddHeader("Access-Control-Allow-Headers", "*"); context.Response.AddHeader("Access-Control-Allow-Credentials", "true"); #endif context.Response.ContentType = "text/plain"; context.Response.StatusCode = 500; context.Response.Charset = "utf-8"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write("Internal server error."); context.Response.Flush(); } }