/// <summary> /// Остановить мониторинг устройств /// </summary> public void StopDeviceMonitoring() { Console.WriteLine("StopDeviceMonitoring"); DeviceChangeNotifier.LogReceived -= OnDeviceChangeNotifierLogReceived; DeviceChangeNotifier.Stop(); DeviceMonitoringState = MonitoringState.Stopped; }
/// <summary> /// Обработчик изменения состояния мониторинга файловой системы /// </summary> private void OnServerFileWatcherStateNotify(object sender, DtoEventArgs <NotifyMonitoringStateDto> e) { BeginInvoke(new Action(() => { FileWatcherState = e.Dto.State; })); }
/// <summary> /// Остановить мониторинг журнала событий /// </summary> public void StopEventMonitoring() { Console.WriteLine(string.Format("StopEventMonitoring")); SystemEventLog = null; SecurityEventLog = null; EventMonitoringState = MonitoringState.Stopped; }
/// <summary> /// Запустить мониторинг журнала событий /// </summary> public void StartEventMonitoring() { Console.WriteLine(string.Format("StartEventMonitoring")); SystemEventLog = new EventLog("System"); SecurityEventLog = new EventLog("Security"); EventMonitoringState = MonitoringState.Started; }
/// <summary> /// Обработчик изменения состояния мониторинга журнала событий /// </summary> private void OnServerEventMonitoringStateNotify(object sender, DtoEventArgs <NotifyMonitoringStateDto> e) { BeginInvoke(new Action(() => { EventMonitoringState = e.Dto.State; StartEventMonitoringButton.Enabled = true; })); }
/// <summary> /// Check for /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CheckForUpdatesNow_Click(object sender, RoutedEventArgs e) { ResetStatusLabel.Content = string.Empty; ResetStatusLabel.Content = "Performing check for updated management packs, please wait."; MonitoringState packStatus = GetPackUpdateMonitorState(); packStatus.Reset(15000); packStatus.Recalculate(); ResetStatusLabel.Content = "Management pack update check has completed."; }
/// <nodoc/> public static DefenderChecker Create() { MonitoringState state = MonitoringState.Unknown; List <string> excludedPaths = new List <string>(); try { // First check if defender is enabled using (RegistryKey realTimeProtection = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows Defender\Real-Time Protection")) { if (realTimeProtection != null) { state = MonitoringState.Enabled; object realTimeDisabled = realTimeProtection.GetValue("DisableRealtimeMonitoring"); if (realTimeDisabled != null && realTimeDisabled.GetType() == typeof(int)) { if ((int)realTimeDisabled == 1) { state = MonitoringState.Disabled; } } // Then look up excluded paths using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths")) { if (key != null) { foreach (string excludedPath in key.GetValueNames()) { excludedPaths.Add(excludedPath); } } } } } } #pragma warning disable ERP022 // TODO: This should catch specific exceptions catch { state = MonitoringState.Unknown; } #pragma warning restore ERP022 return(new DefenderChecker(state, excludedPaths)); }
/// <summary> /// Using the static ManagementGroupConnector this method pulls the monitoring state /// for the Community Pack Update Monitor /// </summary> /// <returns>The <see cref="MonitoringState"/> object that represents the Community Pack Update Monitor.</returns> private MonitoringState GetPackUpdateMonitorState() { // Filter to the Root Management Server Emulator role, there is only one instance of this class so the criteria can be simple. ManagementPackClass rootManagementServerClass = ManagementGroupConnector.CurrentManagementGroup.EntityTypes.GetClass(Guid.Parse("1a9387f0-6fe5-5527-a2cb-73f2f6be6bc7")); MonitoringObjectGenericCriteria monitoringObjectCriteria = new MonitoringObjectGenericCriteria("FullName like 'Microsoft.SystemCenter%'"); IObjectReader <MonitoringObject> monitoringObjects = ManagementGroupConnector.CurrentManagementGroup.EntityObjects.GetObjectReader <MonitoringObject>(monitoringObjectCriteria, rootManagementServerClass, ObjectQueryOptions.Default); MonitoringObject rootManagementServerInstance = monitoringObjects.GetData(0); // For the instance of the Root Management Server Emulator we need to cross that with the Monitor to get the exact monitoring state item ManagementPackMonitorCriteria monitorsCriteria = new ManagementPackMonitorCriteria("Name = 'Community.ManagementPackCatalog.PackStatusMonitor'"); ManagementPackMonitor updateManagementPackMonitor = ManagementGroupConnector.CurrentManagementGroup.Monitoring.GetMonitors(monitorsCriteria)[0]; // Creating a list of one item we pull the current monitoring state of the Update Status monitor var monitorList = new List <ManagementPackMonitor>(); monitorList.Add(updateManagementPackMonitor); MonitoringState packStatus = rootManagementServerInstance.GetMonitoringStates((IEnumerable <ManagementPackMonitor>)monitorList)[0]; return(packStatus); }
/// <summary> /// Запустить мониторинг директории /// </summary> public void StartFileWatcher(FileWatcherSettingsDto dto) { Console.WriteLine(string.Format("StartFileWatcher {0}", dto.Path)); try { Watcher = new FileSystemWatcher(dto.Path, "*.*"); Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; if (dto.EventType.HasFlag(FileEventType.Changed)) { _watcher.Changed -= OnFileChanged; _watcher.Changed += OnFileChanged; } if (dto.EventType.HasFlag(FileEventType.Created)) { _watcher.Created -= OnFileCreated; _watcher.Created += OnFileCreated; } if (dto.EventType.HasFlag(FileEventType.Deleted)) { _watcher.Deleted -= OnFileDeleted; _watcher.Deleted += OnFileDeleted; } if (dto.EventType.HasFlag(FileEventType.Renamed)) { _watcher.Renamed -= OnFileRenamed; _watcher.Renamed += OnFileRenamed; } Watcher.EnableRaisingEvents = true; FileWatcherState = MonitoringState.Started; } catch (Exception ex) { Console.WriteLine(string.Format("Error: StartFileWatcher\r\n{0}", ex.Message)); FileWatcherState = MonitoringState.Stopped; } }
private DefenderChecker(MonitoringState state, List <string> excludedPaths) { m_state = state; m_excludedPaths = excludedPaths; }
/// <summary> /// Остановить мониторинг директории /// </summary> public void StopFileWatcher() { Console.WriteLine("StopFileWatcher"); Watcher = null; FileWatcherState = MonitoringState.Stopped; }