Пример #1
0
 public void Disable(AutoStartEntry autoStart)
 {
     Task.Run(() => {
         Logger.Info("Should disable {@autoStart}", autoStart);
         try {
             AppStatus.IncrementRunningActionCount();
             if (!MessageService.ShowConfirm("Confirm disable", $"Are you sure you want to disable auto start \"{autoStart.Value}\"?"))
             {
                 return;
             }
             if (AutoStartService.IsAdminRequiredForChanges(autoStart))
             {
                 StartSubProcessAsAdmin(autoStart, DisableParameterName);
                 autoStart.ConfirmStatus = ConfirmStatus.Disabled;
             }
             else
             {
                 AutoStartService.DisableAutoStart(autoStart);
             }
             MessageService.ShowSuccess("Auto start disabled", $"\"{autoStart.Value}\" has been disabled.");
         } catch (Exception e) {
             var message = "Failed to disable";
             var err     = new Exception(message, e);
             Logger.Error(err);
             MessageService.ShowError(message, e);
         } finally {
             AppStatus.DecrementRunningActionCount();
         }
     });
 }
Пример #2
0
 public void RevertRemove(AutoStartEntry autoStart)
 {
     Task.Run(() => {
         Logger.Info("Should remove {@autoStart}", autoStart);
         try {
             AppStatus.IncrementRunningActionCount();
             if (!MessageService.ShowConfirm("Confirm add", $"Are you sure you want to add \"{autoStart.Value}\" as auto start?"))
             {
                 return;
             }
             if (AutoStartService.IsAdminRequiredForChanges(autoStart))
             {
                 StartSubProcessAsAdmin(autoStart, RevertRemoveParameterName);
                 autoStart.ConfirmStatus = ConfirmStatus.Reverted;
             }
             else
             {
                 AutoStartService.AddAutoStart(autoStart);
             }
             MessageService.ShowSuccess("Auto start added", $"\"{autoStart.Value}\" has been added to auto starts.");
         } catch (Exception e) {
             var message = "Failed to revert remove";
             var err     = new Exception(message, e);
             Logger.Error(err);
             MessageService.ShowError(message, e);
         } finally {
             AppStatus.DecrementRunningActionCount();
         }
     });
 }
Пример #3
0
        public void Start(bool skipInitializing = false)
        {
            // disable notifications for new added auto starts on first start to avoid too many notifications at once
            bool isFirstRun = !AutoStartService.GetValidAutoStartFileExists();

            if (!isFirstRun)
            {
                AutoStartService.Add     += AddHandler;
                AutoStartService.Remove  += RemoveHandler;
                AutoStartService.Enable  += EnableHandler;
                AutoStartService.Disable += DisableHandler;
            }

            try {
                AutoStartService.LoadCurrentAutoStarts();
                AppStatus.HasOwnAutoStart = AutoStartService.HasOwnAutoStart;
            } catch (Exception) {
            }

            if (isFirstRun)
            {
                AutoStartService.Add     += AddHandler;
                AutoStartService.Remove  += RemoveHandler;
                AutoStartService.Enable  += EnableHandler;
                AutoStartService.Disable += DisableHandler;
            }
            AutoStartService.StartWatcher();

            if (!skipInitializing)
            {
                InitializeComponent();
            }
        }
Пример #4
0
 private void RemoveHandler(AutoStartEntry removedAutostart)
 {
     Logger.Trace("RemoveHandler called");
     if (AutoStartService.IsOwnAutoStart(removedAutostart))
     {
         Logger.Info("Own auto start removed");
         AppStatus.HasOwnAutoStart = false;
     }
     NotificationService.ShowRemovedAutoStartEntryNotification(removedAutostart);
 }
Пример #5
0
 private void AddHandler(AutoStartEntry addedAutostart)
 {
     Logger.Trace("AddHandler called");
     if (AutoStartService.IsOwnAutoStart(addedAutostart))
     {
         Logger.Info("Own auto start added");
         AppStatus.HasOwnAutoStart = true;
     }
     NotificationService.ShowNewAutoStartEntryNotification(addedAutostart);
 }
Пример #6
0
 protected override void OnExit(ExitEventArgs e)
 {
     try {
         AutoStartService.SaveAutoStarts();
     } finally {
         try {
             Icon.Dispose();
         } catch (Exception) {
         }
         base.OnExit(e);
     }
 }
        public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var autoStart = (AutoStartEntry)value[0];

            if (autoStart.CanBeDisabled.HasValue)
            {
                return(autoStart.CanBeDisabled.Value);
            }
            Task.Run(() => {
                AutoStartService.LoadCanBeDisabled(autoStart);
            });
            return(false);
        }
Пример #8
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             if (AutoStartService != null)
             {
                 AutoStartService.Dispose();
             }
         }
         disposedValue = true;
     }
 }
Пример #9
0
 public void RevertRemove(Guid id)
 {
     Logger.Info("Removal of {id} should be reverted", id);
     if (AutoStartService.TryGetHistoryAutoStart(id, out AutoStartEntry autoStart))
     {
         RevertRemove(autoStart);
     }
     else
     {
         var message = "Failed to get auto start to add";
         Logger.Error(message);
         MessageService.ShowError(message);
     }
 }
Пример #10
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var autoStart = (AutoStartEntry)values[0];

            switch (autoStart.Change)
            {
            case Change.Added:
                if (autoStart.CanBeRemoved.HasValue)
                {
                    return(autoStart.CanBeRemoved.Value);
                }
                Task.Run(() => {
                    AutoStartService.LoadCanBeRemoved(autoStart);
                });
                break;

            case Change.Removed:
                if (autoStart.CanBeAdded.HasValue)
                {
                    return(autoStart.CanBeAdded.Value);
                }
                Task.Run(() => {
                    AutoStartService.LoadCanBeAdded(autoStart);
                });
                break;

            case Change.Enabled:
                if (autoStart.CanBeDisabled.HasValue)
                {
                    return(autoStart.CanBeDisabled.Value);
                }
                Task.Run(() => {
                    AutoStartService.LoadCanBeDisabled(autoStart);
                });
                break;

            case Change.Disabled:
                if (autoStart.CanBeEnabled.HasValue)
                {
                    return(autoStart.CanBeEnabled.Value);
                }
                Task.Run(() => {
                    AutoStartService.LoadCanBeEnabled(autoStart);
                });
                break;
            }
            return(false);
        }
Пример #11
0
 public void Disable(Guid id)
 {
     Task.Run(() => {
         Logger.Info("{id} should be disabled", id);
         if (AutoStartService.TryGetCurrentAutoStart(id, out AutoStartEntry autoStart))
         {
             Disable(autoStart);
         }
         else
         {
             var message = "Failed to get auto start to disable";
             Logger.Error(message);
             MessageService.ShowError(message);
         }
     });
 }
Пример #12
0
 public Task ToggleOwnAutoStart()
 {
     return(Task.Run(() => {
         try {
             AppStatus.IncrementRunningActionCount();
             AutoStartService.ToggleOwnAutoStart();
         } catch (Exception e) {
             var message = "Failed to change own auto start";
             var err = new Exception(message, e);
             Logger.Error(err);
             MessageService.ShowError(message, e);
         } finally {
             AppStatus.DecrementRunningActionCount();
         }
     }));
 }
Пример #13
0
 public void ConfirmRemove(AutoStartEntry autoStart)
 {
     Task.Run(() => {
         try {
             AppStatus.IncrementRunningActionCount();
             Logger.Trace("ConfirmRemove called");
             AutoStartService.ConfirmRemove(autoStart);
         } catch (Exception e) {
             var message = $"Failed to confirm remove of {autoStart}";
             var err     = new Exception(message, e);
             Logger.Error(err);
             MessageService.ShowError(message, e);
         } finally {
             AppStatus.DecrementRunningActionCount();
         }
     });
 }
Пример #14
0
 public void ConfirmAdd(Guid id)
 {
     Task.Run(() => {
         try {
             AppStatus.IncrementRunningActionCount();
             Logger.Trace("ConfirmAdd called");
             AutoStartService.ConfirmAdd(id);
         } catch (Exception e) {
             var message = $"Failed to confirm add of {id}";
             var err     = new Exception(message, e);
             Logger.Error(err);
             MessageService.ShowError(message, e);
         } finally {
             AppStatus.DecrementRunningActionCount();
         }
     });
 }
Пример #15
0
 /// <summary>
 /// Handles auto starts if command line parameters are set
 /// </summary>
 /// <param name="args">Command line parameters</param>
 /// <returns>True, if parameters were set, correctly handled and the program can be closed</returns>
 private bool HandleCommandLineParameters(string[] args)
 {
     for (int i = 0; i < args.Length; i++)
     {
         var arg = args[i];
         if (string.Equals(arg, RevertAddParameterName, StringComparison.OrdinalIgnoreCase))
         {
             Logger.Info("Adding should be reverted");
             AutoStartEntry autoStartEntry = LoadAutoStartFromParameter(args, i);
             AutoStartService.RemoveAutoStart(autoStartEntry);
             Logger.Info("Finished");
             return(true);
         }
         else if (string.Equals(arg, RevertRemoveParameterName, StringComparison.OrdinalIgnoreCase))
         {
             Logger.Info("Removing should be reverted");
             AutoStartEntry autoStartEntry = LoadAutoStartFromParameter(args, i);
             AutoStartService.AddAutoStart(autoStartEntry);
             Logger.Info("Finished");
             return(true);
         }
         else if (string.Equals(arg, EnableParameterName, StringComparison.OrdinalIgnoreCase))
         {
             Logger.Info("Auto start should be enabled");
             AutoStartEntry autoStartEntry = LoadAutoStartFromParameter(args, i);
             AutoStartService.EnableAutoStart(autoStartEntry);
             Logger.Info("Finished");
             return(true);
         }
         else if (string.Equals(arg, DisableParameterName, StringComparison.OrdinalIgnoreCase))
         {
             Logger.Info("Auto start should be disabled");
             AutoStartEntry autoStartEntry = LoadAutoStartFromParameter(args, i);
             AutoStartService.DisableAutoStart(autoStartEntry);
             Logger.Info("Finished");
             return(true);
         }
     }
     return(false);
 }