示例#1
0
        public RoutineIncludeExcludeInstruction ApplyRules(Application app, JsFile jsFileContext)
        {
            var instruction = new RoutineIncludeExcludeInstruction();

            // apply Metadata first
            if (this.jsDALMetadata != null && this.jsDALMetadata.jsDAL != null)
            {
                if (this.jsDALMetadata.jsDAL != null)
                {
                    if (this.jsDALMetadata.jsDAL.exclude ?? false)
                    {
                        instruction.Source   = RoutineIncludeExcludeInstructionSource.DatabaseMetadata;
                        instruction.Excluded = this.jsDALMetadata.jsDAL.exclude;
                        if (instruction.Excluded ?? false)
                        {
                            instruction.Reason = "T-SQL metadata";
                        }
                    }
                    else if (!this.jsDALMetadata.jsDAL.include ?? false)
                    {
                        instruction.Source   = RoutineIncludeExcludeInstructionSource.DatabaseMetadata;
                        instruction.Included = this.jsDALMetadata.jsDAL.include;
                        if (instruction.Included ?? false)
                        {
                            instruction.Reason = "T-SQL metadata";
                        }
                    }
                }
            }

            if (instruction.Reason != null)
            {
                return(instruction);
            }

            // apply DB source level
            foreach (var dbRule in app.Rules)
            {
                if (dbRule == null)
                {
                    continue;
                }

                if (dbRule.Apply(this))
                {
                    if (app.DefaultRuleMode == (int)DefaultRuleMode.ExcludeAll)
                    {
                        instruction.Included = true;
                        instruction.Reason   = dbRule.ToString();
                    }
                    else if (app.DefaultRuleMode == (int)DefaultRuleMode.IncludeAll)
                    {
                        instruction.Excluded = true;
                        instruction.Reason   = dbRule.ToString();
                    }
                    else
                    {
                        throw new Exception("Unsupported DefaultRuleMode: " + app.DefaultRuleMode);
                    }

                    instruction.Rule   = dbRule;
                    instruction.Source = RoutineIncludeExcludeInstructionSource.DbSourceLevel;

                    return(instruction);
                }
            }
            ;



            if (instruction.Rule != null)
            {
                return(instruction);
            }

            // apply JSFile level
            if (jsFileContext != null)
            {
                foreach (var fileRule in jsFileContext.Rules)
                {
                    if (fileRule == null)
                    {
                        continue;
                    }

                    if (fileRule.Apply(this))
                    {
                        if (app.DefaultRuleMode == (int)DefaultRuleMode.ExcludeAll)
                        {
                            instruction.Included = true;
                            instruction.Reason   = fileRule.ToString(); // TODO: Consider recording a more substantial reference to the rule
                        }
                        else if (app.DefaultRuleMode == (int)DefaultRuleMode.IncludeAll)
                        {
                            instruction.Excluded = true;
                            instruction.Reason   = fileRule.ToString();
                        }
                        else
                        {
                            throw new Exception("Unsupported DefaultRuleMode: " + app.DefaultRuleMode);
                        }

                        instruction.Rule   = fileRule;
                        instruction.Source = RoutineIncludeExcludeInstructionSource.JsFileLevel;

                        return(instruction);
                    }
                }
                ;
            }

            if (app.DefaultRuleMode == (int)DefaultRuleMode.ExcludeAll)
            {
                instruction.Excluded = true;
            }
            else
            {
                instruction.Included = true;
            }

            instruction.Rule   = null;
            instruction.Source = RoutineIncludeExcludeInstructionSource.DbSourceLevel;
            instruction.Reason = "Default";
            return(instruction);
        }
示例#2
0
        public static RoutineIncludeExcludeInstruction Create(CachedRoutine routine, List <BaseRule> appRules, DefaultRuleMode defaultRuleMode, List <BaseRule> fileRules = null)
        {
            var instruction = new RoutineIncludeExcludeInstruction();

            // apply Metadata first
            if (routine.jsDALMetadata != null && routine.jsDALMetadata.jsDAL != null)
            {
                if (routine.jsDALMetadata.jsDAL != null)
                {
                    if (routine.jsDALMetadata.jsDAL.exclude ?? false)
                    {
                        instruction.Source   = RoutineIncludeExcludeInstructionSource.DatabaseMetadata;
                        instruction.Excluded = routine.jsDALMetadata.jsDAL.exclude;
                        if (instruction.Excluded ?? false)
                        {
                            instruction.Reason = "T-SQL metadata";
                        }
                    }
                    else if (!routine.jsDALMetadata.jsDAL.include ?? false)
                    {
                        instruction.Source   = RoutineIncludeExcludeInstructionSource.DatabaseMetadata;
                        instruction.Included = routine.jsDALMetadata.jsDAL.include;
                        if (instruction.Included ?? false)
                        {
                            instruction.Reason = "T-SQL metadata";
                        }
                    }
                }
            }

            if (instruction.Reason != null)
            {
                return(instruction);
            }

            // always apply APP-level rules first
            foreach (var rule in appRules)
            {
                if (rule.Apply(routine))
                {
                    if (defaultRuleMode == DefaultRuleMode.ExcludeAll)
                    {
                        instruction.Included = true;
                        instruction.Reason   = rule.ToString();
                    }
                    else if (defaultRuleMode == DefaultRuleMode.IncludeAll)
                    {
                        instruction.Excluded = true;
                        instruction.Reason   = rule.ToString();
                    }
                    else
                    {
                        throw new Exception("Unsupported DefaultRuleMode: " + defaultRuleMode.ToString());
                    }

                    instruction.Rule   = rule;
                    instruction.Source = RoutineIncludeExcludeInstructionSource.DbSourceLevel;

                    return(instruction);
                }
            }
            ;

            if (instruction.Rule != null)
            {
                return(instruction);
            }

            // apply JSFile level
            if (fileRules != null)
            {
                foreach (var fileRule in fileRules)
                {
                    if (fileRule == null)
                    {
                        continue;
                    }

                    if (fileRule.Apply(routine))
                    {
                        if (defaultRuleMode == DefaultRuleMode.ExcludeAll)
                        {
                            instruction.Included = true;
                            instruction.Reason   = fileRule.ToString(); // TODO: Consider recording a more substantial reference to the rule
                        }
                        else if (defaultRuleMode == DefaultRuleMode.IncludeAll)
                        {
                            instruction.Excluded = true;
                            instruction.Reason   = fileRule.ToString();
                        }
                        else
                        {
                            throw new Exception("Unsupported DefaultRuleMode: " + defaultRuleMode.ToString());
                        }

                        instruction.Rule   = fileRule;
                        instruction.Source = RoutineIncludeExcludeInstructionSource.JsFileLevel;

                        return(instruction);
                    }
                }
                ;
            }

            if (defaultRuleMode == DefaultRuleMode.ExcludeAll)
            {
                instruction.Excluded = true;
            }
            else
            {
                instruction.Included = true;
            }

            instruction.Rule   = null;
            instruction.Source = RoutineIncludeExcludeInstructionSource.DbSourceLevel;
            instruction.Reason = "Default";

            return(instruction);
        }