Example #1
0
        internal static void CheckComplexityMetrics(List <KBObject> objs, IOutputService output, int maxNestLevel, int maxComplexityLevel, int maxCodeBlock, int maxParametersCount)
        {
            foreach (KBObject obj in objs)
            {
                if (obj is Transaction || obj is WebPanel || obj is Procedure || obj is WorkPanel)
                {
                    if (isGenerated(obj) && !isGeneratedbyPattern(obj))
                    {
                        string source = Utility.ObjectSourceUpper(obj);
                        source = Utility.RemoveEmptyLines(source);

                        string sourceWOComments = Utility.ExtractComments(source);
                        sourceWOComments = Utility.RemoveEmptyLines(sourceWOComments);

                        int CodeBlock       = Utility.MaxCodeBlock(sourceWOComments);
                        int NestLevel       = Utility.MaxNestLevel(sourceWOComments);
                        int ComplexityLevel = Utility.ComplexityLevel(sourceWOComments);

                        KBObjectPart part = Utility.ObjectSourcePart(obj);

                        int parametersCount = ParametersCountObject(obj);
                        if (NestLevel > maxNestLevel)
                        {
                            OutputError err = new OutputError("Nested level too high (" + NestLevel.ToString() + "). Recommended max: " + maxNestLevel.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }
                        if (ComplexityLevel > maxComplexityLevel)
                        {
                            OutputError err = new OutputError("Complexity too high(" + ComplexityLevel.ToString() + ").Recommended max: " + maxComplexityLevel.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }

                        if (CodeBlock > maxCodeBlock)
                        {
                            OutputError err = new OutputError("Code block too large(" + CodeBlock.ToString() + ").Recommended max: " + maxCodeBlock.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }
                        if (parametersCount > maxParametersCount)
                        {
                            OutputError err = new OutputError("Too many parameters (" + parametersCount.ToString() + ").Recommended max: " + maxParametersCount.ToString(), MessageLevel.Error, new KBObjectPosition(part));
                            output.Add("KBDoctor", err);
                        }
                    }
                }
            }
        }
Example #2
0
 internal static void CodeCommented(List <KBObject> objs, IOutputService output)
 {
     foreach (KBObject obj in objs)
     {
         string source = Utility.ObjectSourceUpper(obj);
         source = Utility.RemoveEmptyLines(source);
         string codeCommented = Utility.CodeCommented(source);
         codeCommented = codeCommented.Replace("'", "");
         codeCommented = codeCommented.Replace(">", "");
         codeCommented = codeCommented.Replace("<", "");
         if (codeCommented != "")
         {
             KBObjectPart part = Utility.ObjectSourcePart(obj);
             OutputError  err  = new OutputError("Commented code", MessageLevel.Warning, new KBObjectPosition(part));
             output.Add("KBDoctor", err);
         }
     }
 }
Example #3
0
 internal String AppendTemplateOutputXml(KBObject obj, KBObjectPart part, PatternInstanceElement element, String template)
 {
     return AppendTemplateOutputInner(obj, part, element, template).InnerXml;
 }
Example #4
0
 internal XmlDocument AppendTemplateOutputInner(KBObject obj, KBObjectPart part, PatternInstanceElement element, String template)
 {
     Generator.GeneratorParameters parms = new Generator.GeneratorParameters();
     DefaultProvider.PrepareTemplateParameters(parms);
     parms.Properties["Object"] = obj;
     parms.Properties["Part"] = part;
     parms.Properties["Instance"] = Instance;
     parms.Properties["Element"] = element;
     StringBuilder sb = new StringBuilder();
     Heurys.Patterns.HPattern.HPatternTransactionUpdater.AppendTemplateOutput(sb, template, parms);
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.LoadXml(sb.ToString());
     return xmlDocument;
 }