public EnvironmentConfig GetEnvironmentConfiguration(string environmentName)
 {
     try
     {
         EnvironmentConfig env;
         if (environmentCache.TryGetValue(environmentName, out env))
         {
             return(env);
         }
         if (ConfigSet.IsNull())
         {
             LoadConfigSet();
         }
         var envs = from e in ConfigSet.Environments where e.EnvironmentName == environmentName select e;
         env = envs.First();
         environmentCache.TryAdd(environmentName, env);
         return(env);
     }
     catch (Exception ex)
     {
         if (LastException != null)
         {
             LastException.Log();
         }
         throw new InvalidDataException(string.Format("Cannot find environment node with name = {0}", environmentName), LastException ?? ex);
     }
 }
Пример #2
0
        /// <inheritdoc />
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    await ActionAsync(stoppingToken).ConfigureAwait(false);

                    LogAndResetLastExceptionIfNotNull();
                }
                catch (Exception ex) when(ex is OperationCanceledException || ex is TaskCanceledException || ex is TimeoutException)
                {
                    Logger.LogTrace(ex);
                }
                catch (Exception ex)
                {
                    // Only log one type of exception once.
                    if (LastException is null ||                  // If the exception never came.
                        ex.GetType() != LastException.GetType() ||                         // Or the exception have different type from previous exception.
                        ex.Message != LastException.Message)                            // Or the exception have different message from previous exception.
                    {
                        // Then log and reset the last exception if another one came before.
                        LogAndResetLastExceptionIfNotNull();
                        // Set new exception and log it.
                        LastException = ex;
                        LastExceptionFirstAppeared = DateTimeOffset.UtcNow;
                        LastExceptionCount         = 1;
                        Logger.LogError(ex);
                    }
Пример #3
0
        private void CopyErrorToClipboard()
        {
            var log = LastException?.ToString();

            if (!string.IsNullOrEmpty(log))
            {
                SafeClipboard.SetText(log);
            }
        }
 public ConfigParameter GetComplexConfigurationParameters(string rootName)
 {
     try
     {
         var cp = from c in ConfigSet.Parameters where c.Name == rootName select c;
         return(cp.First());
     }
     catch (Exception ex)
     {
         if (LastException != null)
         {
             LastException.Log();
         }
         throw new InvalidDataException(string.Format("Cannot find Parameters node with name {0}", rootName), LastException ?? ex);
     }
 }
 public ServiceConfig GetServiceConfiguration(string serviceName)
 {
     try
     {
         ServiceConfig service;
         if (serviceCache.TryGetValue(serviceName, out service))
         {
             return(service);
         }
         var services = from s in ConfigSet.Services where s.ServiceName == serviceName select s;
         service = services.First();
         serviceCache.TryAdd(serviceName, service);
         return(service);
     }
     catch (Exception ex)
     {
         if (LastException != null)
         {
             LastException.Log();
         }
         throw new InvalidDataException(string.Format("Cannot find service node with name = {0}", serviceName), LastException ?? ex);
     }
 }
Пример #6
0
        /// <summary>
        /// Takes the parsed error information from the object properties and parses this information into a string,
        /// that can be displayed as plain text or in a browser. The string is formatted text and displays well
        /// in a browser using a PRE tag.
        ///
        /// Method also displays request information including:
        ///
        /// Full Url
        /// Refering Url
        /// IP Address of caller
        /// Client Browser
        /// Full POST buffer
        ///
        /// Full handling also returns:
        ///
        /// Stack Trace
        /// Source code blocks of the 5 lines before and after failure line if and/or debugging info is available
        /// <returns>Formatted Error string</returns>
        public override string ToString()
        {
            if (!IsParsed)
            {
                Parse();
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(ErrorMessage + "\r\n\r\n");

            sb.AppendLine("--- Base Error Info ---");
            sb.AppendLine("Exception: " + LastException.GetType().Name);
            sb.AppendFormat("      Url: {0}\r\n", RawUrl);
            sb.AppendFormat("     Time: {0}\r\n", DateTime.Now.ToString("MMM dd, yyyy  HH:mm"));


            if (CompactFormat)
            {
                return(sb.ToString());
            }


            if (!string.IsNullOrEmpty(SourceCode))
            {
                sb.AppendLine("\r\n--- Code ---");
                sb.Append(SourceCode);
            }

            if (!string.IsNullOrEmpty(StackTrace))
            {
                sb.AppendFormat("\r\n--- Stack Trace ---\r\n{0}\r\n\r\n", StackTrace);
            }

            sb.Append("\r\n--- Request Information ---\r\n");
            sb.AppendFormat("  Full Url: {0}\r\n", FullUrl);
            sb.AppendFormat(" Client IP: {0}\r\n", IPAddress);

            if (!string.IsNullOrEmpty(Referer))
            {
                sb.AppendFormat("   Referer: {0}\r\n", Referer);
            }

            sb.AppendFormat("   Browser: {0}\r\n", Browser);
            sb.AppendFormat("     Login: {0}\r\n", Login);
            sb.AppendFormat("    Locale: {0}\r\n", Locale);
            sb.AppendFormat("    Status: {0}\r\n", OriginalHttpStatusCode);

            if (!string.IsNullOrEmpty(PostBuffer))
            {
                sb.AppendFormat("\r\n\r\n--- Raw Post Buffer ---\r\n\r\n{0}", PostBuffer);
            }


            if (!string.IsNullOrEmpty(ServerVariables))
            {
                sb.AppendFormat("\r\n\r\n--- All Server Variables ---\r\n\r\n{0}", ServerVariables);
            }

            return(sb.ToString());
        }
Пример #7
0
        protected override void OnInitialized()
        {
            ExceptionHandlerBuilder.Handler(e =>
            {
                bool isSkipped     = false;
                Type exceptionType = e.GetType();
                foreach (Type type in SkippedExceptions)
                {
                    if (type.IsAssignableFrom(exceptionType))
                    {
                        isSkipped = true;
                        break;
                    }
                }

                if (!isSkipped)
                {
                    LastException = e;

                    if (e is Neptuo.Models.AggregateRootException)
                    {
                        string message = null;

                        if (e is CurrencyAlreadyAsDefaultException)
                        {
                            message = MessageBuilder.CurrencyAlreadyAsDefault();
                        }
                        else if (e is CurrencyAlreadyExistsException)
                        {
                            message = MessageBuilder.CurrencyAlreadyExists();
                        }
                        else if (e is CurrencyDoesNotExistException)
                        {
                            message = MessageBuilder.CurrencyDoesNotExist();
                        }
                        else if (e is CurrencyExchangeRateDoesNotExistException)
                        {
                            message = MessageBuilder.CurrencyExchangeRateDoesNotExist();
                        }
                        else if (e is OutcomeAlreadyDeletedException)
                        {
                            message = MessageBuilder.OutcomeAlreadyDeleted();
                        }
                        else if (e is OutcomeAlreadyHasCategoryException)
                        {
                            message = MessageBuilder.OutcomeAlreadyHasCategory();
                        }
                        else if (e is CantDeleteDefaultCurrencyException)
                        {
                            message = MessageBuilder.CantDeleteDefaultCurrency();
                        }
                        else if (e is CantDeleteLastCurrencyException)
                        {
                            message = MessageBuilder.CantDeleteLastCurrency();
                        }
                        else if (e is DemoUserCantBeChangedException)
                        {
                            message = MessageBuilder.DemoUserCantBeChanged();
                        }
                        else if (e is PasswordChangeFailedException passwordChangeFailed)
                        {
                            message = MessageBuilder.PasswordChangeFailed(passwordChangeFailed.ErrorDescription);
                        }
                        else if (e is EmailChangeFailedException)
                        {
                            message = MessageBuilder.EmailChangeFailed();
                        }

                        Message = message;
                    }
                    else if (e is ServerNotRespondingException)
                    {
                        Message = MessageBuilder.ServerNotResponding();
                    }
                    else if (e is InternalServerException)
                    {
                        Message = MessageBuilder.InternalServerError();
                    }
                }

                if (isSkipped)
                {
                    Title         = null;
                    Message       = null;
                    LastException = null;
                }
                else if (Message == null)
                {
                    Title   = LastException.GetType().FullName;
                    Message = LastException.Message;
                }
                else
                {
                    Title = null;
                }

                StateHasChanged();
            });

            base.OnInitialized();
        }