Пример #1
0
 public ErrorInfoException(ErrorInfo errorInfo)
 {
     try
       {
     ErrorInfo = errorInfo;
       }
       catch (Exception exception)
       {
     Log.Error(exception);
       }
 }
Пример #2
0
        public static string Execute(List<string> parameters)
        {
            try
              {
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            try
            {
              MethodInfo method = null;

              try
              {
            if (parameters == null || parameters.Count == 0)
            {
              throw new Exception("No arguments where found.");
            }

            if (parameters.Any(t => t == null))
            {
              throw new Exception("Input parameter 'parameters' contains null values.");
            }

            if (String.Equals(parameters[0], "Debug", StringComparison.CurrentCultureIgnoreCase))
            {
              System.Diagnostics.Debugger.Launch();

              parameters.RemoveAt(0);

              if (parameters.Count == 0)
              {
                throw new Exception("No arguments where found besides debug.");
              }
            }

            var methodType = MethodType.Unknown;

            if (!Enum.TryParse(parameters[0], out methodType))
            {
              throw new Exception("Input parameter 'args' does not contain a valid method ID {" + parameters[0] +
                                  "} at first position.");
            }

            foreach (MethodInfo t in Methods)
            {
              method = t;

              if (method.Type == methodType)
              {
                break;
              }

              method = null;
            }

            if (method == null)
            {
              throw new Exception("Input parameter 'args' specified method ID '" + (int)methodType +
                                  "' which was not found.");
            }

            parameters.RemoveAt(0);
              }
              catch (Exception exception)
              {
            Log.Error(exception, false);

            var errorInfo = new ErrorInfo(exception);

            errorInfo.AddDetail("Expected format:  MethodID  Parameter1  Parameter2  etc...");

            var builder = new StringBuilder();

            builder.Append(errorInfo);
            builder.AppendLine();
            builder.Append(GetMethodsAsString());

            return builder.ToString();
              }

              var stopWatch = new Log.Stopwatch();

              Log.StartPerformance(ref stopWatch, "Begin - Invoking method ID " + method.ID + " (" + method.Name + ")...");

              Log.Information("Received: " + parameters.Aggregate(method.Name, (current, t) => current + (" " + t)));
              try
              {
            if (OnExecute != null)
            {
              try
              {
                OnExecute();
              }
              catch
              {
              }
            }

            return method.Invoke(parameters.ToArray());
              }
              catch (Exception exception)
              {
            Log.Error(exception, false);

            var errorInfo = new ErrorInfo(exception);

            errorInfo.AddDetail("Attempted to Invoke method ID " + method.ID + " (" + method.Name + ")");

            var builder = new StringBuilder();

            builder.Append(errorInfo);

            return builder.ToString();
              }
              finally
              {
            Log.EndPerformance(ref stopWatch,
                               "End - Invoking method ID " + method.ID + " (" + method.Name + ")",
                               LogType.Warning);
              }
            }
            catch (Exception exception)
            {
              Log.Error(exception, false);

              var errorInfo = new ErrorInfo(exception);

              var builder = new StringBuilder();

              builder.Append(errorInfo);
              builder.AppendLine();
              builder.Append(GetMethodsAsString());

              return builder.ToString();
            }
            finally
            {
              System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception, false);

            var errorInfo = new ErrorInfo(exception);

            return errorInfo.ToString();
              }
        }
Пример #3
0
        public void Copy(ErrorInfo errorInfo)
        {
            try
              {
            _type = errorInfo.Type;
            _message = errorInfo.Message;

            for (int i = 0; i < errorInfo.Details.Count; i++)
            {
              DetailInfo detailInfo = errorInfo.Details[i].Copy();

              Details.Add(detailInfo);
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception);
              }
        }
Пример #4
0
        public static string Execute(string[] args)
        {
            try
              {
            var parameters = new List<string>();

            if (args != null)
            {
              for (int i = 0; i < args.Length; i++)
              {
            string arg = args[i];

            if (arg != null)
            {
              parameters.Add(arg);
            }
              }
            }

            return Execute(parameters);
              }
              catch (Exception exception)
              {
            Log.Error(exception, false);

            var errorInfo = new ErrorInfo(exception);

            return errorInfo.ToString();
              }
        }