Esempio n. 1
0
        /// <summary>
        /// Extension method to use default role configuration resource files
        /// </summary>
        /// <param name="roles">MergeRoles, Flag enum with one or more roles</param>
        /// <param name="append">true = add, false = overwrite existing </param>
        /// <param name="rolesFilter">Dictionary of roles to OutPutFilters to use for merge, overwrites current assigned dictionary</param>
        public void ApplyRoleFilters(RoleFilter roles, bool append = false, Dictionary <RoleFilter, OutPutFilters> rolesFilter = null)
        {
            if (rolesFilter != null)
            {
                RolesFilterHolder = rolesFilter;
            }

            bool init = append ? !this.IsEmpty(): false;

            OutPutFilters mergeFilter = null;

            foreach (RoleFilter role in Enum.GetValues(typeof(RoleFilter)))
            {
                if (roles.HasFlag(role))
                {
                    if (RolesFilterHolder.ContainsKey(role))
                    {
                        mergeFilter = RolesFilterHolder[role];
                    }
                    else
                    {   //load defaults
                        string mergeFile = GetDefaultRoleFile(role);
                        if (!string.IsNullOrEmpty(mergeFile))
                        {
                            mergeFilter             = new OutPutFilters(mergeFile, role);
                            RolesFilterHolder[role] = mergeFilter;
                        }
                    }
                    if (mergeFilter != null)
                    {
                        if (!init)
                        {
                            this.Copy(mergeFilter); //start a fresh
                            init = true;            //want to merge on next loop iteration
                        }
                        else
                        {
                            this.Merge(mergeFilter);
                        }
                    }
                    mergeFilter = null;
                }
            }
            //add the default property filters
            OutPutFilters defaultPropFilters = new OutPutFilters(null, RoleFilter.Unknown, ImportSet.PropertyFilters);

            this.Merge(defaultPropFilters);

            //save the applied roles at end as this.Copy(mergeFilter) would set to first role in RoleFilter
            AppliedRoles = roles;
        }
Esempio n. 2
0
        /// <summary>
        /// Extension method to use default role configuration resource files
        /// </summary>
        /// <param name="roles">MergeRoles, Flag enum with one or more roles</param>
        /// <param name="append">true = add, false = overwrite existing </param>
        /// <param name="rolesFilter">Dictionary of roles to OutPutFilters to use for merge, overwrites current assigned dictionary</param>
        public void ApplyRoleFilters(RoleFilter roles, bool append = false, Dictionary <RoleFilter, OutputFilters> rolesFilter = null)
        {
            if (rolesFilter != null)
            {
                RolesFilterHolder = rolesFilter;
            }

            var init = append && !IsEmpty();

            OutputFilters mergeFilter = null;

            foreach (RoleFilter role in Enum.GetValues(typeof(RoleFilter)))
            {
                if (!roles.HasFlag(role))
                {
                    continue;
                }
                if (RolesFilterHolder.ContainsKey(role))
                {
                    mergeFilter = RolesFilterHolder[role];
                }
                else
                {
                    // load defaults
                    mergeFilter             = GetDefaults(role, _log);
                    RolesFilterHolder[role] = mergeFilter;
                }
                if (mergeFilter != null)
                {
                    if (!init)
                    {
                        Copy(mergeFilter); //start a fresh
                        init = true;       //want to merge on next loop iteration
                    }
                    else
                    {
                        Merge(mergeFilter);
                    }
                }
                mergeFilter = null;
            }
            //add the default property filters
            OutputFilters defaultPropFilters = new OutputFilters(null, _log, RoleFilter.Unknown, ImportSet.PropertyFilters);

            Merge(defaultPropFilters);

            //save the applied roles at end as this.Copy(mergeFilter) would set to first role in RoleFilter
            AppliedRoles = roles;
        }
Esempio n. 3
0
        /// <summary>
        /// Get stored role filter
        /// </summary>
        /// <param name="role">RoleFilter with single flag(role) set</param>
        /// <returns>OutPutFilters</returns>
        public OutPutFilters GetRoleFilter(RoleFilter role)
        {
            if ((role & (role - 1)) != 0)
            {
                throw new ArgumentException("More than one flag set on role");
            }

            if (RolesFilterHolder.ContainsKey(role))
            {
                return(RolesFilterHolder[role]);
            }
            //load defaults
            var objFilter = GetDefaults(role);

            if (objFilter != null)
            {
                RolesFilterHolder[role] = objFilter;
            }
            return(RolesFilterHolder[role]);
        }