Exemplo n.º 1
0
        /// <summary>
        /// Loads saved settings for the <see cref="MultipleDestinationExporter"/> object from the config file if the <see cref="PersistSettings"/>
        /// property is set to true.
        /// </summary>
        /// <exception cref="ConfigurationErrorsException"><see cref="SettingsCategory"/> has a value of null or empty string.</exception>
        public void LoadSettings()
        {
            if (m_persistSettings)
            {
                // Ensure that settings category is specified.
                if (string.IsNullOrEmpty(m_settingsCategory))
                {
                    throw new ConfigurationErrorsException("SettingsCategory property has not been set");
                }

                // Load settings from the specified category.
                ConfigurationFile config = ConfigurationFile.Current;
                CategorizedSettingsElementCollection settings = config.Settings[m_settingsCategory];

                if (settings.Count == 0)
                {
                    return;    // Don't proceed if export destinations don't exist in config file.
                }
                m_exportTimeout        = settings["ExportTimeout", true].ValueAs(m_exportTimeout);
                m_maximumRetryAttempts = settings["MaximumRetryAttempts", true].ValueAs(m_maximumRetryAttempts);
                m_retryDelayInterval   = settings["RetryDelayInterval", true].ValueAs(m_retryDelayInterval);
                int count = settings["ExportCount", true].ValueAsInt32();

                lock (m_exportDestinationsLock)
                {
                    m_exportDestinations = new List <ExportDestination>(count);

                    for (int x = 0; x < count; x++)
                    {
                        string entryRoot = $"ExportDestination{x + 1}";

                        // Load export destination from configuration entries
                        ExportDestination destination = new ExportDestination();

                        destination.DestinationFile = settings[entryRoot, true].ValueAsString() + settings[$"{entryRoot}.FileName", true].ValueAsString();
                        destination.ConnectToShare  = settings[$"{entryRoot}.ConnectToShare", true].ValueAsBoolean();
                        destination.Domain          = settings[$"{entryRoot}.Domain", true].ValueAsString();
                        destination.UserName        = settings[$"{entryRoot}.UserName", true].ValueAsString();
                        destination.Password        = settings[$"{entryRoot}.Password", true].ValueAsString();

                        // Save new export destination if destination file name has been defined and is valid
                        if (FilePath.IsValidFileName(destination.DestinationFile))
                        {
                            m_exportDestinations.Add(destination);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads saved settings for the <see cref="MultipleDestinationExporter"/> object from the config file if the <see cref="PersistSettings"/> 
        /// property is set to true.
        /// </summary>
        /// <exception cref="ConfigurationErrorsException"><see cref="SettingsCategory"/> has a value of null or empty string.</exception>
        public void LoadSettings()
        {
            if (m_persistSettings)
            {
                // Ensure that settings category is specified.
                if (string.IsNullOrEmpty(m_settingsCategory))
                    throw new ConfigurationErrorsException("SettingsCategory property has not been set");

                // Load settings from the specified category.
                ConfigurationFile config = ConfigurationFile.Current;
                CategorizedSettingsElementCollection settings = config.Settings[m_settingsCategory];

                if (settings.Count == 0)
                    return;    // Don't proceed if export destinations don't exist in config file.

                ExportDestination destination;
                string entryRoot;
                int count;

                m_exportTimeout = settings["ExportTimeout", true].ValueAs(m_exportTimeout);
                m_maximumRetryAttempts = settings["MaximumRetryAttempts", true].ValueAs(m_maximumRetryAttempts);
                m_retryDelayInterval = settings["RetryDelayInterval", true].ValueAs(m_retryDelayInterval);
                count = settings["ExportCount", true].ValueAsInt32();

                lock (m_exportDestinationsLock)
                {
                    m_exportDestinations = new List<ExportDestination>(count);

                    for (int x = 0; x < count; x++)
                    {
                        entryRoot = string.Format("ExportDestination{0}", x + 1);

                        // Load export destination from configuration entries
                        destination = new ExportDestination();
                        destination.DestinationFile = settings[entryRoot, true].ValueAsString() + settings[string.Format("{0}.FileName", entryRoot), true].ValueAsString();
                        destination.ConnectToShare = settings[string.Format("{0}.ConnectToShare", entryRoot), true].ValueAsBoolean();
                        destination.Domain = settings[string.Format("{0}.Domain", entryRoot), true].ValueAsString();
                        destination.UserName = settings[string.Format("{0}.UserName", entryRoot), true].ValueAsString();
                        destination.Password = settings[string.Format("{0}.Password", entryRoot), true].ValueAsString();

                        // Save new export destination if destination file name has been defined and is valid
                        if (FilePath.IsValidFileName(destination.DestinationFile))
                            m_exportDestinations.Add(destination);
                    }
                }
            }
        }