/// <summary> /// Gets the date range represented by the listing mode, /// to allow migrating from old settings (<see cref="ListingMode"/>) to new settings (<see cref="DateRange"/>). /// </summary> /// <param name="moduleControl">The module control for which to get the date range.</param> /// <returns>A new <see cref="DateRange"/> instance</returns> private static DateRange GetDateRangeForListingMode(IModuleControlBase moduleControl) { DateRangeBound startRangeBound; DateRangeBound endRangeBound; #pragma warning disable 618 switch (DisplayModeOption.GetValueAsEnumFor <ListingMode>(moduleControl)) { case ListingMode.CurrentMonth: startRangeBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Day); endRangeBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Month); break; case ListingMode.Future: startRangeBound = DateRangeBound.CreateRelativeBound(1, DateInterval.Month); endRangeBound = DateRangeBound.CreateUnboundedBound(); break; case ListingMode.Past: startRangeBound = DateRangeBound.CreateUnboundedBound(); endRangeBound = DateRangeBound.CreateRelativeBound(0, DateInterval.Day); break; ////case ListingMode.All: default: startRangeBound = DateRangeBound.CreateUnboundedBound(); endRangeBound = DateRangeBound.CreateUnboundedBound(); break; } #pragma warning restore 618 return(new DateRange(startRangeBound, endRangeBound)); }
#pragma warning restore 618 /// <summary> /// Gets the <see cref="Categories"/> for the given <paramref name="moduleControl"/> as an <see cref="IEnumerable{T}"/> of <see cref="int"/> /// </summary> /// <param name="moduleControl">The module control.</param> /// <returns>The IDs of the categories that the module is to display, or an empty sequence to not filter the module by category</returns> public static IEnumerable <int> GetCategoriesFor(IModuleControlBase moduleControl) { var categoriesSettingValue = Categories.GetValueAsStringFor(moduleControl); return(string.IsNullOrEmpty(categoriesSettingValue) ? Enumerable.Empty <int>() : categoriesSettingValue.Split(',').Select(id => int.Parse(id, CultureInfo.InvariantCulture))); }
/// <summary> /// Sets the module's settings to the given <paramref name="range"/>. /// </summary> /// <param name="moduleControl">The module control.</param> /// <param name="range">The range to which the settings should be set.</param> /// <exception cref="ArgumentNullException">When <paramref name="range"/> is <c>null</c></exception> public static void SetDateRangeSettings(IModuleControlBase moduleControl, DateRange range) { if (range == null) { throw new ArgumentNullException("range"); } RangeStartRelativeAmount.Set(moduleControl, range.Start.RelativeAmount); RangeStartRelativeInterval.Set(moduleControl, range.Start.RelativeInterval); RangeStartSpecificDate.Set(moduleControl, range.Start.SpecificDate); RangeStartWindowAmount.Set(moduleControl, range.Start.WindowAmount); RangeStartWindowInterval.Set(moduleControl, range.Start.WindowInterval); RangeEndRelativeAmount.Set(moduleControl, range.End.RelativeAmount); RangeEndRelativeInterval.Set(moduleControl, range.End.RelativeInterval); RangeEndSpecificDate.Set(moduleControl, range.End.SpecificDate); RangeEndWindowAmount.Set(moduleControl, range.End.WindowAmount); RangeEndWindowInterval.Set(moduleControl, range.End.WindowInterval); }
/// <summary> /// Gets the date range for the given module. /// </summary> /// <param name="moduleControl">The module control.</param> /// <returns>The date range</returns> public static DateRange GetDateRangeFor(IModuleControlBase moduleControl) { if (!RangeStartRelativeAmount.IsSettingDefinedFor(moduleControl) && DisplayModeOption.IsSettingDefinedFor(moduleControl)) { var dateRange = GetDateRangeForListingMode(moduleControl); SetDateRangeSettings(moduleControl, dateRange); return(dateRange); } var startRangeBound = new DateRangeBound( GetValueAsNullableInt32(RangeStartRelativeAmount, moduleControl), GetValueAsNullableEnum(RangeStartRelativeInterval, moduleControl), GetValueAsNullableDateTime(RangeStartSpecificDate, moduleControl), GetValueAsNullableInt32(RangeStartWindowAmount, moduleControl), GetValueAsNullableEnum(RangeStartWindowInterval, moduleControl)); var endRangeBound = new DateRangeBound( GetValueAsNullableInt32(RangeEndRelativeAmount, moduleControl), GetValueAsNullableEnum(RangeEndRelativeInterval, moduleControl), GetValueAsNullableDateTime(RangeEndSpecificDate, moduleControl), GetValueAsNullableInt32(RangeEndWindowAmount, moduleControl), GetValueAsNullableEnum(RangeEndWindowInterval, moduleControl)); return(new DateRange(startRangeBound, endRangeBound)); }
/// <summary> /// Gets the CAPTCHA strategies. /// </summary> /// <param name="moduleControl">The module control.</param> /// <returns>A sequence of <see cref="RadCaptcha.ProtectionStrategies"/></returns> public static IEnumerable <RadCaptcha.ProtectionStrategies> GetCaptchaStrategies(IModuleControlBase moduleControl) { var commaDelimited = CaptchaStrategies.GetValueAsStringFor(moduleControl); if (string.IsNullOrEmpty(commaDelimited)) { return(Enumerable.Empty <RadCaptcha.ProtectionStrategies>()); } var split = commaDelimited.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return(from value in split where Enum.IsDefined(typeof(RadCaptcha.ProtectionStrategies), value) select(RadCaptcha.ProtectionStrategies) Enum.Parse(typeof(RadCaptcha.ProtectionStrategies), value)); }
/// <summary> /// Gets the CAPTCHA strategies. /// </summary> /// <param name="moduleControl">The module control.</param> /// <returns>A sequence of <see cref="RadCaptcha.ProtectionStrategies"/></returns> public static IEnumerable<RadCaptcha.ProtectionStrategies> GetCaptchaStrategies(IModuleControlBase moduleControl) { var commaDelimited = CaptchaStrategies.GetValueAsStringFor(moduleControl); if (string.IsNullOrEmpty(commaDelimited)) { return Enumerable.Empty<RadCaptcha.ProtectionStrategies>(); } var split = commaDelimited.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); return from value in split where Enum.IsDefined(typeof(RadCaptcha.ProtectionStrategies), value) select (RadCaptcha.ProtectionStrategies)Enum.Parse(typeof(RadCaptcha.ProtectionStrategies), value); }
/// <summary> /// Gets the value of this setting for the given <paramref name="moduleControl"/> as an <see cref="Enum"/> of <typeparamref name="TEnum"/>, /// or <see cref="Setting{T}.DefaultValue"/> if the setting hasn't been set or isn't an <see cref="Enum"/> of <typeparamref name="TEnum"/>. /// </summary> /// <typeparam name="TEnum">The type of the <see cref="Enum"/> to which the value should be converted.</typeparam> /// <param name="setting">The setting to get the value for.</param> /// <param name="moduleControl">A module control instance to which this setting applies.</param> /// <returns> /// The value of this setting for the given <paramref name="moduleControl"/> /// or <see cref="Setting{T}.DefaultValue"/> if the value does not exist yet or cannot be converted to a <typeparamref name="TEnum"/>, /// or <c>null</c> if <see cref="Setting{T}.DefaultValue"/> is not a <typeparamref name="TEnum"/>. /// </returns> /// <remarks> /// Adjusts for <see cref="Setting{T}.GetValueAsEnumFor{TEnum}(Engage.Dnn.Framework.IModuleControlBase)"/>'s assumption /// that a value of <c>null</c> is not valid and so should return <see cref="Setting{T}.DefaultValue"/> /// </remarks> private static TEnum?GetValueAsNullableEnum <TEnum>(Setting <TEnum?> setting, IModuleControlBase moduleControl) where TEnum : struct { return(setting.GetValueAsEnumFor(moduleControl.DesktopModuleName, moduleControl.ModuleConfiguration, setting.IsSettingDefinedFor(moduleControl) ? null : setting.DefaultValue)); }
/// <summary> /// Gets the value of this setting for the given <paramref name="moduleControl"/> as a <see cref="DateTime"/>, /// or <see cref="Setting{T}.DefaultValue"/> if the setting hasn't been set or isn't an <see cref="DateTime"/>. /// </summary> /// <param name="setting">The setting to get the value for.</param> /// <param name="moduleControl">A module control instance to which this setting applies.</param> /// <returns> /// The value of this setting for the given <paramref name="moduleControl"/> /// or <see cref="Setting{T}.DefaultValue"/> if the value does not exist yet or cannot be converted to a <see cref="DateTime"/>, /// or <c>null</c> if <see cref="Setting{T}.DefaultValue"/> is not a <see cref="DateTime"/>. /// </returns> /// <remarks> /// Adjusts for <see cref="Setting{T}.GetValueAsEnumFor{TEnum}(Engage.Dnn.Framework.IModuleControlBase)"/>'s assumption /// that a value of <c>null</c> is not valid and so should return <see cref="Setting{T}.DefaultValue"/> /// </remarks> private static DateTime?GetValueAsNullableDateTime(Setting <DateTime?> setting, IModuleControlBase moduleControl) { return(setting.GetValueAsDateTimeFor(moduleControl.DesktopModuleName, moduleControl.ModuleConfiguration, setting.IsSettingDefinedFor(moduleControl) ? null : setting.DefaultValue)); }
/// <summary> /// Gets the value of this setting for the given <paramref name="moduleControl"/> as an <see cref="int"/>, /// or <see cref="Setting{T}.DefaultValue"/> if the setting hasn't been set or isn't an <see cref="int"/>. /// </summary> /// <param name="setting">The setting to get the value for.</param> /// <param name="moduleControl">A module control instance to which this setting applies.</param> /// <returns> /// The value of this setting for the given <paramref name="moduleControl"/> /// or <see cref="Setting{T}.DefaultValue"/> if the value does not exist yet or cannot be converted to an <see cref="int"/>, /// or <c>null</c> if <see cref="Setting{T}.DefaultValue"/> is not an <see cref="int"/>. /// </returns> /// <remarks> /// Adjusts for <see cref="Setting{T}.GetValueAsEnumFor{TEnum}(Engage.Dnn.Framework.IModuleControlBase)"/>'s assumption /// that a value of <c>null</c> is not valid and so should return <see cref="Setting{T}.DefaultValue"/> /// </remarks> private static int?GetValueAsNullableInt32(Setting <int?> setting, IModuleControlBase moduleControl) { return(setting.GetValueAsInt32For(moduleControl.DesktopModuleName, moduleControl.ModuleConfiguration, setting.IsSettingDefinedFor(moduleControl) ? null : setting.DefaultValue)); }