Example #1
0
        internal static void AttributeWithoutTable(List <KBObject> objs, IOutputService output)
        {
            List <Artech.Genexus.Common.Objects.Attribute> attTodos = new List <Artech.Genexus.Common.Objects.Attribute>();

            KBModel model = null;

            foreach (KBObject obj in objs)
            {
                model = obj.Model;
                if (obj is Artech.Genexus.Common.Objects.Attribute)
                {
                    attTodos.Add((Artech.Genexus.Common.Objects.Attribute)obj);
                }
            }
            if (model != null)
            {
                foreach (Table t in Table.GetAll(model))
                {
                    foreach (EntityReference reference in t.GetReferences(LinkType.UsedObject))
                    {
                        KBObject objRef = KBObject.Get(model, reference.To);
                        if (objRef is Artech.Genexus.Common.Objects.Attribute)
                        {
                            Artech.Genexus.Common.Objects.Attribute a = (Artech.Genexus.Common.Objects.Attribute)objRef;
                            attTodos.Remove(a);
                        }
                    }
                }
            }
            foreach (Artech.Genexus.Common.Objects.Attribute att in attTodos)
            {
                OutputError err = new OutputError("Attribute without table: " + att.Name, MessageLevel.Error, new KBObjectAnyPosition(att));
                output.Add("KBDoctor", err);
            }
        }
Example #2
0
 internal static void SDTBasedOnAttDomain(List <KBObject> objs, IOutputService output)
 {
     foreach (KBObject obj in objs)
     {
         if (obj is SDT)
         {
             SDTStructurePart sdtstruct         = obj.Parts.Get <SDTStructurePart>();
             bool             hasItemNotBasedOn = false;
             string           itemnames         = "";
             foreach (IStructureItem structItem in sdtstruct.Root.Items)
             {
                 if (structItem is SDTItem)
                 {
                     SDTItem sdtItem = (SDTItem)structItem;
                     if (sdtItem.BasedOn == null && sdtItem.AttributeBasedOn == null && Utility.TypeHasToBeInDomain(sdtItem.Type))
                     {
                         hasItemNotBasedOn = true;
                         itemnames        += sdtItem.Name + " ";
                     }
                 }
             }
             if (hasItemNotBasedOn)
             {
                 OutputError err = new OutputError("SDT with items without domain: " + itemnames, MessageLevel.Warning, new KBObjectAnyPosition(obj));
                 output.Add("KBDoctor", err);
             }
         }
     }
 }
Example #3
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 #4
0
 internal static void isInModule(List <KBObject> objs, IOutputService output)
 {
     foreach (KBObject obj in objs)
     {
         if (obj.Module.Description == "Root Module")
         {
             OutputError err = new OutputError("Object without module.", MessageLevel.Warning, new KBObjectAnyPosition(obj));
             output.Add("KBDoctor", err);
         }
     }
 }
Example #5
0
        private static List <KBObject> GetObjectsWithProblems(List <KBObject> objs, IOutputService output)
        {
            int             numObj              = 0;
            int             objWithProblems     = 0;
            List <KBObject> objectsWithProblems = new List <KBObject>();

            foreach (KBObject obj in objs)
            {
                ICallableObject callableObject = obj as ICallableObject;

                if (callableObject != null)
                {
                    numObj += 1;
                    if ((numObj % 100) == 0)
                    {
                        output.AddLine("KBDoctor", "Processing " + obj.Name);
                    }
                    foreach (Signature signature in callableObject.GetSignatures())
                    {
                        Boolean someInOut = false;
                        foreach (Parameter parm in signature.Parameters)
                        {
                            if (parm.Accessor.ToString() == "PARM_INOUT")
                            {
                                someInOut = true;
                                break;
                            }
                        }
                        if (someInOut)
                        {
                            string ruleParm = Utility.ExtractRuleParm(obj);
                            if (ruleParm != "")
                            {
                                int countparms     = ruleParm.Split(new char[] { ',' }).Length;
                                int countsemicolon = ruleParm.Split(new char[] { ':' }).Length - 1;
                                if (countparms != countsemicolon)
                                {
                                    objWithProblems += 1;
                                    objectsWithProblems.Add(obj);
                                    OutputError err = new OutputError("Parameter without IN/OUT/INOUT ", MessageLevel.Error, new  KBObjectPosition(obj.Parts.Get <RulesPart>()));
                                    output.Add("KBDoctor", err);
                                }
                            }
                        }
                    }
                }
            }

            return(objectsWithProblems);
        }
Example #6
0
        internal static void AttributeHasDomain(List <KBObject> objs, IOutputService output)
        {
            foreach (KBObject obj in objs)
            {
                if (obj is Artech.Genexus.Common.Objects.Attribute)
                {
                    Artech.Genexus.Common.Objects.Attribute a = (Artech.Genexus.Common.Objects.Attribute)obj;
                    string Picture   = Utility.ReturnPicture(a);
                    bool   isSubtype = Utility.AttIsSubtype(a);

                    if ((a.DomainBasedOn == null) && !isSubtype && Utility.AttHasToBeInDomain(a))
                    {
                        OutputError err = new OutputError("Attribute without domain: " + a.Name, MessageLevel.Warning, new KBObjectAnyPosition(obj));
                        output.Add("KBDoctor", err);
                    }
                }
            }
        }
Example #7
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 #8
0
        internal static void CommitOnExit(List <KBObject> objs, IOutputService output)
        {
            bool commitOnExit;

            foreach (KBObject obj in objs)
            {
                if (obj is Procedure)
                {
                    object aux = obj.GetPropertyValue("CommitOnExit");
                    if (aux != null)
                    {
                        commitOnExit = aux.ToString() == "Yes";
                        if (commitOnExit)
                        {
                            OutputError wrn = new OutputError("Commit on EXIT = YES ", MessageLevel.Warning, new KBObjectAnyPosition(obj));
                            output.Add("KBDoctor", wrn);
                        }
                    }
                }
            }
        }
Example #9
0
 internal static void ObjectsWithVarNotBasedOnAtt(List <KBObject> objs, IOutputService output)
 {
     foreach (KBObject obj in objs)
     {
         string  vnames    = "";
         Boolean hasErrors = false;
         Boolean SaveObj   = false;
         if (isGenerated(obj) && (obj is Transaction || obj is WebPanel || obj is WorkPanel || obj is Procedure))
         {
             string        pic2 = (string)obj.GetPropertyValue("ATT_PICTURE");
             VariablesPart vp   = obj.Parts.Get <VariablesPart>();
             if (vp != null)
             {
                 foreach (Variable v in vp.Variables)
                 {
                     if ((!v.IsStandard) && Utility.VarHasToBeInDomain(v))
                     {
                         string attname = (v.AttributeBasedOn == null) ? "" : v.AttributeBasedOn.Name;
                         string domname = (v.DomainBasedOn == null) ? "" : v.DomainBasedOn.Name;
                         if (attname == "" && domname == "")
                         {
                             string vname = v.Name.ToLower();
                             vnames   += vname + " ";
                             hasErrors = true;
                         }
                     }
                 }
             }
             if (hasErrors)
             {
                 OutputError err = new OutputError("Variables not based in attributes or domain: " + vnames, MessageLevel.Error, new KBObjectPosition(vp));
                 output.Add("KBDoctor", err);
             }
         }
     }
 }
Example #10
0
        public static void OutputError(OutputError oe)
        {
            IOutputService output = NewKBDoctorOutput();

            output.Add("KBDoctor", oe);
        }