Ejemplo n.º 1
0
		/// <summary>
		/// Gets an instance of <see cref="GspDataProviderEntity"/> that contains data from the &lt;dataProvider .../&gt; 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="GalleryServerPro.Configuration.DataProvider"/> that contains configuration
		/// data stored in the &lt;dataProvider .../&gt; section of galleryserverpro.config.</param>
		/// <returns>Returns an instance of <see cref="GspDataProviderEntity"/> that is contains data from the &lt;dataProvider .../&gt; section of 
		/// galleryserverpro.config.</returns>
		public static GspDataProviderEntity GetGspDataProviderEntity(DataProvider dataProvider)
		{
			GspDataProviderEntity dpe = new GspDataProviderEntity();

			dpe.defaultProvider = dataProvider.DefaultProvider;

			return dpe;
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Persist the configuration data to the &lt;dataProvider .../&gt; section of galleryserverpro.config.
		/// </summary>
		/// <param name="dataProvider">An instance of <see cref="GspDataProviderEntity"/> that contains data to save to the
		/// &lt;dataProvider .../&gt; 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);
		}