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();
         }
     });
 }
Esempio n. 2
0
        public void AddAutoStart_AddsAndEnablesAutoStart(bool useGuid)
        {
            if (useGuid)
            {
                Service.AllHistoryAutoStarts.Add(AutoStartEntry);
                Service.AddAutoStart(Guid);
            }
            else
            {
                Service.AddAutoStart(AutoStartEntry);
            }

            Assert.AreEqual(ConfirmStatus.Reverted, AutoStartEntry.ConfirmStatus);
            A.CallTo(() => ConnectorService.EnableAutoStart(AutoStartEntry)).MustHaveHappenedOnceExactly();
            A.CallTo(() => ConnectorService.AddAutoStart(AutoStartEntry)).MustHaveHappenedOnceExactly();
        }
 /// <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);
 }