/// <summary> /// Update log view. /// </summary> private void Update() { // If file watcher is active, use delayed update. if (FileWatcherController.IsActive()) { lock (_lockUpdateTimer) { if (!_updateTimer.Enabled) { _updateTimer.Enabled = true; } } } else { lock (_lockUpdateTimer) { if (_updateTimer.Enabled) { _updateTimer.Enabled = false; } } _logView.Update(LogMessages()); } }
/// <summary> /// Initializes a new instance of the ApplicationOptionsController class. /// </summary> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="xmlApplicationOptionsFilePath">Path of the configuration XML file.</param> /// <param name="xmlSchemaApplicationOptionsFilePath">Path of the configuration XML Schema file.</param> /// <param name="applicationOptions">Application options.</param> /// <exception cref="ArgumentNullException">fileWatcherController is null.</exception> /// <exception cref="ArgumentNullException">xmlApplicationOptionsFilePath is null.</exception> /// <exception cref="ArgumentNullException">xmlSchemaApplicationOptionsFilePath is null.</exception> /// <exception cref="ArgumentNullException">applicationOptions is null.</exception> public ApplicationOptionsController(FileWatcherController fileWatcherController, string xmlApplicationOptionsFilePath, string xmlSchemaApplicationOptionsFilePath, ApplicationOptions applicationOptions) { if (fileWatcherController == null) { throw new ArgumentNullException("fileWatcherController", Resources.ArgumentNullException); } if (xmlApplicationOptionsFilePath == null) { throw new ArgumentNullException("xmlApplicationOptionsFilePath", Resources.ArgumentNullException); } if (xmlSchemaApplicationOptionsFilePath == null) { throw new ArgumentNullException("xmlSchemaApplicationOptionsFilePath", Resources.ArgumentNullException); } if (applicationOptions == null) { throw new ArgumentNullException("applicationOptions", Resources.ArgumentNullException); } _fileWatcherController = fileWatcherController; _xmlApplicationOptionsFilePath = xmlApplicationOptionsFilePath; _xmlSchemaApplicationOptionsFilePath = xmlSchemaApplicationOptionsFilePath; _internalApplicationOptions = applicationOptions; }
/// <summary> /// Initializes a new instance of the ConsoleViewPresenter class. /// </summary> /// <param name="consoleView">Console view.</param> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="logger">Logger.</param> /// <param name="formatter">Log formatter.</param> /// <param name="xmlConfigFilePath">Path of the configuration XML file.</param> /// <param name="xmlSchemaConfigFilePath">Path of the configuration XML Schema file.</param> /// <exception cref="ArgumentNullException">xmlConfigFilePath is null.</exception> /// <exception cref="ArgumentNullException">xmlSchemaConfigFilePath is null.</exception> public ConsoleViewPresenter(IConsoleView consoleView, FileWatcherController fileWatcherController, ILogger logger, IFormatter formatter, string xmlConfigFilePath, string xmlSchemaConfigFilePath) : base(fileWatcherController, logger, formatter) { if (consoleView == null) { throw new ArgumentNullException("consoleView", Resources.ArgumentNullException); } if (xmlConfigFilePath == null) { throw new ArgumentNullException("xmlConfigFilePath", Resources.ArgumentNullException); } if (xmlSchemaConfigFilePath == null) { throw new ArgumentNullException("xmlSchemaConfigFilePath", Resources.ArgumentNullException); } _consoleView = consoleView; _xmlConfigFilePath = xmlConfigFilePath; _xmlSchemaConfigFilePath = xmlSchemaConfigFilePath; SubscribeToConsoleViewEvents(); }
/// <summary> /// Updates main view list. /// </summary> /// <param name="forceUpdate">Force update even if file watcher controller is running.</param> private void UpdateList(bool forceUpdate) { // True if to update. _updateInfo = true; // If file watcher is active, use delayed update. if (FileWatcherController.IsActive()) { if (!_updateTimer.Enabled) { _updateTimer.Enabled = true; } if (forceUpdate) { _mainView.UpdateList(_fileWatcherSortedDictionary); } } else { if (_updateTimer.Enabled) { _updateTimer.Enabled = false; } _mainView.UpdateList(_fileWatcherSortedDictionary); } }
/// <summary> /// Initializes a new instance of the OptionsViewPresenter class. /// </summary> /// <param name="optionsView">Options view.</param> /// <param name="mainView">Main view.</param> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="applicationOptionsController">ApplicationOptionsController.</param> /// <exception cref="ArgumentNullException">fileWatcherController is null.</exception> public OptionsViewPresenter(IOptionsView optionsView, IMainView mainView, FileWatcherController fileWatcherController, ApplicationOptionsController applicationOptionsController) { if (mainView == null) { throw new ArgumentNullException("mainView", Resources.ArgumentNullException); } if (optionsView == null) { throw new ArgumentNullException("optionsView", Resources.ArgumentNullException); } if (fileWatcherController == null) { throw new ArgumentNullException("fileWatcherController", Resources.ArgumentNullException); } if (applicationOptionsController == null) { throw new ArgumentNullException("applicationOptionsController", Resources.ArgumentNullException); } _optionsView = optionsView; _mainView = mainView; _fileWatcherController = fileWatcherController; _applicationOptionsController = applicationOptionsController; SubscribeToMainViewEvents(); SubscribeToOptionsViewEvents(); }
/// <summary> /// Initializes a new instance of the LogViewPresenterBase class. /// </summary> /// <param name="logView">Log view.</param> /// <param name="mainView">Main view.</param> /// <param name="applicationOptionsController">ApplicationOptionsController.</param> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="formatter">Log formatter.</param> /// <param name="viewUpdateInterval">View update interval.</param> /// <param name="logMessageSize">Log message size.</param> /// <exception cref="ArgumentNullException">Log view is null.</exception> /// <exception cref="ArgumentNullException">fileWatcherController is null.</exception> /// <exception cref="ArgumentNullException">formatter is null.</exception> public LogViewPresenter(ILogView logView, IMainView mainView, ApplicationOptionsController applicationOptionsController, FileWatcherController fileWatcherController, IFormatter formatter, double viewUpdateInterval, int logMessageSize) : base(fileWatcherController, formatter, logMessageSize) { if (logView == null) { throw new ArgumentNullException("logView", Resources.ArgumentNullException); } if (mainView == null) { throw new ArgumentNullException("mainView", Resources.ArgumentNullException); } if (applicationOptionsController == null) { throw new ArgumentNullException("applicationOptionsController", Resources.ArgumentNullException); } if (fileWatcherController == null) { throw new ArgumentNullException("fileWatcherController", Resources.ArgumentNullException); } if (formatter == null) { throw new ArgumentNullException("formatter", Resources.ArgumentNullException); } _logView = logView; _mainView = mainView; _applicationOptionsController = applicationOptionsController; // Check if view interval is less than default value. if (viewUpdateInterval < 100) { _updateTimer.Interval = 100; } else { _updateTimer.Interval = viewUpdateInterval; } SubscribeToLogViewEvents(); SubscribeToMainViewEvents(); SubscribeToApplicationOptionsControllerEvents(); // Subscribe to timer event. (updates view). _updateTimer.Elapsed += new ElapsedEventHandler(OnElapsed); // Set synchronization context for running events in main thread. SetSynchronizationContext(); }
/// <summary> /// Performs stop. /// </summary> private void Stop() { if (SelectedDaemon != null) { FileWatcherController.StopFileWatcher(SelectedDaemon); } EnableDisableControls(); }
/// <summary> /// Enables or disables controls. /// </summary> private void UpdateControls() { _mainView.StartEnabled = false; _mainView.StopEnabled = false; _mainView.DeleteEnabled = false; _mainView.PropertiesEnabled = false; _mainView.StartAllEnabled = FileWatcherController.CanStartAllFileWatchers(); _mainView.StopAllEnabled = FileWatcherController.CanStopAllFileWatchers(); _mainView.NewEnabled = FileWatcherController.CanAddFileWatcherConfiguration(); _mainView.ExitEnabled = !FileWatcherController.IsActive(); }
/// <summary> /// Loads file watcher configuration and sets controller. /// </summary> private void SetFileWatcherContoller() { // Exits if error occures. Dictionary <string, FileWatcherConfigurationSet> configurationDictionary = LoadConfiguration(ConfigurationWrapper.XmlConfigurationFilePath, ConfigurationWrapper.XmlSchemaConfigurationFilePath); _fileWatcherController = new FileWatcherController(configurationDictionary); // Set queue trim interval. _fileWatcherController.SetQueueTrimInterval(ConfigurationWrapper.QueueTrimInterval); }
/// <summary> /// Stops file watchers. /// </summary> private void StopAllFileWatchers() { // Avoid deadlock if all file watchers have invalid path by checking IsActive. while (!FileWatcherController.CanStopAllFileWatchers() && FileWatcherController.IsActive()) { // Wait for starting file watchers. _canStopAll.WaitOne(); } if (FileWatcherController.CanStopAllFileWatchers()) { FileWatcherController.StopAllFileWatchers(); } }
/// <summary> /// Enables or disables controls. /// </summary> /// <param name="selectedDaemon">Selected daemon name.</param> private void UpdateControls(string selectedDaemon) { _mainView.StartEnabled = FileWatcherController.CanStartFileWatcher(selectedDaemon); _mainView.StopEnabled = FileWatcherController.CanStopFileWatcher(selectedDaemon); _mainView.StartAllEnabled = FileWatcherController.CanStartAllFileWatchers(); _mainView.StopAllEnabled = FileWatcherController.CanStopAllFileWatchers(); _mainView.NewEnabled = FileWatcherController.CanAddFileWatcherConfiguration(); bool canEdit = FileWatcherController.CanEditFileWatcherConfiguration(); _mainView.DeleteEnabled = canEdit; _mainView.PropertiesEnabled = canEdit; _mainView.ExitEnabled = !FileWatcherController.IsActive(); }
/// <summary> /// Initializes a new instance of the WindowsServiceViewPresenter class. /// </summary> /// <param name="windowsServiceView">Windows service view.</param> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="logger">Logger.</param> /// <param name="formatter">Log formatter.</param> public WindowsServiceViewPresenter(IWindowsServiceView windowsServiceView, FileWatcherController fileWatcherController, ILogger logger, IFormatter formatter) : base(fileWatcherController, logger, formatter) { if (windowsServiceView == null) { throw new ArgumentNullException("windowsServiceView", Resources.ArgumentNullException); } _windowsServiceView = windowsServiceView; SubscribeToWindowsServiceViewEvents(); }
/// <summary> /// Performs delete. /// </summary> private void Delete() { if (SelectedDaemon != null) { // Remove before refreshing the selected daemon. _fileWatcherSortedDictionary.Remove(SelectedDaemon); // This will refresh the selected daemon. FileWatcherController.RemoveFileWatcher(SelectedDaemon); _mainView.UpdateList(_fileWatcherSortedDictionary); // Save configuration changes. XmlConfigurationSaver.SaveConfigurationSets(FileWatcherController.FileWatcherConfiguration, _xmlConfigFilePath, _xmlSchemaConfigFilePath); EnableDisableControls(); } }
/// <summary> /// Runs the application. /// </summary> private void RunApplication() { base.WriteApplicationStartedMessage(); if (FileWatcherController.CanStartAllFileWatchers()) { StartAllFileWatchers(); _consoleView.EchoReadLine(String.Empty); StopAllFileWatchers(); WaitForControllerStopped(); } else { _consoleView.EchoLine(@Resources.MessageNoDaemonsToStart); _consoleView.EchoReadLine(@Resources.MessagePressEnterToExit); } base.WriteApplicationStoppedMessage(); Dispose(); }
/// <summary> /// Initializes a new instance of the LogViewPresenterBase class. /// </summary> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="formatter">Log formatter.</param> /// <param name="logMessageSize">Log message size.</param> /// <exception cref="ArgumentNullException">fileWatcherController is null.</exception> /// <exception cref="ArgumentNullException">formatter is null.</exception> public LogViewPresenterBase(FileWatcherController fileWatcherController, IFormatter formatter, int logMessageSize) { if (fileWatcherController == null) { throw new ArgumentNullException("fileWatcherController", Resources.ArgumentNullException); } if (formatter == null) { throw new ArgumentNullException("formatter", Resources.ArgumentNullException); } _fileWatcherController = fileWatcherController; _formatter = formatter; LogMessageSize = logMessageSize; SubscribeToFileWatcherControllerEvents(); }
/// <summary> /// Initializes a new instance of the PropertiesViewPresenter class. /// </summary> /// <param name="propertiesView">Properties view.</param> /// <param name="mainView">Main view.</param> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="xmlConfigFilePath">Path of the configuration XML file.</param> /// <param name="xmlSchemaConfigFilePath">Path of the configuration XML Schema file.</param> /// <exception cref="ArgumentNullException">propertiesView is null.</exception> /// <exception cref="ArgumentNullException">mainView is null.</exception> /// <exception cref="ArgumentNullException">fileWatcherController is null.</exception> /// <exception cref="ArgumentNullException">xmlConfigFilePath is null.</exception> /// <exception cref="ArgumentNullException">xmlSchemaConfigFilePath is null.</exception> public PropertiesViewPresenter(IPropertiesView propertiesView, IMainView mainView, FileWatcherController fileWatcherController, string xmlConfigFilePath, string xmlSchemaConfigFilePath) { if (propertiesView == null) { throw new ArgumentNullException("propertiesView", Resources.ArgumentNullException); } if (mainView == null) { throw new ArgumentNullException("mainView", Resources.ArgumentNullException); } if (fileWatcherController == null) { throw new ArgumentNullException("fileWatcherController", Resources.ArgumentNullException); } if (xmlConfigFilePath == null) { throw new ArgumentNullException("xmlConfigFilePath", Resources.ArgumentNullException); } if (xmlSchemaConfigFilePath == null) { throw new ArgumentNullException("xmlSchemaConfigFilePath", Resources.ArgumentNullException); } _propertiesView = propertiesView; _mainView = mainView; _fileWatcherController = fileWatcherController; _xmlConfigFilePath = xmlConfigFilePath; _xmlSchemaConfigFilePath = xmlSchemaConfigFilePath; SubscribeToMainViewEvents(); SubscribeToPropertiesViewEvents(); }
/// <summary> /// Initializes a new instance of the MainViewPresenterBase class. /// </summary> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="logger">Logger.</param> /// <param name="formatter">Log formatter.</param> /// <exception cref="ArgumentNullException">fileWatcherController is null.</exception> /// <exception cref="ArgumentNullException">logger is null.</exception> /// <exception cref="ArgumentNullException">formatter is null.</exception> public MainViewPresenterBase(FileWatcherController fileWatcherController, ILogger logger, IFormatter formatter) { if (fileWatcherController == null) { throw new ArgumentNullException("fileWatcherController", Resources.ArgumentNullException); } if (logger == null) { throw new ArgumentNullException("logger", Resources.ArgumentNullException); } if (formatter == null) { throw new ArgumentNullException("formatter", Resources.ArgumentNullException); } _fileWatcherController = fileWatcherController; _logger = logger; _formatter = formatter; SubscribeToFileWatcherControllerEvents(); }
/// <summary> /// Starts file watchers. /// </summary> private void StartAllFileWatchers() { FileWatcherController.StartAllFileWatchers(); }
/// <summary> /// Starts file watchers. /// </summary> private void StartAllFileWatchers() { _consoleView.EchoLine(@Resources.MessageStartingDaemons); FileWatcherController.StartAllFileWatchers(); }
/// <summary> /// Performs stop all. /// </summary> private void StopAll() { FileWatcherController.StopAllFileWatchers(); EnableDisableControls(); }
/// <summary> /// Updates main view running processes. /// </summary> private void UpdateRunningProcesses() { _mainView.UpdateRunningProcesses(FileWatcherController.RunningProcesses()); }
/// <summary> /// Initializes a new instance of the MainViewPresenter class. /// </summary> /// <param name="mainView">Main view.</param> /// <param name="fileWatcherController">FileWatcherController.</param> /// <param name="logger">Logger.</param> /// <param name="formatter">Log formatter.</param> /// <param name="xmlConfigFilePath">Path of the configuration XML file.</param> /// <param name="xmlSchemaConfigFilePath">Path of the configuration XML Schema file.</param> /// <param name="viewUpdateInterval">View update interval.</param> /// <exception cref="ArgumentNullException">mainView is null.</exception> /// <exception cref="ArgumentNullException">fileWatcherController is null.</exception> /// <exception cref="ArgumentNullException">logger is null.</exception> /// <exception cref="ArgumentNullException">formatter is null.</exception> /// <exception cref="ArgumentNullException">xmlConfigFilePath is null.</exception> /// <exception cref="ArgumentNullException">xmlSchemaConfigFilePath is null.</exception> public MainViewPresenter(IMainView mainView, FileWatcherController fileWatcherController, ILogger logger, IFormatter formatter, string xmlConfigFilePath, string xmlSchemaConfigFilePath, double viewUpdateInterval) : base(fileWatcherController, logger, formatter) { if (mainView == null) { throw new ArgumentNullException("mainView", Resources.ArgumentNullException); } if (fileWatcherController == null) { throw new ArgumentNullException("fileWatcherController", Resources.ArgumentNullException); } if (logger == null) { throw new ArgumentNullException("logger", Resources.ArgumentNullException); } if (formatter == null) { throw new ArgumentNullException("formatter", Resources.ArgumentNullException); } if (xmlConfigFilePath == null) { throw new ArgumentNullException("xmlConfigFilePath", Resources.ArgumentNullException); } if (xmlSchemaConfigFilePath == null) { throw new ArgumentNullException("xmlSchemaConfigFilePath", Resources.ArgumentNullException); } _mainView = mainView; _xmlConfigFilePath = xmlConfigFilePath; _xmlSchemaConfigFilePath = xmlSchemaConfigFilePath; // Check if view interval is less than default value. if (viewUpdateInterval < 100) { _updateTimer.Interval = 100; } else { _updateTimer.Interval = viewUpdateInterval; } // Subscribe to timer event. (updates view). _updateTimer.Elapsed += new ElapsedEventHandler(OnElapsed); // Set synchronization context for running events in main thread. SetSynchronizationContext(); SubscribeToMainViewEvents(); SetFileWatcherSortedDictionary(); // Write message to log. base.WriteApplicationStartedMessage(); }