/// <summary>
        /// Retrieves the gallery control settings from the data store for all controls containing galleries.
        /// </summary>
        /// <returns>Returns an <see cref="IGalleryControlSettingsCollection" /> containing the settings for all controls containing galleries.</returns>
        internal static IGalleryControlSettingsCollection RetrieveGalleryControlSettingsFromDataStore()
        {
            IGalleryControlSettingsCollection gallerySettings = new GalleryControlSettingsCollection();
              IGalleryControlSettings gs = null;
              string prevControlId = null;

              Type gsType = typeof(GalleryControlSettings);

              // Loop through each gallery control setting and assign to the relevant property. When we encounter a record with a new control ID,
              // automatically create a new GalleryControlSetting instance and start populating that one. When we are done with the loop we will
              // have created one GalleryControlSetting instance for each control that contains a gallery.

              // SQL:
              // SELECT
              //  GalleryControlSettingId, ControlId, SettingName, SettingValue
              // FROM [gs_GalleryControlSetting]
              // ORDER BY ControlId;
              using (var repo = new GalleryControlSettingRepository())
              {
            foreach (GalleryControlSettingDto gcsDto in repo.GetAll().OrderBy(g => g.ControlId))
            {
              #region Check for new gallery

              string currControlId = gcsDto.ControlId.Trim();

              if (String.IsNullOrEmpty(prevControlId) || (!currControlId.Equals(prevControlId)))
              {
            // We have encountered settings for a new gallery. Create a new object and add it to our collection.
            gs = new GalleryControlSettings(gcsDto.GalleryControlSettingId, currControlId);

            gallerySettings.Add(gs);

            prevControlId = currControlId;
              }

              #endregion

              #region Assign property

              // For each setting in the data store, find the matching property and assign the value to it.
              string settingName = gcsDto.SettingName.Trim();

              PropertyInfo prop = gsType.GetProperty(settingName);

              if (prop == null)
              {
            throw new MissingMemberException(String.Format(CultureInfo.CurrentCulture, "Invalid gallery control setting. A gallery control setting named '{0}' was found in the data store, but no property by that name exists in the class '{1}'. Check the gallery control settings in the data store to ensure they are correct.", settingName, gsType));
              }
              else if (prop.PropertyType == typeof(bool?))
              {
            prop.SetValue(gs, Convert.ToBoolean(gcsDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null);
              }
              else if (prop.PropertyType == typeof(bool))
              {
            prop.SetValue(gs, Convert.ToBoolean(gcsDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null);
              }
              else if (prop.PropertyType == typeof(string))
              {
            prop.SetValue(gs, Convert.ToString(gcsDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null);
              }
              else if (prop.PropertyType == typeof(int))
              {
            prop.SetValue(gs, Convert.ToInt32(gcsDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null);
              }
              else if (prop.PropertyType == typeof(int?))
              {
            prop.SetValue(gs, Convert.ToInt32(gcsDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null);
              }
              else if (prop.PropertyType == typeof(Single))
              {
            prop.SetValue(gs, Convert.ToSingle(gcsDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null);
              }
              else if (prop.PropertyType == typeof(ViewMode))
              {
            AssignViewModeProperty(gs, prop, gcsDto.SettingValue.Trim());
              }
              else if (prop.PropertyType == typeof(SlideShowType))
              {
                        AssignSlideShowTypeProperty(gs, prop, gcsDto.SettingValue.Trim());
              }
              else if (prop.PropertyType == typeof(String[]))
              {
            // Parse comma-delimited string to array
            string[] strings = gcsDto.SettingValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            // Trim any leading and trailing spaces
            for (int i = 0; i < strings.Length; i++)
            {
              strings[i] = strings[i].Trim();
            }

            prop.SetValue(gs, strings, null);
              }
              else
              {
            throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, "GalleryControlSettings.RetrieveGalleryControlSettingsFromDataStore is not designed to process a property of type {0} (encountered in GalleryControlSettings.{1})", prop.PropertyType, prop.Name));
              }

              #endregion
            }
              }

              return gallerySettings;
        }
        /// <summary>
        /// Persist the current gallery control settings to the data store.
        /// </summary>
        public void Save()
        {
            //Factory.GetDataProvider().GalleryControlSetting_Save(this);
              using (var repo = new GalleryControlSettingRepository())
              {
            repo.Save(this);
              }

              // Clear the settings stored in static variables so they are retrieved from the data store during the next access.
              Factory.ClearGalleryControlSettingsCache();
        }