/// <summary> /// Initializes a new instance of the <see cref="ScanManager"/> class. /// </summary> /// <param name="storageProvider"> /// The storage provider to use. /// </param> /// <param name="dataProvider"> /// The data provider to use. /// </param> internal ScanManager(IStorageProvider storageProvider, IDataProvider dataProvider) { this.storageProvider = storageProvider; this.dataProvider = dataProvider; this.settings = Settings.LoadSettings(storageProvider); this.tvShows = TvShow.GetTvShows(storageProvider).ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="FileManager"/> class. Initialises a new instance of the <see cref="FileManager"/> class. /// </summary> /// <param name="storageProvider"> /// The storage provider. /// </param> /// <param name="dataProvider"> /// The data provider. /// </param> internal FileManager(IStorageProvider storageProvider, IDataProvider dataProvider) { this.storageProvider = storageProvider; this.settings = Settings.LoadSettings(storageProvider); this.scanManager = new ScanManager(this.storageProvider, dataProvider); }
/// <summary> /// Loads the settings. /// </summary> private void LoadSettings() { this.settings = Settings.LoadSettings(); this.settings.SettingsChanged += (sender, e) => { this.SubDirectories = this.LoadSubDirectories(); }; this.SubDirectories = this.LoadSubDirectories(); }
/// <summary> /// Loads the settings from the specified provider. /// </summary> /// <param name="provider"> /// The provider to load the settings from. /// </param> /// <returns> /// The new settings object. /// </returns> internal static Settings LoadSettings(IStorageProvider provider) { var settings = new Settings(); try { provider.LoadSettings(settings); // Remove the event handler before adding it incase the // handler has been added before. provider.SettingsSaved -= settings.OnSettingsSaved; provider.SettingsSaved += settings.OnSettingsSaved; } catch (IOException) { // Settings file does not exist. Use default settings. settings.SetDefault(); } return settings; }
/// <summary> /// Saves the specified settings into the XML file. /// </summary> /// <param name="settings"> /// The settings to save. /// </param> public void SaveSettings(Settings settings) { if (this.document.Root == null) { throw new XmlException("XML is invalid."); } XElement settingsNode = this.document.Root.Element(GetName("Settings")); if (settingsNode == null) { throw new XmlException("Xml is invalid"); } settingsNode.ReplaceWith(settings.ToXml()); this.document.Save(XmlFile); this.OnSettingsSaved(); }
/// <summary> /// Reads the settings from the XML file. /// </summary> /// <param name="settings"> /// The settings to set from the XML. /// </param> public void LoadSettings(Settings settings) { if (this.document.Root == null) { throw new XmlException("XML is invalid."); } XElement settingsNode = this.document.Root.Element(GetName("Settings")); if (settingsNode == null) { throw new XmlSchemaException("The XML file is invalid."); } settings.FromXml(settingsNode); }