Esempio n. 1
0
        private void OnShowHddLoadsCallback(object state)
        {
            if (string.IsNullOrEmpty(this.currentSelectedHdd))
            {
                return;
            }

            var  hddLoad = string.Empty;
            bool allHdds = false;

            allHdds = this.currentSelectedHdd == WsapmTools.GetCommonDiaplayNameAllDrives();

            try
            {
                if (allHdds)
                {
                    hddLoad = WsapmConvert.ConvertByteToKB(this.hddLoad.GetCurrentHddLoadTotalAllHdds()).ToString("0.00") + " KB/s";
                }
                else
                {
                    hddLoad = WsapmConvert.ConvertByteToKB(this.hddLoad.GetCurrentHddLoadInBytesPerSecond(this.currentSelectedHdd)).ToString("0.00") + " KB/s";
                }
            }
            catch (Exception)
            {
            }

            Dispatcher.Invoke((Action)(() =>
            {
                this.labelCurrentHddLoad.Content = hddLoad;
            }));
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of ServiceLog.
 /// </summary>
 /// <param name="logMode">The LogMode defining the level of detail of the log.</param>
 /// <param name="maxFileSize">The max file size in byte.</param>
 internal WsapmLog(LogMode logMode, uint maxFileSize)
 {
     this.settingsFolder = WsapmTools.GetCommonApplicationDataFolder();
     this.logFile        = WsapmTools.GetCommonApplicationLogFile();
     this.LogMode        = logMode;
     this.MaxLogFileSize = maxFileSize;
 }
Esempio n. 3
0
        /// <summary>
        /// Writes a line to the log file.
        /// This action is not dependent of the LogMode.
        /// </summary>
        /// <param name="msg">The message to write in the log.</param>
        /// <remarks>This function is thread save.</remarks>
        private void WriteLine(string msg)
        {
            FileStream   fStream = null;
            StreamWriter writer  = null;

            try
            {
                lock (lockObj)
                {
                    if (!Directory.Exists(this.settingsFolder))
                    {
                        Directory.CreateDirectory(this.settingsFolder);
                    }

                    if (!File.Exists(this.logFile))
                    {
                        fStream = new FileStream(this.logFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                    }
                    else
                    {
                        if (this.MaxLogFileSize != 0)
                        {
                            FileInfo fi = new FileInfo(this.logFile);
                            var      currentFileSize = fi.Length;

                            if (currentFileSize > this.MaxLogFileSize)
                            {
                                File.Delete(this.logFile);
                                fStream = new FileStream(this.logFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                            }
                        }
                    }

                    writer = new StreamWriter(this.logFile, true);
                    writer.WriteLine(WsapmTools.GetTimeString() + ": " + msg);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (writer != null)
                {
                    writer.Flush();
                    writer.Close();
                    writer = null;
                }

                if (fStream != null)
                {
                    fStream.Flush();
                    fStream.Close();
                    fStream = null;
                }
            }
        }
Esempio n. 4
0
        public AddNetworkInterfaceWindow(NetworkInterfaceToMonitor[] allNetworkInterfaces)
        {
            InitializeComponent();

            this.allNetworkInterfaces = allNetworkInterfaces;

            var nics = WsapmTools.GetAvailableNetworkInterfaces();

            foreach (var nic in nics)
            {
                this.comboBoxAvailableNetworkInterfaces.Items.Add(nic);
            }

            this.comboBoxAvailableNetworkInterfaces.Items.Add(WsapmTools.GetCommonDiaplayNameAllNetworkInterfaces());

            this.networkLoad      = new NetworkLoadCurrent();
            this.networkLoadTimer = null;
            this.networkLoadTimer = new Timer(OnShowNetworkLoadsCallback, null, new TimeSpan(), this.displayRefreshInterval);
        }
Esempio n. 5
0
        public AddHddWindow(HddToMonitor[] allDrives)
        {
            InitializeComponent();

            this.allDrives = allDrives;

            var hdds = WsapmTools.GetAvailableLogicalVolumeNames();

            foreach (var hdd in hdds)
            {
                this.comboBoxAvailableDrives.Items.Add(hdd);
            }

            this.comboBoxAvailableDrives.Items.Add(WsapmTools.GetCommonDiaplayNameAllDrives());

            this.hddLoad      = new HddLoadCurrent();
            this.hddLoadTimer = null;
            this.hddLoadTimer = new Timer(OnShowHddLoadsCallback, null, new TimeSpan(), this.displayRefreshInterval);
        }
Esempio n. 6
0
        public MainWindow()
        {
            if (AlreadyRunning())
            {
                MessageBox.Show(Wsapm.Resources.Wsapm.MainWindow_AppAlreadyRunning, Wsapm.Resources.Wsapm.MainWindow_Title, MessageBoxButton.OK, MessageBoxImage.Information);
                App.Current.Shutdown();
                return;
            }

            ParseArgs();

            try
            {
                this.settingsLock           = new object();
                this.logManager             = new LogManager(WsapmTools.GetCommonApplicationDataFolder(), WsapmConstants.WsapmApplicationLogFile);
                this.logManager.LogChanged += logManager_LogChanged;

                InitializeComponent();

                this.serviceManager  = new ServiceManager();
                this.settingsManager = new SettingsManager();

                lock (this.settingsLock)
                {
                    this.currentSettings = this.settingsManager.LoadSettings();
                }

                this.logManager.Start();

                if (this.textBoxLog != null && this.scrollViewerLog != null)
                {
                    this.textBoxLog.Text = this.logManager.Log; // Load current log manually for the first time.
                    this.scrollViewerLog.ScrollToEnd();
                }

                this.temporaryUptimeManager = new TemporaryUptimeManager();
            }
            catch (Exception ex)
            {
                UnhandledExceptionManager.HandleException(ex);
            }
        }
Esempio n. 7
0
        public static ActionResult RemoveApplicationDataFolder(Session session)
        {
            session.Log("Begin RemoveApplicationDataFolder");

            try
            {
                string applicationDataFolder = WsapmTools.GetCommonApplicationDataFolder();

                if (Directory.Exists(applicationDataFolder))
                {
                    Directory.Delete(applicationDataFolder, true);
                }
            }
            catch (Exception ex)
            {
                session.Log("Failed to remove application data folder: " + ex.Message);
                return(ActionResult.Failure);
            }

            return(ActionResult.Success);
        }
Esempio n. 8
0
        private void OnShowNetworkLoadsCallback(object state)
        {
            if (string.IsNullOrEmpty(this.currentSelectedNic))
            {
                return;
            }

            var  loadTotal    = string.Empty;
            var  loadSent     = string.Empty;
            var  loadReceived = string.Empty;
            bool allNics      = false;

            allNics = this.currentSelectedNic == WsapmTools.GetCommonDiaplayNameAllNetworkInterfaces();

            try
            {
                if (allNics)
                {
                    loadTotal    = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadTotalAllNics()).ToString("0.00") + " KBit/s";
                    loadSent     = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadUploadAllNics()).ToString("0.00") + " KBit/s";
                    loadReceived = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadDownloadAllNics()).ToString("0.00") + " KBit/s";
                }
                else
                {
                    loadTotal    = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadTotal(this.currentSelectedNic)).ToString("0.00") + " KBit/s";
                    loadSent     = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadUpload(this.currentSelectedNic)).ToString("0.00") + " KBit/s";
                    loadReceived = WsapmConvert.ConvertByteToKBit(this.networkLoad.GetCurrentNetworkLoadDownload(this.currentSelectedNic)).ToString("0.00") + " KBit/s";
                }
            }
            catch (Exception)
            {
            }

            Dispatcher.Invoke((Action)(() =>
            {
                this.labelCurrentNetworkLoadReceived.Content = loadReceived;
                this.labelCurrentNetworkLoadSent.Content = loadSent;
                this.labelCurrentNetworkLoadTotal.Content = loadTotal;
            }));
        }
Esempio n. 9
0
        /// <summary>
        /// Handles the contents of the status panel (depending if service is running, validation errors, etc.).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void workerStatusPanelStatus_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!this.serviceManager.ServiceInstalled)
            {
                Dispatcher.Invoke((Action)(() => this.statusPanelService.Status = Wsapm.Wpf.Controls.StatusPanel.StatusPanelStatus.Error));
                Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = Wsapm.Resources.Wsapm.MainWindow_StatusPanelStatusServiceNotInstalled));
                Dispatcher.Invoke((Action)(() => this.linkStartService.IsEnabled = false));
                Dispatcher.Invoke((Action)(() => this.linkStopService.IsEnabled = false));
            }
            else
            {
                var running = this.serviceManager.ServiceRunning;

                if (!this.serviceManager.ServiceRunning)
                {
                    // Service not running.
                    Dispatcher.Invoke((Action)(() => this.statusPanelService.Status = Wsapm.Wpf.Controls.StatusPanel.StatusPanelStatus.Warning));
                    Dispatcher.Invoke((Action)(() => this.linkStartService.IsEnabled = true));
                    Dispatcher.Invoke((Action)(() => this.linkStopService.IsEnabled = false));

                    if (!String.IsNullOrEmpty(this.serviceManager.StatusMessage))
                    {
                        Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = this.serviceManager.StatusMessage));
                    }
                    else
                    {
                        Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = Wsapm.Resources.Wsapm.MainWindow_StatusPanelStatusServiceNotMonitoring));
                    }
                }
                else
                {
                    // Service running.
                    // Check for temporary uptime
                    DateTime?temporaryUptimeUntil = this.temporaryUptimeManager.TemporaryUptimeDefinedAndActive;

                    if (temporaryUptimeUntil.HasValue)
                    {
                        // Temporary Uptime defined.
                        Dispatcher.Invoke((Action)(() => this.statusPanelService.Status = Wsapm.Wpf.Controls.StatusPanel.StatusPanelStatus.Warning));
                        Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = string.Format(Wsapm.Resources.Wsapm.MainWindow_StatusPanelStatusTemporaryUptimeDefinedUntil, temporaryUptimeUntil.Value.ToShortTimeString())));
                        Dispatcher.Invoke((Action)(() => this.hyperlinkTextBlockTemporaryUptime.Text = Wsapm.Resources.Wsapm.MainWindow_StatusPanelStatusDeleteTemporaryUptime));
                        return;
                    }
                    else
                    {
                        // No temporary uptime defined.
                        Dispatcher.Invoke((Action)(() => this.hyperlinkTextBlockTemporaryUptime.Text = Wsapm.Resources.Wsapm.MainWindow_StatusPanelStatusTemporaryUptime));
                    }

                    // Now check for validation errors.
                    bool validationErrors = false;

                    if (currentSettings != null)
                    {
                        bool checkIntervalValid   = true;
                        bool wakeTimersValid      = true;
                        uint currentCheckInterval = 0;

                        lock (this.settingsLock)
                        {
                            // Validate settings and print warning when needed.
                            checkIntervalValid = WsapmTools.ValidateCheckInterval(currentSettings);

                            // Validate if wake timers are allowed.
                            wakeTimersValid      = WsapmTools.ValidateWakeTimers(currentSettings);
                            currentCheckInterval = currentSettings.MonitoringTimerInterval;
                        }

#if DEBUG
                        checkIntervalValid = true;
                        wakeTimersValid    = true;
#endif

                        if (!checkIntervalValid || !wakeTimersValid)
                        {
                            validationErrors = true;
                            Dispatcher.Invoke((Action)(() => this.statusPanelService.Status = Wsapm.Wpf.Controls.StatusPanel.StatusPanelStatus.Warning));
                        }

                        Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = String.Empty));

                        if (!checkIntervalValid)
                        {
                            var winIdleTimeoutAcMinutes = WsapmTools.GetCurrentWindowsIdleTimeoutAcMinutes();
                            Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = String.Format(Wsapm.Resources.Wsapm.MainWindow_ValidationErrorCheckInterval, winIdleTimeoutAcMinutes, currentCheckInterval)));
                        }

                        if (!wakeTimersValid)
                        {
                            Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text += Environment.NewLine + Wsapm.Resources.Wsapm.MainWindow_ValidationErrorWakeTimers));
                        }
                    }

                    if (!validationErrors)
                    {
                        // Everything OK.
                        Dispatcher.Invoke((Action)(() => this.statusPanelService.Status = Wsapm.Wpf.Controls.StatusPanel.StatusPanelStatus.OK));
                        Dispatcher.Invoke((Action)(() => this.linkStartService.IsEnabled = false));
                        Dispatcher.Invoke((Action)(() => this.linkStopService.IsEnabled = true));

                        if (!String.IsNullOrEmpty(this.serviceManager.StatusMessage))
                        {
                            Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = this.serviceManager.StatusMessage));
                        }
                        else
                        {
                            Dispatcher.Invoke((Action)(() => this.textBlockStatus.Text = Wsapm.Resources.Wsapm.MainWindow_StatusPanelStatusServiceMonitoring));
                        }
                    }
                }
            }

            Thread.Sleep(TimeSpan.FromSeconds(5));
        }
Esempio n. 10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            WsapmTools.DeleteTempResources();
        }