public override void Log(ExceptionLoggerContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            string errorMessage = context.Exception.Message;

            try
            {
                using (var stream = context.Request.Content.ReadAsStreamAsync().Result)
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(stream))
                    {
                        string data = reader.ReadToEnd();
                        errorMessage = data + "\n" + errorMessage;
                    }
                }
            }
            catch { }
            Exception exceptionToRaise = new HttpUnhandledException(errorMessage, context.Exception);

            // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
        /// <summary>
        /// Gets the closed achievements from http://steamcommunity.com/id/[customurl]/[game]/?xml=1.
        /// </summary>
        /// <param name="steamUserId">The steam user id.</param>
        /// <returns></returns>
        public ICollection <UserAchievement> GetAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            List <UserAchievement> achievements = new List <UserAchievement>();

            IEnumerable <Game> games = GetGames(steamUserId);

            foreach (Game game in games.Where(g => g.PlayedRecently))
            {
                Uri xmlStatsUrl = new Uri(game.StatsUrl + "/?xml=1", UriKind.Absolute);

                string xml = _webClient.DownloadString(xmlStatsUrl);

                if (xml == null)
                {
                    continue;
                }

                IEnumerable <UserAchievement> gameAchievements;
                try
                {
                    gameAchievements = _achievementParser.ParseClosed(xml);
                }
                catch (XmlException ex)
                {
                    // log and ignore invalid achievement xml
                    HttpContext context = HttpContext.Current;
                    if (context != null)
                    {
                        ErrorSignal signal = ErrorSignal.FromContext(context);
                        if (signal != null)
                        {
                            string    message   = String.Format("Invalid xml for {0} stats: {1}.", game.Name, game.StatsUrl);
                            Exception exception = new InvalidStatsXmlException(message, ex);
                            signal.Raise(exception);
                        }
                    }

                    continue;
                }

                if (!gameAchievements.Any())
                {
                    continue;
                }

                List <UserAchievement> achievementList = gameAchievements.ToList();
                Game game1 = game;
                achievementList.ForEach(a => a.Game = game1);

                achievements.AddRange(achievementList);
            }

            return(achievements);
        }
Beispiel #3
0
        public HttpResponseMessage Post(ErrorInputModel errorMessage)
        {
            ClientErrorException ex = new ClientErrorException(errorMessage.ToString());

            ErrorSignal signal = ErrorSignal.FromCurrentContext();

            signal.Raise(ex);

            return(Request.CreateResponse(HttpStatusCode.OK, "{success:true}"));
        }
Beispiel #4
0
        public override void Log(ExceptionLoggerContext context)
        {
            HttpContext httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }

            Exception exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);

            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the closed achievements from http://steamcommunity.com/id/[customurl]/statsfeed/[game]/?xml=1.
        /// </summary>
        /// <param name="steamUserId">The steam user id.</param>
        /// <returns></returns>
        public IEnumerable <Achievement> GetAchievements(string steamUserId)
        {
            if (steamUserId == null)
            {
                throw new ArgumentNullException("steamUserId");
            }

            List <Achievement> achievements = new List <Achievement>();

            IEnumerable <Game> games = GetGames(steamUserId);

            foreach (Game game in games.Where(g => g.PlayedRecently))
            {
                string statsUrl    = game.StatsUrl.ToString();
                string xmlStatsUrl = statsUrl + "/?xml=1";

                string xml = _webClient.DownloadString(xmlStatsUrl);

                IEnumerable <Achievement> gameAchievements;
                try
                {
                    gameAchievements = _achievementParser.ParseClosed(xml);
                }
                catch (XmlException ex)
                {
                    ErrorSignal signal = ErrorSignal.FromCurrentContext();
                    if (signal != null)
                    {
                        string    message   = "Invalid xml for " + game.Name + " stats: " + statsUrl;
                        Exception exception = new InvalidOperationException(message, ex);
                        signal.Raise(exception);
                    }

                    continue;
                }

                if (gameAchievements.Any())
                {
                    List <Achievement> achievementList = gameAchievements.ToList();
                    Game game1 = game;
                    achievementList.ForEach(a => a.Game = game1);

                    achievements.AddRange(achievementList);
                }
            }

            return(achievements);
        }
Beispiel #6
0
        public void SendMailMessage(QueuedMessage queuedMessage)
        {
            try
            {
                var mailMessage = BuildMailMessage(queuedMessage);

                _smtpClient.Send(mailMessage);
                queuedMessage.SentOn = DateTime.Now;
            }
            catch (Exception exception)
            {
                _errorSignal.Raise(exception);
                queuedMessage.Tries++;
            }
            _session.Transact(session => session.SaveOrUpdate(queuedMessage));
        }
        private static bool RaiseErrorSignal(Exception e)
        {
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return(false);
            }
            ErrorSignal signal = ErrorSignal.FromContext(context);

            if (signal == null)
            {
                return(false);
            }
            signal.Raise(e, context);
            return(true);
        }
        public override void Log(ExceptionLoggerContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = GetHttpContext(context.Request);

            if (httpContext == null)
            {
                return;
            }

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            Exception exceptionToRaise = new HttpUnhandledException(context.Exception.Message, context.Exception);

            // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
Beispiel #9
0
        private void Log(ExceptionContext context)
        {
            // Retrieve the current HttpContext instance for this request.
            HttpContext httpContext = context.HttpContext.ApplicationInstance.Context;

            if (httpContext == null)
            {
                return;
            }

            // Wrap the exception in an HttpUnhandledException so that ELMAH can capture the original error page.
            Exception exceptionToRaise = new HttpUnhandledException(message: null, innerException: context.Exception);

            // Send the exception to ELMAH (for logging, mailing, filtering, etc.).
            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            signal.Raise(exceptionToRaise, httpContext);
        }
        /// <summary>
        /// Tries the raise error signal.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private static bool TryRaiseErrorSignal(ExceptionContext context)
        {
            HttpContext httpContext = GetHttpContextImpl(context.HttpContext);

            if (httpContext == null)
            {
                return(false);
            }

            ErrorSignal signal = ErrorSignal.FromContext(httpContext);

            if (signal == null)
            {
                return(false);
            }

            signal.Raise(context.Exception, httpContext);
            return(true);
        }
        private bool TryRaiseErrorSignal(ExceptionContext context)
        {
            HttpContext httpContextImpl = GetHttpContextImpl(context.HttpContext);

            if (httpContextImpl == null)
            {
                return(false);
            }

            ErrorSignal errorSignal = ErrorSignal.FromContext(httpContextImpl);

            if (errorSignal == null)
            {
                return(false);
            }

            errorSignal.Raise(context.Exception.Demystify(), httpContextImpl);

            return(true);
        }
        public string DownloadString(Uri url)
        {
            try
            {
                return(_webClient.DownloadString(url));
            }
            catch (Exception ex)
            {
                HttpContext context = HttpContext.Current;
                if (context != null)
                {
                    ErrorSignal signal = ErrorSignal.FromContext(context);
                    if (signal != null)
                    {
                        string    message   = "Could not access url: " + url;
                        Exception exception = new InvalidOperationException(message, ex);
                        signal.Raise(exception);
                    }
                }

                return(null);
            }
        }
Beispiel #13
0
        public bool TestSettings(MailSettings settings, TestEmailInfo info)
        {
            try
            {
                using (var smtpClient = _getSmtpClient.GetClient(settings))
                {
                    var mailMessage = new MailMessage
                    {
                        From    = new MailAddress(settings.SystemEmailAddress),
                        Subject = "SMTP Test",
                        Body    = _resourceProvider.GetValue("Admin - Test Email - Content", "Testing email functionality from " + _site.DisplayName),
                    };
                    mailMessage.To.Add(new MailAddress(info.Email));

                    smtpClient.Send(mailMessage);
                }
                return(true);
            }
            catch (Exception ex)
            {
                _errorSignal.Raise(ex);
                return(false);
            }
        }
Beispiel #14
0
        private void ErrorReportingFailed(Exception e)
        {
            ErrorSignal signal = ErrorSignal.FromCurrentContext();

            signal.Raise(e);
        }