Esempio n. 1
0
        public static void SetFilterGlobalParameterValue(this DbContext context, string filterName, string parameterName, object value)
        {
            //  This is null when called during filter creation in OnModelCreating
            if (context != null)
            {
                context.Database.Initialize(false);
            }

            filterName = ScrubFilterName(filterName);

            if (string.IsNullOrEmpty(parameterName))
            {
                parameterName = GetDefaultParameterNameForFilter(filterName);
            }

            _GlobalParameterValues.AddOrUpdate(filterName,
                                               (f) =>
            {
                var newValues = new DynamicFilterParameters();
                newValues.SetParameter(parameterName, value);
                return(newValues);
            },
                                               (f, currValues) =>
            {
                currValues.SetParameter(parameterName, value);
                return(currValues);
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Globally disable the filter.  Can be enabled as needed via DbContext.EnableFilter().
        /// </summary>
        /// <param name="modelBuilder"></param>
        /// <param name="filterName"></param>
        public static void DisableFilterGlobally(this DbModelBuilder modelBuilder, string filterName)
        {
            filterName = ScrubFilterName(filterName);

            _GlobalParameterValues.AddOrUpdate(filterName,
                                               (f) =>
            {
                var newValues     = new DynamicFilterParameters();
                newValues.Enabled = false;
                return(newValues);
            },
                                               (f, currValues) =>
            {
                currValues.Enabled = false;
                return(currValues);
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Set the parameter for a filter within the current DbContext scope.  Once the DbContext is disposed, this
        /// parameter will no longer be in scope and will be removed.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="filterName"></param>
        /// <param name="parameterName"></param>
        /// <param name="value"></param>
        public static void SetFilterScopedParameterValue(this DbContext context, string filterName, string parameterName, object value)
        {
            context.Database.Initialize(false);

            filterName = ScrubFilterName(filterName);

            var filterParams = GetOrCreateScopedFilterParameters(context, filterName);

            if (string.IsNullOrEmpty(parameterName))
            {
                parameterName = GetDefaultParameterNameForFilter(filterName);
            }

            DynamicFilterParameters globalFilterParams = _GlobalParameterValues[filterName];        //  Already validated that this exists.

            if (!globalFilterParams.ParameterValues.ContainsKey(parameterName))
            {
                throw new ApplicationException(string.Format("Parameter {0} not found in Filter {1}", parameterName, filterName));
            }

            filterParams.SetParameter(parameterName, value);
        }