Esempio n. 1
0
        public void Delete()
        {
            AutoUpdateLogger log = new AutoUpdateLogger("log");

            log.Delete(new DateTime(2011, 1, 2));

            // make sure the file named 2011-1-1.log was deleted and 2011-1-2.log remains.
            string[] files = Directory.GetFiles("log");
            Assert.That(files.Length, Is.EqualTo(1));
            Assert.That(Path.GetFileName(files[0]), Is.EqualTo("2011-1-2.log"));
        }
Esempio n. 2
0
        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();
            }
        }