/// <summary> /// Persist the configuration data to the <dataProvider .../> section of galleryserverpro.config. /// </summary> /// <param name="dataProvider">An instance of <see cref="GspDataProviderEntity"/> that contains data to save to the /// <dataProvider .../> section of galleryserverpro.config.</param> /// <exception cref="UnauthorizedAccessException">Thrown when the IIS application pool identity does not have /// write access to galleryserverpro.config.</exception> public static void SaveDataProvider(GspDataProviderEntity dataProvider) { XmlDocument xmlDoc = LoadGalleryServerProConfigFromDisk(); // Update the attributes of the <core ...> element with the values from the source config file. XmlElement coreElement = (XmlElement)xmlDoc.SelectSingleNode(@"galleryServerPro/dataProvider"); // Loop through each entity property and assign the value to the matching element in the <core> section of // galleryserverpro.config. Type type = typeof(GspDataProviderEntity); foreach (FieldInfo field in type.GetFields()) { string attValue = Convert.ToString(field.GetValue(dataProvider), System.Globalization.CultureInfo.InvariantCulture); //string attValue = field.GetValue(dataProvider).ToString(); if (field.FieldType == typeof(bool)) { // Bool fields should be stored in lower case; all others can be stored without modification. attValue = attValue.ToLowerInvariant(); } coreElement.SetAttribute(field.Name, attValue); } SaveGalleryServerProConfigToDisk(xmlDoc); }
/// <summary> /// Gets an instance of <see cref="GspDataProviderEntity"/> that contains data from the <dataProvider .../> section of /// galleryserverpro.config. The entity can be updated with new values and then passed to the <see cref="SaveDataProvider"/> /// method for persisting back to the file system. /// </summary> /// <param name="dataProvider">An instance of <see cref="IDataProvider"/> that contains configuration /// data stored in the <dataProvider .../> section of galleryserverpro.config.</param> /// <returns>Returns an instance of <see cref="GspDataProviderEntity"/> that is contains data from the <dataProvider .../> section of /// galleryserverpro.config.</returns> public static GspDataProviderEntity GetGspDataProviderEntity(IDataProvider dataProvider) { GspDataProviderEntity dpe = new GspDataProviderEntity(); dpe.defaultProvider = dataProvider.Name; return(dpe); }