Exemple #1
0
        /// <summary>
        /// Creates example daemon configuration files.
        /// </summary>
        public void CreateExampleDaemonConfigFiles()
        {
            Dictionary <string, FileWatcherConfigurationSet> configurationDictionary =
                new Dictionary <string, FileWatcherConfigurationSet>();

            configurationDictionary.Add("Default 'notepad.exe' Daemon (monitors: *.txt)",
                                        GetNotepadDaemonConfiguration());
            configurationDictionary.Add("Default 'calc.exe' Daemon (monitors: *.txt)",
                                        GetCalcDaemonConfiguration());
            configurationDictionary.Add("Default 'mspaint.exe' Daemon (monitors: *.txt)",
                                        GetMSPaintDaemonConfiguration());

            XmlConfigurationSaver.SaveConfigurationSets(configurationDictionary,
                                                        _xmlConfigFilePath,
                                                        _xmlSchemaConfigFilePath);
        }
        /// <summary>
        /// Handles on save event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Event data.</param>
        private void OnSave(object sender,
                            EventArgs e)
        {
            bool success = false;

            // If not a new one.
            if (OriginalDaemonName != null)
            {
                try
                {
                    // Update configuration.
                    _fileWatcherController.UpdateFileWatcher(OriginalDaemonName,
                                                             _propertiesView.NewConfigurationKeyValuePair());
                    success = true;
                }
                catch (ArgumentException ex)
                {
                    // Show error in view.
                    _propertiesView.ShowError(ex.Message);
                }
            }
            else
            {
                try
                {
                    // Try to add new configuration.
                    _fileWatcherController.AddFileWatcher(_propertiesView.NewConfigurationKeyValuePair());
                    success = true;
                }
                catch (ArgumentException ex)
                {
                    // Show error in view.
                    _propertiesView.ShowError(ex.Message);
                }
            }

            // If operation was success.
            if (success)
            {
                // Save configuration.
                XmlConfigurationSaver.SaveConfigurationSets(_fileWatcherController.FileWatcherConfiguration,
                                                            _xmlConfigFilePath,
                                                            _xmlSchemaConfigFilePath);
                // Hide view.
                _propertiesView.HideView();
            }
        }
        /// <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();
            }
        }