public void ProcessRequest(HttpContext context) { try { string logPath = context.Server.MapPath("~/App_Data/AutoUpdate"); _log = new AutoUpdateLogger(logPath); IUnityContainer container = ContainerManager.Container; _manager = new AutoUpdateManager(container.Resolve <IAchievementService>(), container.Resolve <IUserService>(), container.Resolve <IFacebookPublisher>(), _log); bool authorized = context.Request["auth"] == Properties.Settings.Default.AutoUpdateAuthKey; if (!authorized) { _log.Log("Invalid auth key"); context.Response.Write("Invalid auth key"); } else { string method = context.Request["method"]; if (method == "GetAutoUpdateUsers") { _log.Log("Getting auto update users"); string users = _manager.GetAutoUpdateUsers(); _log.Log(users); _log.Flush(); context.Response.Write(users); } else if (method == "PublishUserAchievements") { string userName = context.Request["user"]; _manager.PublishUserAchievements(userName); _log.Flush(); context.Response.Write(userName + " published."); // delete logs more than two weeks old _log.Delete(DateTime.UtcNow.AddDays(-14).Date); } else { context.Response.Write("Invalid method"); } } } catch (Exception ex) { _log.Log(ex); _log.Write(context.Response); } finally { _manager.Dispose(); _log.Flush(); } }