private void CheckForDefaultGalleryObjectMediaObjectConflict(IGalleryControlSettings gcs) { if (!gcs.MediaObjectId.HasValue) { return; // No default media object is specified, so there is nothing to test. } // If a media object is specified as the default gallery object, is it contained within the hierarchy of // the album we are deleting? IGalleryObject defaultGalleryMediaObject = GetDefaultGalleryMediaObject(gcs); if (defaultGalleryMediaObject != null) { IGalleryObject albumParent = defaultGalleryMediaObject.Parent; while (!(albumParent is NullGalleryObject)) { if (albumParent.Id == _albumToDelete.Id) { _validationFailure = true; _validationFailureReason = GalleryObjectDeleteValidationFailureReason.AlbumContainsDefaultGalleryObjectMediaObject; return; } albumParent = albumParent.Parent; } } }
private void CheckForDefaultGalleryObjectAlbumConflict(IGalleryControlSettings gcs) { if (!gcs.AlbumId.HasValue) { return; // No default album is specified, so there is nothing to test. } // Test #1: If an album is specified as the default gallery object, is it the album we are deleting? if (gcs.AlbumId.Value == _albumToDelete.Id) { _validationFailure = true; _validationFailureReason = GalleryObjectDeleteValidationFailureReason.AlbumSpecifiedAsDefaultGalleryObject; return; } // Test #2: If an album is specified as the default gallery object, is it contained within the hierarchy of // the album we are deleting? IGalleryObject defaultGalleryAlbum = GetDefaultGalleryAlbum(gcs); if (defaultGalleryAlbum != null) { IGalleryObject albumParent = defaultGalleryAlbum.Parent; while (!(albumParent is NullGalleryObject)) { if (albumParent.Id == _albumToDelete.Id) { _validationFailure = true; _validationFailureReason = GalleryObjectDeleteValidationFailureReason.AlbumContainsDefaultGalleryObjectAlbum; return; } albumParent = albumParent.Parent; } } }
/// <summary> /// Adds the specified gallery control settings. /// </summary> /// <param name="item">The gallery control settings to add.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="item" /> is null.</exception> public void Add(IGalleryControlSettings item) { if (item == null) { throw new ArgumentNullException(nameof(item), "Cannot add null to an existing GalleryControlSettingsCollection. Items.Count = " + _items.Count); } _items.TryAdd(item.ControlId.ToLowerInvariant(), item); }
private void DataBindBehaviorFirstTime() { IGalleryControlSettings controlSettings = GalleryControl.GalleryControlSettings; chkAllowUrlOverride.Checked = (!controlSettings.AllowUrlOverride.HasValue || controlSettings.AllowUrlOverride.Value); DataBindOverridableSettingsFirstTime(); SetOverrideCheckboxFirstTime(); }
/// <summary> /// Assigns the <paramref name="value" /> to the specified <paramref name="property" /> of the <paramref name="galleryControlSetting" /> /// instance. The <paramref name="value" /> is converted to the appropriate enumeration before assignment. /// </summary> /// <param name="galleryControlSetting">The gallery control setting instance containing the <paramref name="property" /> to assign.</param> /// <param name="property">The property to assign the <paramref name="value" /> to.</param> /// <param name="value">The value to assign to the <paramref name="property" />.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="value" /> cannot be parsed into a /// <see cref="SlideShowType" /> value.</exception> private static void AssignSlideShowTypeProperty(IGalleryControlSettings galleryControlSetting, PropertyInfo property, string value) { SlideShowType viewMode; try { viewMode = (SlideShowType)Enum.Parse(typeof(SlideShowType), value, true); } catch (ArgumentException ex) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, "GalleryControlSettings.AssignSlideShowTypeProperty cannot convert the string {0} to a SlideShowType enumeration value. The following values are valid: NotSet, Inline, FullScreen", value), ex); } property.SetValue(galleryControlSetting, viewMode, null); }
/// <summary> /// Assigns the <paramref name="value" /> to the specified <paramref name="property" /> of the <paramref name="galleryControlSetting" /> /// instance. The <paramref name="value" /> is converted to the appropriate enumeration before assignment. /// </summary> /// <param name="galleryControlSetting">The gallery control setting instance containing the <paramref name="property" /> to assign.</param> /// <param name="property">The property to assign the <paramref name="value" /> to.</param> /// <param name="value">The value to assign to the <paramref name="property" />.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="value" /> cannot be parsed into a /// <see cref="DisplayObjectType" /> value.</exception> private static void AssignDisplayObjectTypeTypeProperty(IGalleryControlSettings galleryControlSetting, PropertyInfo property, string value) { DisplayObjectType displayType; try { displayType = (DisplayObjectType)Enum.Parse(typeof(DisplayObjectType), value, true); } catch (ArgumentException ex) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, "GalleryControlSettings.AssignDisplayObjectTypeTypeProperty cannot convert the string {0} to a DisplayObjectType enumeration value. The following values are valid: Unknown, Thumbnail, Optimized, Original, External", value), ex); } property.SetValue(galleryControlSetting, displayType, null); }
/// <summary> /// Assigns the <paramref name="value" /> to the specified <paramref name="property" /> of the <paramref name="galleryControlSetting" /> /// instance. The <paramref name="value" /> is converted to the appropriate enumeration before assignment. /// </summary> /// <param name="galleryControlSetting">The gallery control setting instance containing the <paramref name="property" /> to assign.</param> /// <param name="property">The property to assign the <paramref name="value" /> to.</param> /// <param name="value">The value to assign to the <paramref name="property" />.</param> /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="value" /> cannot be parsed into a /// <see cref="ViewMode" /> value.</exception> private static void AssignViewModeProperty(IGalleryControlSettings galleryControlSetting, PropertyInfo property, string value) { ViewMode viewMode; try { viewMode = (ViewMode)Enum.Parse(typeof(ViewMode), value, true); } catch (ArgumentException ex) { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, "GalleryControlSettings.AssignViewModeProperty cannot convert the string {0} to a ViewMode enumeration value. The following values are valid: NotSet, Multiple, Single, SingleRandom", value), ex); } property.SetValue(galleryControlSetting, viewMode, null); }
private void SetOverrideCheckboxFirstTime() { IGalleryControlSettings settings = GalleryControl.GalleryControlSettings; bool areAnyGallerySettingsOverridden = (settings.ShowLeftPaneForAlbum.HasValue || settings.ShowLeftPaneForMediaObject.HasValue || settings.ShowCenterPane.HasValue || settings.ShowRightPane.HasValue || !String.IsNullOrEmpty(settings.TreeViewNavigateUrl) || settings.ShowHeader.HasValue || !String.IsNullOrEmpty(settings.GalleryTitle) || !String.IsNullOrEmpty(settings.GalleryTitleUrl) || settings.ShowLogin.HasValue || settings.ShowSearch.HasValue || settings.AllowAnonymousBrowsing.HasValue || settings.ShowRibbonToolbar.HasValue || settings.ShowAlbumBreadCrumb.HasValue || settings.ShowMediaObjectNavigation.HasValue || settings.ShowMediaObjectIndexPosition.HasValue || settings.ShowMediaObjectTitle.HasValue || settings.AutoPlaySlideShow.HasValue || settings.MediaViewSize != DisplayObjectType.Unknown || settings.SlideShowType != SlideShowType.NotSet || settings.SlideShowLoop.HasValue ); chkOverride.Checked = areAnyGallerySettingsOverridden; }
private void SetOverrideCheckboxFirstTime() { IGalleryControlSettings settings = GalleryControl.GalleryControlSettings; bool areAnyGallerySettingsOverridden = (settings.ShowLeftPaneForAlbum.HasValue || settings.ShowLeftPaneForMediaObject.HasValue || settings.ShowCenterPane.HasValue || settings.ShowRightPane.HasValue || !String.IsNullOrEmpty(settings.TreeViewNavigateUrl) || settings.ShowHeader.HasValue || !String.IsNullOrEmpty(settings.GalleryTitle) || !String.IsNullOrEmpty(settings.GalleryTitleUrl) || settings.ShowLogin.HasValue || settings.ShowSearch.HasValue || settings.AllowAnonymousBrowsing.HasValue || settings.ShowActionMenu.HasValue || settings.ShowAlbumBreadCrumb.HasValue || settings.ShowMediaObjectNavigation.HasValue || settings.ShowMediaObjectIndexPosition.HasValue || settings.ShowMediaObjectTitle.HasValue || settings.AutoPlaySlideShow.HasValue || settings.SlideShowType != SlideShowType.NotSet || settings.ShowMediaObjectToolbar.HasValue || settings.ShowUrlsButton.HasValue || settings.ShowSlideShowButton.HasValue || settings.ShowTransferMediaObjectButton.HasValue || settings.ShowCopyMediaObjectButton.HasValue || settings.ShowRotateMediaObjectButton.HasValue || settings.ShowDeleteMediaObjectButton.HasValue ); chkOverride.Checked = areAnyGallerySettingsOverridden; }
private void SetOverrideCheckbox() { IGalleryControlSettings settings = GalleryControl.GalleryControlSettings; bool areAnyGallerySettingsOverridden = (settings.ShowAlbumTreeViewForAlbum.HasValue || settings.ShowAlbumTreeViewForMediaObject.HasValue || settings.ShowHeader.HasValue || !String.IsNullOrEmpty(settings.GalleryTitle) || !String.IsNullOrEmpty(settings.GalleryTitleUrl) || settings.ShowLogin.HasValue || settings.ShowSearch.HasValue || settings.AllowAnonymousBrowsing.HasValue || settings.ShowActionMenu.HasValue || settings.ShowAlbumBreadCrumb.HasValue || settings.ShowMediaObjectNavigation.HasValue || settings.ShowMediaObjectIndexPosition.HasValue || settings.ShowMediaObjectTitle.HasValue || settings.AutoPlaySlideShow.HasValue || settings.ShowMediaObjectToolbar.HasValue || settings.ShowMetadataButton.HasValue || settings.ShowMediaObjectDownloadButton.HasValue || settings.ShowMediaObjectZipDownloadButton.HasValue || settings.ShowHighResImageButton.HasValue || settings.ShowPermalinkButton.HasValue || settings.ShowSlideShowButton.HasValue || settings.ShowTransferMediaObjectButton.HasValue || settings.ShowCopyMediaObjectButton.HasValue || settings.ShowRotateMediaObjectButton.HasValue || settings.ShowDeleteMediaObjectButton.HasValue ); chkOverride.Checked = areAnyGallerySettingsOverridden; }
private IGalleryObject GetDefaultGalleryAlbum(IGalleryControlSettings gcs) { if (!gcs.AlbumId.HasValue) { return(null); // We should never get here because the calling method should have already verified there is a value, but we'll be extra safe. } IGalleryObject defaultGalleryAlbum = null; try { defaultGalleryAlbum = Factory.LoadAlbumInstance(gcs.AlbumId.Value); } catch (InvalidAlbumException ex) { // Album doesn't exist. This won't prevent us from deleting the album but we should note the issue, since // it can cause problems to specify an album that doesn't exist for the default gallery object. string galleryDescription = Factory.LoadGallery(_albumToDelete.GalleryId).Description; string msg = String.Format(CultureInfo.CurrentCulture, Resources.Error_Default_Gallery_Object_Album_Invalid_Ex_Msg, galleryDescription, _albumToDelete.Id); EventController.RecordError(new BusinessException(msg, ex), AppSetting.Instance, _albumToDelete.GalleryId, Factory.LoadGallerySettings()); } return(defaultGalleryAlbum); }
private IGalleryObject GetDefaultGalleryAlbum(IGalleryControlSettings gcs) { if (!gcs.AlbumId.HasValue) { return(null); // We should never get here because the calling method should have already verified there is a value, but we'll be extra safe. } IGalleryObject defaultGalleryAlbum = null; try { defaultGalleryAlbum = Factory.LoadAlbumInstance(gcs.AlbumId.Value); } catch (InvalidAlbumException ex) { // Album doesn't exist. This won't prevent us from deleting the album but we should note the issue, since // it can cause problems to specify an album that doesn't exist for the default gallery object. string galleryDescription = Factory.LoadGallery(_albumToDelete.GalleryId).Description; string msg = $"Default Gallery Asset Album Invalid: The gallery '{galleryDescription}' has an album ID specified ({_albumToDelete.Id}) as the default gallery asset and it does not match an existing album. Review this setting in the administration area."; EventController.RecordError(new BusinessException(msg, ex), AppSetting.Instance, _albumToDelete.GalleryId, Factory.LoadGallerySettings()); } return(defaultGalleryAlbum); }
/// <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> /// <param name="galleryControlSettings">An instance of <see cref="IGalleryControlSettings"/> to persist to the data store.</param> public abstract void GalleryControlSetting_Save(IGalleryControlSettings galleryControlSettings);
/// <summary> /// Persist the current gallery control settings to the data store. /// </summary> /// <param name="galleryControlSettings">An instance of <see cref="IGalleryControlSettings"/> to persist to the data store.</param> public override void GalleryControlSetting_Save(IGalleryControlSettings galleryControlSettings) { GalleryData.SaveGalleryControlSettings(galleryControlSettings); }
/// <summary> /// Persists the gallery control settings to the data store. /// </summary> /// <param name="galleryControlSettings">The gallery control settings.</param> internal static void SaveGalleryControlSettings(IGalleryControlSettings galleryControlSettings) { using (SqlConnection cn = SqlDataProvider.GetDbConnection()) { using (SqlCommand cmd = GetCommandGalleryControlSettingUpdate(cn)) { cmd.Parameters["@ControlId"].Value = galleryControlSettings.ControlId; string[] propertiesToExclude = new[] { "GalleryControlSettingId", "ControlId", "HasValues" }; string viewModeType = typeof(ViewMode).ToString(); Type gsType = galleryControlSettings.GetType(); string boolType = typeof(bool).ToString(); string boolNullableType = typeof(bool?).ToString(); string intType = typeof(int).ToString(); string intNullableType = typeof(int?).ToString(); string stringType = typeof(string).ToString(); cn.Open(); foreach (PropertyInfo prop in gsType.GetProperties()) { if (Array.IndexOf(propertiesToExclude, prop.Name) >= 0) { continue; // Skip this one. } object objPropValue = prop.GetValue(galleryControlSettings, null); string propValue = null; if (objPropValue != null) { if (prop.PropertyType.FullName == null) { continue; } if (prop.PropertyType.FullName.Equals(boolType) || prop.PropertyType.FullName.Equals(boolNullableType)) { propValue = Convert.ToBoolean(objPropValue, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(intType) || prop.PropertyType.FullName.Equals(intNullableType)) { propValue = Convert.ToInt32(objPropValue, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(stringType)) { propValue = Convert.ToString(objPropValue, CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(viewModeType)) { // Only save ViewMode if it has a non-default value; otherwise set it to null so it is deleted (if it even exists). ViewMode viewMode = (ViewMode)Enum.Parse(typeof(ViewMode), objPropValue.ToString(), true); if (viewMode != ViewMode.NotSet) { propValue = viewMode.ToString(); } } else { propValue = objPropValue.ToString(); } } // Update the item. if (propValue != null) { cmd.Parameters["@SettingValue"].Value = propValue; } else { cmd.Parameters["@SettingValue"].Value = DBNull.Value; } cmd.Parameters["@SettingName"].Value = prop.Name; cmd.ExecuteNonQuery(); //if (propValue == null) //{ // // Include this only for debug purposes. // System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true); // string msg = String.Format(CultureInfo.CurrentCulture, "Deleted Gallery Control Setting \"{0}\". Stack trace: {1}", prop.Name, st); // ErrorHandler.Error.Record(new DataException(msg)); //} } } } }
/// <summary> /// Persist the current gallery control settings to the data store. /// </summary> /// <param name="galleryControlSettings">An instance of <see cref="IGalleryControlSettings"/> to persist to the data store.</param> public override void GalleryControlSetting_Save(IGalleryControlSettings galleryControlSettings) { using (GspContext ctx = new GspContext()) { string[] propertiesToExclude = new[] { "GalleryControlSettingId", "ControlId" }; Type gsType = galleryControlSettings.GetType(); string viewModeType = typeof(ViewMode).ToString(); string boolType = typeof(bool).ToString(); string boolNullableType = typeof(bool?).ToString(); string intType = typeof(int).ToString(); string intNullableType = typeof(int?).ToString(); string stringType = typeof(string).ToString(); ctx.GalleryControlSettings.Load(); foreach (PropertyInfo prop in gsType.GetProperties()) { if (Array.IndexOf(propertiesToExclude, prop.Name) >= 0) { continue; // Skip this one. } // Get a reference to the database record (won't exist for new items). string propName = prop.Name; GalleryControlSettingDto gcsDto = (from g in ctx.GalleryControlSettings.Local where g.ControlId == galleryControlSettings.ControlId && g.SettingName == propName select g).FirstOrDefault(); object objPropValue = prop.GetValue(galleryControlSettings, null); if (objPropValue != null) { string propValue; if (prop.PropertyType.FullName == null) { continue; } if (prop.PropertyType.FullName.Equals(boolType) || prop.PropertyType.FullName.Equals(boolNullableType)) { propValue = Convert.ToBoolean(objPropValue, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(intType) || prop.PropertyType.FullName.Equals(intNullableType)) { propValue = Convert.ToInt32(objPropValue, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(stringType)) { propValue = Convert.ToString(objPropValue, CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(viewModeType)) { // Only save ViewMode if it has a non-default value. ViewMode viewMode = (ViewMode)Enum.Parse(typeof(ViewMode), prop.GetValue(galleryControlSettings, null).ToString(), true); if (viewMode == ViewMode.NotSet) { // Property not assigned. Delete the record. if (gcsDto != null) { ctx.GalleryControlSettings.Remove(gcsDto); } continue; // We're done with this property, so let's move on to the next one. } propValue = viewMode.ToString(); } else { propValue = prop.GetValue(galleryControlSettings, null).ToString(); } // Insert or update the item. if (gcsDto == null) { gcsDto = new GalleryControlSettingDto { ControlId = galleryControlSettings.ControlId, SettingName = propName, SettingValue = propValue }; ctx.GalleryControlSettings.Add(gcsDto); } else { gcsDto.SettingValue = propValue; } } else { // Property not assigned. Delete the record. if (gcsDto != null) { ctx.GalleryControlSettings.Remove(gcsDto); } // Include this only for debug purposes. //System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true); //string msg = String.Format(CultureInfo.CurrentCulture, "Deleted Gallery Control Setting \"{0}\". Stack trace: {1}", prop.Name, st); //errMessages.Add(msg); } } ctx.SaveChanges(); } }
private IGalleryObject GetDefaultGalleryMediaObject(IGalleryControlSettings gcs) { if (!gcs.MediaObjectId.HasValue) { return null; // We should never get here because the calling method should have already verified there is a value, but we'll be extra safe. } IGalleryObject defaultGalleryMediaObject = null; try { defaultGalleryMediaObject = Factory.LoadMediaObjectInstance(gcs.MediaObjectId.Value); } catch (InvalidMediaObjectException ex) { // Media object doesn't exist. This won't prevent us from deleting the album but we should note the issue, since // it can cause problems to specify a media object that doesn't exist for the default gallery object. string galleryDescription = Factory.LoadGallery(_albumToDelete.GalleryId).Description; string msg = String.Format(CultureInfo.CurrentCulture, Resources.Error_Default_Gallery_Object_MediaObject_Invalid_Ex_Msg, galleryDescription, _albumToDelete.Id); ErrorHandler.Error.Record(new BusinessException(msg, ex), _albumToDelete.GalleryId, Factory.LoadGallerySettings(), AppSetting.Instance); } return defaultGalleryMediaObject; }
/// <summary> /// Persist the current gallery control settings to the data store. /// </summary> /// <param name="galleryControlSettings">An instance of <see cref="IGalleryControlSettings"/> to persist to the data store.</param> public void Save(IGalleryControlSettings galleryControlSettings) { var propertiesToExclude = new[] { "GalleryControlSettingId", "ControlId" }; Type gsType = galleryControlSettings.GetType(); string viewModeType = typeof(ViewMode).ToString(); string displayObjectTypeType = typeof(DisplayObjectType).ToString(); string slideShowTypeType = typeof(SlideShowType).ToString(); string boolType = typeof(bool).ToString(); string boolNullableType = typeof(bool?).ToString(); string intType = typeof(int).ToString(); string intNullableType = typeof(int?).ToString(); string stringType = typeof(string).ToString(); //ctx.GalleryControlSettings.Load(); this.Context.GalleryControlSettings.Load(); foreach (PropertyInfo prop in gsType.GetProperties()) { if (Array.IndexOf(propertiesToExclude, prop.Name) >= 0) { continue; // Skip this one. } // Get a reference to the database record (won't exist for new items). string propName = prop.Name; //GalleryControlSettingDto gcsDto = (from g in ctx.GalleryControlSettings.Local // where g.ControlId == galleryControlSettings.ControlId && g.SettingName == propName // select g).FirstOrDefault(); GalleryControlSettingDto gcsDto = Context.GalleryControlSettings.Local.FirstOrDefault(g => g.ControlId == galleryControlSettings.ControlId && g.SettingName == propName); object objPropValue = prop.GetValue(galleryControlSettings, null); if (objPropValue != null) { string propValue; if (prop.PropertyType.FullName == null) { continue; } if (prop.PropertyType.FullName.Equals(boolType) || prop.PropertyType.FullName.Equals(boolNullableType)) { propValue = Convert.ToBoolean(objPropValue, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(intType) || prop.PropertyType.FullName.Equals(intNullableType)) { propValue = Convert.ToInt32(objPropValue, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(stringType)) { propValue = Convert.ToString(objPropValue, CultureInfo.InvariantCulture); } else if (prop.PropertyType.FullName.Equals(viewModeType)) { // Only save ViewMode if it has a non-default value. var viewMode = (ViewMode)Enum.Parse(typeof(ViewMode), prop.GetValue(galleryControlSettings, null).ToString(), true); if (viewMode == ViewMode.NotSet) { // Property not assigned. Delete the record. if (gcsDto != null) { Delete(gcsDto); } continue; // We're done with this property, so let's move on to the next one. } propValue = viewMode.ToString(); } else if (prop.PropertyType.FullName.Equals(displayObjectTypeType)) { // Only save MediaViewSize if it has a non-default value. var dotType = (DisplayObjectType)Enum.Parse(typeof(DisplayObjectType), prop.GetValue(galleryControlSettings, null).ToString(), true); if (dotType == DisplayObjectType.Unknown) { // Property not assigned. Delete the record. if (gcsDto != null) { Delete(gcsDto); } continue; // We're done with this property, so let's move on to the next one. } propValue = dotType.ToString(); } else if (prop.PropertyType.FullName.Equals(slideShowTypeType)) { // Only save SlideShowType if it has a non-default value. var ssType = (SlideShowType)Enum.Parse(typeof(SlideShowType), prop.GetValue(galleryControlSettings, null).ToString(), true); if (ssType == SlideShowType.NotSet) { // Property not assigned. Delete the record. if (gcsDto != null) { Delete(gcsDto); } continue; // We're done with this property, so let's move on to the next one. } propValue = ssType.ToString(); } else { propValue = prop.GetValue(galleryControlSettings, null).ToString(); } // Insert or update the item. if (gcsDto == null) { gcsDto = new GalleryControlSettingDto { ControlId = galleryControlSettings.ControlId, SettingName = propName, SettingValue = propValue }; Add(gcsDto); } else { gcsDto.SettingValue = propValue; } } else { // Property not assigned. Delete the record. if (gcsDto != null) { Delete(gcsDto); } // Include this only for debug purposes. //System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true); //string msg = String.Format(CultureInfo.CurrentCulture, "Deleted Gallery Control Setting \"{0}\". Stack trace: {1}", prop.Name, st); //errMessages.Add(msg); } } Save(); }