コード例 #1
0
        /// <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;
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the ApplicationOptionsChangedEventArgs class.
 /// </summary>
 /// <param name="applicationOptions">ApplicationOptions.</param>
 /// <exception cref="ArgumentNullException">applicationOptions is null.</exception>
 public ApplicationOptionsChangedEventArgs(ApplicationOptions applicationOptions)
 {
     if (applicationOptions == null)
     {
         throw new ArgumentNullException("applicationOptions",
                                         Resources.ArgumentNullException);
     }
     _applicationOptions = applicationOptions;
 }
コード例 #3
0
ファイル: XmlOptionsSaver.cs プロジェクト: pkirk/file-watcher
        /// <summary>
        /// Stores given application options in XML file and creates XML Schema.
        /// </summary>
        /// <param name="applicationOptions">Application options to store.</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">applicationOptions is null.</exception>
        /// <exception cref="ArgumentNullException">xmlConfigFilePath is null.</exception>
        /// <exception cref="ArgumentNullException">xmlSchemaConfigFilePath is null.</exception>
        public static void SaveApplicationOptions(ApplicationOptions applicationOptions,
            string xmlConfigFilePath,
            string xmlSchemaConfigFilePath)
        {
            if (applicationOptions == null)
            {
                throw new ArgumentNullException("applicationOptions",
                                                Resources.ArgumentNullException);
            }
            if (xmlConfigFilePath == null)
            {
                throw new ArgumentNullException("xmlConfigFilePath",
                                                Resources.ArgumentNullException);
            }
            if (xmlSchemaConfigFilePath == null)
            {
                throw new ArgumentNullException("xmlSchemaConfigFilePath",
                                                Resources.ArgumentNullException);
            }

            DataSet dataSet = null;

            try
            {
                // Create dataset and set rows and columns.
                dataSet = BuildConfigurationDataSet(applicationOptions);

                // Write configuration files.
                dataSet.WriteXmlSchema(xmlSchemaConfigFilePath);
                dataSet.WriteXml(xmlConfigFilePath);
            }
            finally
            {
                if (dataSet != null)
                {
                    dataSet.Dispose();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Loads configuration from XML files.
        /// </summary>
        /// <param name="xmlConfigFilePath">Path of the configuration XML file.</param>
        /// <param name="xmlSchemaConfigFilePath">Path of the configuration XML Schema file.</param>
        /// <returns>Application options.</returns>
        /// <remarks>Throws all exceptions defined in ApplicationOptions.</remarks>
        private static ApplicationOptions LoadOptionsToApplicationOptions(string xmlConfigFilePath,
            string xmlSchemaConfigFilePath)
        {
            using (DataSet dataSet = new DataSet())
            {
                dataSet.Locale = CultureInfo.InvariantCulture;

                dataSet.ReadXmlSchema(xmlSchemaConfigFilePath);
                dataSet.ReadXml(xmlConfigFilePath);

                ApplicationOptions applicationOptions = new ApplicationOptions();

                // Load application options.
                foreach (DataRow dataRow in dataSet.Tables[Resources.TableName].Rows)
                {
                    applicationOptions.AutoStartup =
                        (bool)dataRow[Resources.ColumnAutoStartup];

                    applicationOptions.LogMessages =
                        (int)dataRow[Resources.ColumnLogMessages];

                    applicationOptions.ProcessBatchSize =
                        (int)dataRow[Resources.ColumnProcessBatchSize];

                    applicationOptions.RunQueuedProcesses =
                        (bool)dataRow[Resources.ColumnRunQueuedProcesses];

                    applicationOptions.SynchronousExecution =
                        (bool)dataRow[Resources.ColumnSynchronousExecution];
                }

                return applicationOptions;
            }
        }
コード例 #5
0
ファイル: FormOptions.cs プロジェクト: pkirk/file-watcher
        /// <summary>
        /// Returns modified application options.
        /// </summary>
        /// <returns>Modified application options.</returns>
        public ApplicationOptions NewApplicationOptions()
        {
            ApplicationOptions applicationOptions = new ApplicationOptions();

            applicationOptions.AutoStartup =
                checkBoxApplicationAutoStartup.Checked;

            applicationOptions.RunQueuedProcesses =
                checkBoxApplicationRunQueuedProcesses.Checked;

            applicationOptions.SynchronousExecution =
                checkBoxApplicationSynchronousExecution.Checked;

            applicationOptions.LogMessages =
                Convert.ToInt32(numericUpDownLogMessages.Value);

            applicationOptions.ProcessBatchSize =
                Convert.ToInt32(numericUpDownProcessBatchSize.Value);

            return applicationOptions;
        }
コード例 #6
0
ファイル: FormOptions.cs プロジェクト: pkirk/file-watcher
        /// <summary>
        /// Display application options on the view.
        /// </summary>
        /// <param name="applicationOptions">Application options to display.</param>
        public void ViewApplicationOptions(ApplicationOptions applicationOptions)
        {
            if (applicationOptions == null)
            {
                throw new ArgumentNullException("applicationOptions",
                                                Resources.ArgumentNullException);
            }

            checkBoxApplicationAutoStartup.Checked =
                applicationOptions.AutoStartup;

            checkBoxApplicationRunQueuedProcesses.Checked =
                applicationOptions.RunQueuedProcesses;

            checkBoxApplicationSynchronousExecution.Checked =
                applicationOptions.SynchronousExecution;

            numericUpDownLogMessages.Value =
                applicationOptions.LogMessages;

            numericUpDownProcessBatchSize.Value =
                applicationOptions.ProcessBatchSize;
        }
コード例 #7
0
ファイル: XmlOptionsSaver.cs プロジェクト: pkirk/file-watcher
        /// <summary>
        /// Creates configuration DataSet.
        /// </summary>
        /// <param name="applicationOptions">Application options to store.</param>
        /// <returns>Configuration DataSet.</returns>
        private static DataSet BuildConfigurationDataSet(ApplicationOptions applicationOptions)
        {
            DataSet dataSet = null;

            try
            {
                // Create dataset and set columns.
                dataSet = DataSetBuilder.CreateDataSet();

                // Create new datarow.
                DataRow dataRow = dataSet.Tables[Resources.TableName].NewRow();

                // Add values to datarow.
                dataRow[Resources.ColumnAutoStartup] = applicationOptions.AutoStartup;
                dataRow[Resources.ColumnLogMessages] = applicationOptions.LogMessages;
                dataRow[Resources.ColumnProcessBatchSize] = applicationOptions.ProcessBatchSize;
                dataRow[Resources.ColumnRunQueuedProcesses] = applicationOptions.RunQueuedProcesses;
                dataRow[Resources.ColumnSynchronousExecution] = applicationOptions.SynchronousExecution;

                // Add row to dataset.
                dataSet.Tables[Resources.TableName].Rows.Add(dataRow);

                // Accept changes.
                dataSet.AcceptChanges();

                return dataSet;
            }
            catch
            {
                if (dataSet != null)
                {
                    dataSet.Dispose();
                }

                throw;
            }
        }
コード例 #8
0
        /// <summary>
        /// Saves application options.
        /// </summary>
        /// <param name="applicationOptions">Application options.</param>
        /// <exception cref="ArgumentNullException">applicationOptions is null.</exception>
        public void Save(ApplicationOptions applicationOptions)
        {
            if (applicationOptions == null)
            {
                throw new ArgumentNullException("applicationOptions",
                                                Resources.ArgumentNullException);
            }

            // Set options to file watcher controller.
            if (!_fileWatcherController.IsActive())
            {
                _fileWatcherController.SynchronousExecution = applicationOptions.SynchronousExecution;
            }

            _fileWatcherController.RunQueuedProcesses = applicationOptions.RunQueuedProcesses;
            _fileWatcherController.ProcessBatchSize = applicationOptions.ProcessBatchSize;

            XmlOptionsSaver.SaveApplicationOptions(applicationOptions,
                                                   _xmlApplicationOptionsFilePath,
                                                   _xmlSchemaApplicationOptionsFilePath);

            // Store new application options.
            _internalApplicationOptions = applicationOptions;

            // Raise configuration changed event.
            if (ConfigurationChanged != null)
            {
                ConfigurationChanged(this,
                    new ApplicationOptionsChangedEventArgs(applicationOptions));
            }
        }