/// <summary> /// Initializes (or reinitializes) <see cref="MultipleDestinationExporter"/> from configuration settings. /// </summary> /// <param name="defaultDestinations">Provides a default set of export destinations if none exist in configuration settings.</param> /// <remarks> /// If not being used as a component (i.e., user creates their own instance of this class), this method /// must be called in order to initialize exports. Event if used as a component this method can be /// called at anytime to reintialize the exports with new configuration information. /// </remarks> public void Initialize(ExportDestination[] defaultDestinations) { // So as to not delay calling thread due to share authentication, we perform initialization on another thread... #if ThreadTracking ManagedThread thread = ManagedThreadPool.QueueUserWorkItem(Initialize, defaultDestinations); thread.Name = "TVA.IO.MultipleDestinationExporter.Initialize()"; #else ThreadPool.QueueUserWorkItem(Initialize, defaultDestinations); #endif }
/// <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 (this) { 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); } } } }
/// <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> public void LoadSettings() { if (m_persistSettings) { // Ensure that settings category is specified. if (string.IsNullOrEmpty(m_settingsCategory)) throw new InvalidOperationException("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. string entryRoot; int count; ExportDestination destination; m_exportTimeout = settings["ExportTimeout", true].ValueAs(m_exportTimeout); count = settings["ExportCount", true].ValueAsInt32(); m_exportDestinations = new List<ExportDestination>(count); lock (m_exportDestinations) { 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 m_exportDestinations.Add(destination); } } } }