Пример #1
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());
            }
        }
Пример #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();
              }
        }