Exemple #1
0
        public CommonReturnValue AddJsFile(string name)
        {
            if (string.IsNullOrWhiteSpace(name) || name.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0)
            {
                return(CommonReturnValue.UserError("Filenames may not be empty or contain special characters. Valid characters include A to Z and 0 to 9."));
            }

            if (this.JsFiles == null)
            {
                this.JsFiles = new List <JsFile>();
            }

            if (!name.ToLower().Trim().EndsWith(".js"))
            {
                name = name.Trim() + ".js";
            }

            var existing = this.JsFiles.FirstOrDefault(f => f.Filename.ToLower() == name.ToLower());

            if (existing != null)
            {
                return(CommonReturnValue.UserError($"The output file '{name}' already exists against this data source."));
            }

            var jsfile = new JsFile();

            jsfile.Filename = name;
            jsfile.Id       = ShortId.Generate();

            this.JsFiles.Add(jsfile);

            return(CommonReturnValue.Success());
        }
Exemple #2
0
        public void ApplyRules(JsFile jsFileContext)
        {
            throw new NotImplementedException();
            //TODO: MOVE TO CORRECT LEVEL..END POINT??? dont think endpoint level but across files...ugh

            /*******
             * if (this.CachedRoutineList == null) return;
             *
             * foreach (var routine in this.CachedRoutineList)
             * {
             *  if (routine.RuleInstructions == null) continue;
             *  if (routine.RuleInstructions.Count == 1 && routine.RuleInstructions.First().Key == null)
             *      continue; // PL: No idea why this happens but when no rules exist RuleInstructions contains a single KeyValue pair that are both null...this causes routine.RuleInstructions[jsFileContext] to hang
             *
             *  routine.RuleInstructions[jsFileContext] = null;
             *
             *  if (routine.IsDeleted) continue;
             *
             *  var instruction = routine.applyRules(this, jsFileContext);
             *
             *  routine.RuleInstructions[jsFileContext] = instruction;
             *
             * };
             *
             */
        }
Exemple #3
0
        public void ApplyRules(JsFile jsFileContext)
        {
            if (this.CachedRoutineList == null)
            {
                return;
            }

            foreach (var routine in this.CachedRoutineList)
            {
                if (routine.RuleInstructions == null)
                {
                    continue;
                }
                if (routine.RuleInstructions.Count == 1 && routine.RuleInstructions.First().Key == null)
                {
                    continue; // PL: No idea why this happens but when no rules exist RuleInstructions contains a single KeyValue pair that are both null...this causes routine.RuleInstructions[jsFileContext] to hang
                }
                routine.RuleInstructions[jsFileContext] = null;

                if (routine.IsDeleted)
                {
                    continue;
                }

                var instruction = routine.ApplyRules(this.Application, jsFileContext);

                routine.RuleInstructions[jsFileContext] = instruction;
            }
            ;
        }
        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);
        }
Exemple #5
0
 public string MinifiedOutputFilePath(JsFile jsFile)
 {
     return(Path.Combine(this.OutputDir, jsFile.Filename.Substring(0, jsFile.Filename.Length - 3) + ".min.js"));
 }
Exemple #6
0
 public string OutputTypeScriptTypingsFilePath(JsFile jsFile)
 {
     return(Path.Combine(this.OutputDir, jsFile.Filename.Substring(0, jsFile.Filename.LastIndexOf('.')) + ".d.ts"));
 }
Exemple #7
0
 public string OutputFilePath(JsFile jsFile)
 {
     return(Path.Combine(this.OutputDir, jsFile.Filename));
 }