/// <summary> /// Save settings from form to user's settings. /// </summary> private void SaveSettings() { // CiscoAgentExeFileLocation if (!File.Exists(this.txtCiscoExeLocation.Text)) { throw new ArgumentException("Cisco Application Name is missing.", "CiscoAgentProcessName"); } else { Settings.Default.CiscoAgentExeFileLocation = this.txtCiscoExeLocation.Text; } // ============ Idle Time ============== // Log out Agent when System is Idle Settings.Default.LogOutOnIdle = this.chkLogOutWhenIdle.Checked; Settings.Default.IdleMinsBeforeLoggingOut = (int)this.numLogOutWhenIdle.Value; // Log in after coming back from Idle Settings.Default.LogInAfterIdle = this.chkLogInAfterIdle.Checked; if (this.rdbIdleReady.Checked == true) { Settings.Default.LogInAfterIdleToStatus = AgentStatus.Ready; } else { Settings.Default.LogInAfterIdleToStatus = AgentStatus.NotReady; } // On screen lock, switch to Settings.Default.ChangeStatusOnScreenLock = this.chkScreenLock.Checked; if (this.rdbScreenLockLogOut.Checked == true) { Settings.Default.ChangeStatusOnScreenLockTo = AgentStatus.LoggedOut; } else { Settings.Default.ChangeStatusOnScreenLockTo = AgentStatus.NotReady; } // Log in after coming back from screen lock to Settings.Default.ChangeStatusOnScreenUnlock = this.chkScreenUnlock.Checked; if (this.rdbScreenUnlockReady.Checked == true) { Settings.Default.ChangeStatusOnScreenUnlockTo = AgentStatus.Ready; } else { Settings.Default.ChangeStatusOnScreenUnlockTo = AgentStatus.NotReady; } // ============ Startup & Shutdown ============== Settings.Default.LogInOnStartup = this.chkStartup.Checked; if (this.rdbStartupReady.Checked == true) { Settings.Default.LogInOnStartupTo = AgentStatus.Ready; } else { Settings.Default.LogInOnStartupTo = AgentStatus.NotReady; } Settings.Default.LogOutAndCloseAgentOnShutDown = this.chkShutdown.Checked; // CiscoPassword if (string.IsNullOrWhiteSpace(this.txtCiscoPassword.Text)) { throw new ArgumentException("Cisco Password is missing.", "CiscoPassword"); } else { Settings.Default.CiscoPassword = this.txtCiscoPassword.Text; SettingsForm.UpdateAhkScriptsWithPassword(this.txtCiscoPassword.Text); } // Save settings to file. Settings.Default.Save(); }
/// <summary> /// Validates stored settings and corrects them if their invalid. /// </summary> public static void ValidateStoredSettings() { // CiscoAgentExeFileLocation must exist if (!File.Exists(Settings.Default.CiscoAgentExeFileLocation)) { if (File.Exists(Resources.AgentExeLocation86)) { Settings.Default.CiscoAgentExeFileLocation = Resources.AgentExeLocation86; Settings.Default.Save(); } else { SettingsForm.ChooseCiscoApplicationLocation(); } } // IdleMinsBeforeLoggingOut can't be less than 1 if (Settings.Default.IdleMinsBeforeLoggingOut < 1) { Settings.Default.IdleMinsBeforeLoggingOut = 1; Settings.Default.Save(); } // LogInAfterIdleToStatus can't be outside NotReady or Ready if (Settings.Default.LogInAfterIdleToStatus != AgentStatus.Ready & Settings.Default.LogInAfterIdleToStatus != AgentStatus.NotReady) { Settings.Default.LogInAfterIdleToStatus = AgentStatus.NotReady; Settings.Default.Save(); } // ChangeStatusOnScreenLockTo can't be outside LogOut or NotReady if (Settings.Default.ChangeStatusOnScreenLockTo != AgentStatus.LoggedOut & Settings.Default.ChangeStatusOnScreenLockTo != AgentStatus.NotReady) { Settings.Default.ChangeStatusOnScreenLockTo = AgentStatus.NotReady; Settings.Default.Save(); } // ChangeStatusOnScreenUnlockTo can't be outside NotReady or Ready if (Settings.Default.ChangeStatusOnScreenUnlockTo != AgentStatus.Ready & Settings.Default.ChangeStatusOnScreenUnlockTo != AgentStatus.NotReady) { Settings.Default.ChangeStatusOnScreenUnlockTo = AgentStatus.NotReady; Settings.Default.Save(); } // LogInOnStartupTo can't be outside NotReady or Ready if (Settings.Default.LogInOnStartupTo != AgentStatus.Ready & Settings.Default.LogInOnStartupTo != AgentStatus.NotReady) { Settings.Default.LogInOnStartupTo = AgentStatus.NotReady; Settings.Default.Save(); } // CiscoPassword can't be empty if (String.IsNullOrWhiteSpace(Settings.Default.CiscoPassword)) { Settings.Default.CiscoPassword = "******"; Settings.Default.Save(); } }