Пример #1
0
        public void TerminateActiveMonitoringSession()
        {
            string cpuMonitorPath = GetCpuMonitoringPath(MonitoringSessionDirectories.Active);
            var    existingFiles  = FileSystemHelpers.GetFilesInDirectory(cpuMonitorPath, "*.json", false, SearchOption.TopDirectoryOnly);

            if (existingFiles.Count > 0)
            {
                FileSystemHelpers.DeleteDirectoryContentsSafe(cpuMonitorPath, true);
            }
        }
Пример #2
0
        public void DeleteSession(string sessionId)
        {
            string cpuMonitoringCompleted = GetCpuMonitoringPath(MonitoringSessionDirectories.Completed);
            var    sessionFilePath        = Path.Combine(cpuMonitoringCompleted, sessionId + ".json");

            if (FileSystemHelpers.FileExists(sessionFilePath))
            {
                FileSystemHelpers.DeleteFileSafe(sessionFilePath);
            }

            string logsFolderPath = GetCpuMonitoringPath(MonitoringSessionDirectories.Logs);
            string logsFolder     = Path.Combine(logsFolderPath, sessionId);

            if (FileSystemHelpers.DirectoryExists(logsFolder))
            {
                FileSystemHelpers.DeleteDirectoryContentsSafe(logsFolder);
                FileSystemHelpers.DeleteDirectorySafe(logsFolder);
            }
            Logger.LogCpuMonitoringVerboseEvent("Deleted session", sessionId);
        }
Пример #3
0
        public MonitoringSession CreateSession(MonitoringSession monitoringSession)
        {
            string cpuMonitoringActive = GetCpuMonitoringPath(MonitoringSessionDirectories.Active);
            var    existingFiles       = FileSystemHelpers.GetFilesInDirectory(cpuMonitoringActive, "*.json", false, SearchOption.TopDirectoryOnly);

            if (existingFiles.Count > 0)
            {
                throw new ApplicationException("Another monitoring session is already in progress");
            }
            else
            {
                ValidateSessionParameters(monitoringSession);
                FileSystemHelpers.DeleteDirectoryContentsSafe(cpuMonitoringActive);
                monitoringSession.StartDate = DateTime.UtcNow;
                monitoringSession.EndDate   = DateTime.MinValue.ToUniversalTime();
                monitoringSession.SessionId = monitoringSession.StartDate.ToString(SessionConstants.SessionFileNameFormat);
                cpuMonitoringActive         = Path.Combine(cpuMonitoringActive, monitoringSession.SessionId + ".json");
                monitoringSession.ToJsonFile(cpuMonitoringActive);
                Logger.LogNewCpuMonitoringSession(monitoringSession);
            }

            return(monitoringSession);
        }