Esempio n. 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());
            }
        }
Esempio n. 2
0
            public bool RefreshIfTimedOut(bool startBackgroundProcesses)
            {
                try
                {
                  var stopWatch = new Log.Stopwatch();

                  if (IsSignedIn)
                  {
                try
                {
                  if (_refreshDateTime > DateTime.Now)
                  {
                return true;
                  }

                  Log.StartPerformance(ref stopWatch, "Begin - Google.Apis.Authentication.RefreshToken");

                  bool timedOut = Authenticator.HasTimedOut();

                  Log.EndPerformance(ref stopWatch, "End - Google.Apis.Authentication.RefreshToken");

                  if (!timedOut)
                  {
                _refreshDateTime = DateTime.Now.AddSeconds(15);

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

                  IsSignedIn = false;

                  _service = null;

                  Log.StartPerformance(ref stopWatch, "Begin - Google.Apis.Authentication.Auth");

                  string tokenFilePath = GetRegistryEntryTokenFilePath();

                  if (String.IsNullOrEmpty(tokenFilePath))
                  {
                tokenFilePath = Settings.TokenNewFilePath;
                  }

                  _service = Authenticator.Init(
                                        Settings.Product,
                                        Settings.ClientID,
                                        Settings.ClientSecret,
                                        new[] {Google.Apis.Drive.v2.DriveService.Scope.Drive},
                                        SignedOut,
                                        tokenFilePath);

                  Log.EndPerformance(ref stopWatch, "End - Google.Apis.Authentication.Auth");

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

                  _refreshDateTime = DateTime.Now.AddSeconds(15);

                  IsSignedIn = true;
                  SignedOut = false;

                  UpdateRegistryEntries(tokenFilePath);

                  if (startBackgroundProcesses || AutoStartBackgroundProcesses)
                  {
                DriveService.StartBackgroundProcesses();
                  }

                  return true;
                }
                catch (Exception exception)
                {
                  Log.Error(exception);

                  return false;
                }
            }
Esempio n. 3
0
            public bool RefreshIfTimedOut(bool startBackgroundProcesses)
            {
                try
                {
                    var stopWatch = new Log.Stopwatch();

                    if (IsSignedIn)
                    {
                        try
                        {
                            if (_refreshDateTime > DateTime.Now)
                            {
                                return(true);
                            }

                            Log.StartPerformance(ref stopWatch, "Begin - Google.Apis.Authentication.RefreshToken");

                            bool timedOut = Authenticator.HasTimedOut();

                            Log.EndPerformance(ref stopWatch, "End - Google.Apis.Authentication.RefreshToken");

                            if (!timedOut)
                            {
                                _refreshDateTime = DateTime.Now.AddSeconds(15);

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

                    IsSignedIn = false;

                    _service = null;

                    Log.StartPerformance(ref stopWatch, "Begin - Google.Apis.Authentication.Auth");

                    string tokenFilePath = GetRegistryEntryTokenFilePath();

                    if (String.IsNullOrEmpty(tokenFilePath))
                    {
                        tokenFilePath = Settings.TokenNewFilePath;
                    }

                    _service = Authenticator.Init(
                        Settings.Product,
                        Settings.ClientID,
                        Settings.ClientSecret,
                        new[] { Google.Apis.Drive.v2.DriveService.Scope.Drive },
                        SignedOut,
                        tokenFilePath);

                    Log.EndPerformance(ref stopWatch, "End - Google.Apis.Authentication.Auth");

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

                    _refreshDateTime = DateTime.Now.AddSeconds(15);

                    IsSignedIn = true;
                    SignedOut  = false;

                    UpdateRegistryEntries(tokenFilePath);

                    if (startBackgroundProcesses || AutoStartBackgroundProcesses)
                    {
                        DriveService.StartBackgroundProcesses();
                    }

                    return(true);
                }
                catch (Exception exception)
                {
                    Log.Error(exception);

                    return(false);
                }
            }
Esempio n. 4
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();
              }
        }