コード例 #1
0
        /// <summary>
        /// Agent Monitor default constructor.
        /// </summary>
        public AgentMonitor()
        {
            // Initialize form's components.
            InitializeComponent();

            // Validate stored settings
            SettingsForm.ValidateStoredSettings();

            // This fixes a bug
            // When the application is updated, the script files are overwritten with new version.
            // The new version of the file has [PASSCODE] not the password even though the user hasn't changed the password.
            SettingsForm.UpdateAhkScriptsWithPassword(Settings.Default.CiscoPassword);

            // Set initial agent status
            this.Status = AgentStatus.Undetermined;

            // Create a simple tray menu.
            this.TrayMenu = new ContextMenu();
            this.TrayMenu.MenuItems.Add("Ready", TrayMenu_Ready);
            this.TrayMenu.MenuItems.Add("Not Ready", TrayMenu_NotReady);
            this.TrayMenu.MenuItems.Add("Log out", TrayMenu_LogOut);
            this.TrayMenu.MenuItems.Add("Close Agent", TrayMenu_CloseAgent);
            this.TrayMenu.MenuItems.Add("-");
            this.TrayMenu.MenuItems.Add("Restore", TrayIcon_OnRestore);
            this.TrayMenu.MenuItems.Add("Exit", TrayIcon_OnExit);

            // Create tray icon.
            this.TrayIcon                    = new NotifyIcon();
            this.TrayIcon.Text               = "Agent Helper";
            this.TrayIcon.ContextMenu        = TrayMenu;
            this.TrayIcon.Visible            = true;
            this.TrayIcon.BalloonTipClicked += TrayIcon_BalloonTipClicked;
            this.TrayIcon.DoubleClick       += TrayIcon_DoubleClick;

            // Set up Idle monitoring
            this.SetupIdleMonitoring();

            // Set up monitoring of agent status every 1 second.
            this.StatusTimer          = new Timer();
            this.StatusTimer.Interval = 1000;
            this.StatusTimer.Tick    += StatusTimer_Tick;

            // Detect status for the first time
            this.DetectAgentStatus();

            // Hook up form's event handlers
            this.Resize      += AgentMonitor_Resize;
            this.FormClosing += AgentMonitor_FormClosing;
            this.FormClosed  += AgentMonitor_FormClosed;

            // Settings button
            this.btnSettings.Click += btnSettings_Click;

            // About button
            this.lnkAbout.Click += lnkAbout_Click;

            // Set up watch for screen lock
            SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);

            // Records
            this.Records               = new List <AgentStatusChangeEventArgs>();
            this.AgentStatusChange    += AgentMonitor_AgentStatusChange;
            this.lnkShowRecords.Click += lnkShowRecords_Click;

            // Change status if User indicates that in Settings
            if (Settings.Default.LogInOnStartup)
            {
                if (Settings.Default.LogInOnStartupTo == AgentStatus.NotReady)
                {
                    this.SwitchToNotReady();
                }
                else if (Settings.Default.LogInOnStartupTo == AgentStatus.Ready)
                {
                    this.SwitchToReady();
                }
            }

            // Start monitoring status
            this.StatusTimer.Start();
        }
コード例 #2
0
ファイル: SettingsForm.cs プロジェクト: AmrEldib/AgentHelper
        /// <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();
        }