예제 #1
0
        private static bool IsReferencedFromOutside(Module mdl, KBObject obj, out string objList)
        {
            if (obj is Table)
            {
                objList = obj.Name + " ";
            }
            else
            {
                objList = "";
            }

            bool   isReferencedFromOutside = false;
            string objName = obj.Name;

            foreach (EntityReference refer in obj.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(obj.Model, refer.From);
                if (objRef != null && Functions.isRunable(objRef))
                {
                    Module modref = objRef.Module;
                    if (modref != mdl)
                    {
                        isReferencedFromOutside = true;
                        if (obj is Table)
                        {
                            objList += " " + Functions.linkObject(objRef);
                        }
                    }
                }
            }

            return(isReferencedFromOutside);
        }
예제 #2
0
        private static ObjectVisibility RecoverVisibility(KBObject obj)
        {
            string objModule = obj.Module.Name;
            string objName   = obj.Name;

            ObjectVisibility objVisibility = ObjectVisibility.Private;

            foreach (EntityReference reference in obj.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(obj.Model, reference.From);

                if (objRef != null && reference.ReferenceType == ReferenceType.Hard && Functions.isRunable(obj))
                {
                    if (objRef is Artech.Genexus.Common.Objects.Attribute && obj is Procedure)
                    {
                        objVisibility = ObjectVisibility.Public;
                    }
                    else
                    {
                        if (Functions.isRunable(objRef))
                        {
                            string objRefModule = objRef.Module.Name;
                            if (objRefModule != objModule)
                            {
                                objVisibility = ObjectVisibility.Public;
                            }
                        }
                    }
                }
            }
            return(objVisibility);
        }
예제 #3
0
        internal static void KillAttribute(Artech.Genexus.Common.Objects.Attribute a)
        {
            IOutputService output = CommonServices.Output;

            foreach (EntityReference reference in a.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(a.Model, reference.From);

                if (objRef != null)
                {
                    CleanVariablesBasedInAttribute(a, output, objRef);
                    CleanSDT(a, output, objRef);
                    if (!(objRef is DataView))
                    {
                        try
                        {
                            objRef.Save();
                        }
                        catch (Exception e)
                        {
                            output.AddErrorLine("ERROR: Can't save object: " + objRef.Name + e.Message);
                        }
                    }
                }
            }
        }
예제 #4
0
        public static void ReplaceDomain()
        {
            IKBService kbserv = UIServices.KB;

            bool           success = true;
            string         title   = "KBDoctor - Replace domain ";
            IOutputService output  = CommonServices.Output;


            ReplaceDomain rd = new ReplaceDomain();
            DialogResult  dr = new DialogResult();

            dr = rd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                output.StartSection(title);

                Domain od = Functions.DomainByName(rd.originalDomainName);
                Domain ud = Functions.DomainByName(rd.destDomainName);

                if (od != null && ud != null)
                {
                    foreach (EntityReference reference in od.GetReferencesTo()) // LinkType.UsedObject))
                    {
                        KBObject objRef = KBObject.Get(UIServices.KB.CurrentModel, reference.From);
                        output.AddLine("Procesing " + objRef.Name);
                        if (objRef is Artech.Genexus.Common.Objects.Attribute)
                        {
                            Artech.Genexus.Common.Objects.Attribute att = (Artech.Genexus.Common.Objects.Attribute)objRef;
                            att.DomainBasedOn = ud;
                            att.Save();
                        }
                        else
                        {
                            VariablesPart vp = objRef.Parts.Get <VariablesPart>();
                            if (vp != null)
                            {
                                foreach (Variable v in vp.Variables)
                                {
                                    if (v.DomainBasedOn == od && !v.IsStandard)
                                    {
                                        v.DomainBasedOn = ud;
                                    }
                                }
                                objRef.Save();
                            }
                            else
                            {
                                output.AddLine("Replace " + od.Name + " domain manually in object " + objRef.Name);
                                success = false;
                            }
                        }
                    }
                }
                output.EndSection(title, success);
            }
        }
예제 #5
0
        internal static void ListObjectsWithTableInOtherModule()
        {
            IKBService kbserv = UIServices.KB;
            KBModel    model  = kbserv.CurrentModel.GetDesignModel();

            string         title  = "KBDoctor - List Objects with table in other module";
            IOutputService output = CommonServices.Output;

            output.StartSection(title);

            string outputFile = Functions.CreateOutputFile(kbserv, title);

            KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] {
                "Name", "Description", "Object Module", "Table ", "Table Module"
            });

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;

            foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                string modulename = ModulesHelper.ObjectModuleName(obj);

                foreach (EntityReference reference in obj.GetReferences())

                {
                    KBObject objref = KBObject.Get(obj.Model, reference.To);

                    if (objref != null && objref is Table && !ObjectsHelper.isGeneratedbyPattern(obj))
                    {
                        Table  t = (Table)objref;
                        string tablemodulename = TablesHelper.TableModule(t.Model, t).Name;

                        if (tablemodulename != modulename)
                        {
                            string objNameLink = Functions.linkObject(obj);

                            output.AddLine("Processing... " + obj.Name + " reference table " + t.Name + " Object module:" + modulename + " Table module:" + tablemodulename);

                            writer.AddTableData(new string[] { objNameLink, obj.Description, modulename, t.Name, tablemodulename });
                        }
                    }
                }
            }


            writer.AddFooter();
            writer.Close();

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
            bool success = true;

            output.EndSection(title, success);
        }
예제 #6
0
        private static void GenerateMDGGraph2(string name, string fileName)
        {
            IKBService kbserv = UIServices.KB;
            KBModel    model  = kbserv.CurrentModel;

            // IOutputService output = CommonServices.Output;
            StreamWriter             nodesFiles = new StreamWriter(kbserv.CurrentKB.UserDirectory + @"\kbdoctor.Nodes.CSV");
            Dictionary <string, int> aristas    = new Dictionary <string, int>();

            KBDoctorOutput.Message("Generating " + name);

            string objRefName = "";

            foreach (KBObject objRef in model.Objects.GetAll())
            {
                objRefName = NombreNodo(objRef);
                if (IncludedInGraph(objRef))
                {
                    nodesFiles.WriteLine(objRefName + " " + ModulesHelper.ObjectModuleName(objRef));

                    foreach (EntityReference r in objRef.GetReferencesTo())
                    {
                        KBObject obj = KBObject.Get(objRef.Model, r.From);

                        if ((obj != null) && (Functions.isRunable(obj)) && (obj != objRef))
                        {
                            string objName = NombreNodo(obj);
                            if (IncludedInGraph(obj))
                            {
                                int weight = ReferenceWeight(obj, objRef);
                                AgregoArista(aristas, objName, objRefName, weight);
                            }
                        }
                    }
                }
            }

            //Cargo todas las transacciones y sus tablas generadas
            foreach (Table tbl in Table.GetAll(model))
            {
                Transaction trn    = Artech.Genexus.Common.Services.GenexusBLServices.Tables.GetBestAssociatedTransaction(model, tbl.Key);
                int         weight = ReferenceWeight(trn, tbl);
                AgregoArista(aristas, NombreNodo(trn), NombreNodo(tbl), weight);
            }
            nodesFiles.Close();

            StreamWriter scriptFile = new StreamWriter(fileName);

            foreach (string arista in aristas.Keys)
            {
                scriptFile.WriteLine(arista + " " + aristas[arista]);
            }
            scriptFile.Close();
        }
예제 #7
0
 public static void AddObjectsReferenceTo(KBObject obj, KBObjectCollection objToBuild, KBDoctorXMLWriter writer)
 {
     foreach (EntityReference refe in obj.GetReferencesTo())
     {
         KBObject objRef = KBObject.Get(obj.Model, refe.From);
         if (objRef != null && KBObjectHelper.IsSpecifiable(objRef) && !objToBuild.Contains(objRef) && KBDoctorCore.Sources.Utility.isGenerated(objRef))
         {
             objToBuild.Add(objRef);
             writer.AddTableData(new string[] { objRef.QualifiedName.ToString(), objRef.Description, obj.QualifiedName.ToString() + " (" + obj.TypeDescriptor.Name + ")" });
         }
     }
 }
예제 #8
0
        public static void ListDomain()
        {
            IKBService kbserv = UIServices.KB;

            string title = "KBDoctor - Domains";

            try
            {
                string outputFile = Functions.CreateOutputFile(kbserv, title);

                IOutputService output = CommonServices.Output;
                output.StartSection("KBDoctor", title);


                KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);
                writer.AddHeader(title);
                writer.AddTableHeader(new string[] { "Domain", "Description", "Data type", "Att references", "Other References" });
                string description;
                string titlesuggested;
                string columnTitle;
                foreach (Domain d in Domain.GetAll(kbserv.CurrentModel))
                {
                    description = d.Description;
                    string Picture         = Utility.FormattedTypeDomain(d);
                    int    attReferences   = 0;
                    int    otherReferences = 0;
                    foreach (EntityReference r in d.GetReferencesTo())
                    {
                        KBObject objRef = KBObject.Get(UIServices.KB.CurrentModel, r.From);
                        if (objRef is Artech.Genexus.Common.Objects.Attribute)
                        {
                            attReferences += 1;
                        }
                        else
                        {
                            otherReferences += 1;
                        }
                    }
                    writer.AddTableData(new string[] { Functions.linkObject(d), description, Picture, attReferences.ToString(), otherReferences.ToString() });
                }
                writer.AddFooter();
                writer.Close();

                KBDoctorHelper.ShowKBDoctorResults(outputFile);
                bool success = true;
                KBDoctor.KBDoctorOutput.EndSection(title, success);
            }
            catch
            {
                bool success = false;
                KBDoctor.KBDoctorOutput.EndSection(title, success);
            }
        }
예제 #9
0
        public static void ListTableAttributesUsingDomain()
        {
            // Object with parm() rule without in: out: or inout:
            IKBService     kbserv = UIServices.KB;
            IOutputService output = CommonServices.Output;
            string         title  = "KBDoctor - Domain to change";

            output.StartSection(title);
            string outputFile = Functions.CreateOutputFile(kbserv, title);


            KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Domain", "Table", "Description", "Attribute", "Descripcion" });
            int cantObjChanged = 0;

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;
            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Domain>());

            foreach (KBObject dom in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                foreach (EntityReference reference in dom.GetReferencesTo())
                {
                    KBObject att = KBObject.Get(dom.Model, reference.From);

                    if ((att != null) && (att is Artech.Genexus.Common.Objects.Attribute))
                    {
                        foreach (EntityReference reference2 in att.GetReferencesTo())
                        {
                            KBObject tbl = KBObject.Get(att.Model, reference2.From);

                            if ((tbl != null) && (tbl is Table))
                            {
                                writer.AddTableData(new string[] { Functions.linkObject(dom), Functions.linkObject(tbl), tbl.Description, Functions.linkObject(att), att.Description });
                            }
                        }
                    }
                }
            }

            writer.AddFooter();
            writer.Close();

            bool success = true;

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
        }
예제 #10
0
        private static void ComponenteConexo(KBObject obj, KBObjectCollection visited)
        {
            foreach (EntityReference r in obj.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(obj.Model, r.From);
                VisitNode(visited, obj, objRef);
            }

            foreach (EntityReference r in obj.GetReferences())
            {
                KBObject objRef = KBObject.Get(obj.Model, r.To);
                VisitNode(visited, obj, objRef);
            }
        }
예제 #11
0
        private static void MarkReachables(IOutputService output, KBObject obj, KBObjectCollection reachablesObjects)
        {
            reachablesObjects.Add(obj);

            foreach (EntityReference reference in obj.GetReferences(LinkType.UsedObject))
            {
                KBObject objRef = KBObject.Get(obj.Model, reference.To);

                if ((objRef != null) && !reachablesObjects.Contains(objRef))
                {
                    MarkReachables(output, objRef, reachablesObjects);
                }
            }
        }
예제 #12
0
        private static void GenerateMDGMinimized(string name, string fileName)
        {
            IKBService kbserv = UIServices.KB;
            KBModel    model  = kbserv.CurrentModel;

            Dictionary <string, int> aristas = new Dictionary <string, int>();

            KBDoctorOutput.Message("Generating " + name);

            string objRefName = "";

            foreach (KBObject objRef in model.Objects.GetAll())
            {
                objRefName = NombreNodoMinimized(objRef);
                if (IncludedInGraph(objRef))
                {
                    foreach (EntityReference r in objRef.GetReferencesTo())
                    {
                        KBObject obj = KBObject.Get(objRef.Model, r.From);

                        if ((obj != null) && (Functions.isRunable(obj)) && (obj != objRef))
                        {
                            string objName = NombreNodoMinimized(obj);
                            if (objName != objRefName && IncludedInGraph(obj))
                            {
                                int weight = ReferenceWeight(obj, objRef);
                                AgregoArista(aristas, objName, objRefName, weight);
                            }
                        }
                    }
                }
            }

            //Cargo todas las transacciones y sus tablas generadas
            foreach (Table tbl in Table.GetAll(model))
            {
                //int weight = ReferenceWeight(tbl.BestAssociatedTransaction, tbl);
                //AgregoArista(aristas, NombreNodoMinimized(tbl.BestAssociatedTransaction), NombreNodoMinimized(tbl), weight);
            }


            StreamWriter scriptFile = new StreamWriter(fileName);

            foreach (string arista in aristas.Keys)
            {
                scriptFile.WriteLine(arista + " " + aristas[arista]);
            }
            scriptFile.Close();
        }
예제 #13
0
        internal static void RemoveAttributesWithoutTable(KBModel kbmodel, IOutputService output, out List <string[]> lineswriter)
        {
            lineswriter = new List <string[]>();
            // grabo todos los atributos en una colección
            List <Artech.Genexus.Common.Objects.Attribute> attTodos = new List <Artech.Genexus.Common.Objects.Attribute>();

            foreach (Artech.Genexus.Common.Objects.Attribute a in Artech.Genexus.Common.Objects.Attribute.GetAll(kbmodel))
            {
                attTodos.Add(a);
            }

            // voy borrando todos los atributos que estan en alguna tabla
            foreach (Table t in Table.GetAll(kbmodel))
            {
                foreach (EntityReference reference in t.GetReferences(LinkType.UsedObject))
                {
                    KBObject objRef = KBObject.Get(kbmodel, 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);
                    }
                }
            }

            // TODO: Atributos en dataviews

            foreach (Artech.Genexus.Common.Objects.Attribute a in attTodos)
            {
                if (!Utility.AttIsSubtype(a))
                {
                    Utility.KillAttribute(a);
                    string strRemoved = "";
                    try
                    {
                        a.Delete();
                        KBDoctorOutput.Message("Atribute deleted: " + a.Name);
                    }
                    catch (Exception e)
                    {
                        output.AddErrorLine("Can't delete " + a.Name + " Msg: " + e.Message);
                    }
                    string attNameLink = Utility.linkObject(a); //"<a href=\"gx://?Command=fa2c542d-cd46-4df2-9317-bd5899a536eb;OpenObject&name=" + a.Guid.ToString() + "\">" + a.Name + "</a>";
                    strRemoved = "<a href=\"gx://?Command=fa2c542d-cd46-4df2-9317-bd5899a536eb;RemoveObject&guid=" + a.Guid.ToString() + "\">Remove</a>";
                    string Picture = Utility.FormattedTypeAttribute(a);
                    lineswriter.Add(new string[] { strRemoved, attNameLink, a.Description, Picture });
                }
            }
        }
예제 #14
0
        private static List <Module> ListModulesOfReferencedTables(KBObject obj)
        {
            List <Module> moduleList = new List <Module>();

            foreach (EntityReference refe in obj.GetReferences())
            {
                KBObject objref = KBObject.Get(obj.Model, refe.To);
                if (objref != null && objref is Table)
                {
                    Module objrefModule = TablesHelper.TableModule(objref.Model, (Table)objref);
                    if (!moduleList.Contains(objrefModule))
                    {
                        moduleList.Add(objrefModule);
                    }
                }
            }

            return(moduleList);
        }
예제 #15
0
        public static void List2(KBObject obj, string objLocation, Dictionary <string, KBObjectCollection> dic, KBDoctorXMLWriter writer)
        {
            string objMasterPage = obj.GetPropertyValueString("MasterPage");

            writer.AddTableData(new string[] { obj.TypeDescriptor.Name, Functions.linkObject(obj), objLocation, objMasterPage });
            if (ObjectsHelper.IsCallalable(obj))
            {
                foreach (EntityReference reference in obj.GetReferences())
                {
                    KBObject      objRef         = KBObject.Get(obj.Model, reference.To);
                    string        typeDescriptor = obj.TypeDescriptor.Name;
                    List <string> list           = new List <string> {
                        "WebPanel", "Transaction", "WorkPanel"
                    };

                    if ((objRef != null) && list.Contains(typeDescriptor) && (reference.ReferenceType == ReferenceType.Hard))
                    {
                        int                count     = 0;
                        string             locations = "";
                        KBObjectCollection objColl   = new KBObjectCollection();
                        foreach (string loc in dic.Keys)
                        {
                            if ((loc != objLocation) && (list.Contains(objRef.TypeDescriptor.Name)))
                            {
                                dic.TryGetValue(loc, out objColl);
                                if (objColl.Contains(obj))
                                {
                                    locations += " " + loc;
                                    count     += 1;
                                }
                            }
                        }
                        if (count > 0)
                        {
                            string objRefMasterPage = objRef.GetPropertyValueString("MasterPage");
                            writer.AddTableData(new string[] { "+-----Called >>" + objRef.TypeDescriptor.Name, Functions.linkObject(objRef), count.ToString() + "-" + locations, objRefMasterPage });
                        }
                    }
                }
            }
        }
예제 #16
0
        private static KBObjectCollection ObjectsReferencesFromOutside(KBObject obj)
        {
            KBObjectCollection objCol = new KBObjectCollection();

            string mdlName = ObjectModuleName(obj);

            foreach (EntityReference refer in obj.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(obj.Model, refer.From);
                if (objRef != null && Functions.isRunable(objRef))
                {
                    string mdlNameRef = ObjectModuleName(objRef);
                    if (mdlNameRef != mdlName)
                    {
                        if (obj is Table)
                        {
                            objCol.Add(obj);
                        }
                    }
                }
            }
            return(objCol);
        }
예제 #17
0
        private static List <string> MostReferencedInFolder(Table tbl)
        {
            IOutputService output = CommonServices.Output;
            List <string>  list   = new List <string>();

            foreach (EntityReference refe in tbl.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(tbl.Model, refe.From);
                if (objRef != null)
                {
                    bool read, insert, update, delete, isBase;

                    ReferenceTypeInfo.ReadTableInfo(refe.LinkTypeInfo, out read, out insert, out update, out delete, out isBase);

                    string updated = (update || delete || insert) ? "UPDATED" : "";

                    if (objRef.Parent is Folder)
                    {
                        list.Add("FOLDER:" + objRef.Parent.Name + " |  " + updated);
                    }
                    if (objRef.Parent is Module)
                    {
                        list.Add("MODULE:" + objRef.Parent.Name + " |  " + updated);
                    }
                }
            }
            output.AddLine(" ");
            output.AddLine("============> " + tbl.Name);

            list.Sort();
            foreach (string s in list)
            {
                output.AddLine(s);
            }
            return(list);
        }
예제 #18
0
        public static string MainsOf(KBObject obj, KBObjectCollection objColl, string callTree)
        {
            string mains = "";

            if (!objColl.Contains(obj))
            {
                objColl.Add(obj);

                if (obj.GetPropertyValue <bool>("IsMain"))
                {
                    string objAppGenerator = obj.GetPropertyValueString("AppGenerator");
                    if (objAppGenerator.Contains("Java Win") && callTree.Contains("HMaster"))
                    {
                        mains = "";
                    }
                    else
                    {
                        mains = callTree + "/" + Functions.linkObject(obj) + "(" + objAppGenerator + ")<BR> ";
                    }
                }
                else
                {
                    callTree += obj.Name + "/";
                    foreach (EntityReference reference in obj.GetReferencesTo())
                    {
                        KBObject objRef = KBObject.Get(obj.Model, reference.From);

                        if ((objRef != null) && (obj.Name != objRef.Name) && (reference.ReferenceType == ReferenceType.Hard) && reference.LinkType == LinkType.UsedObject /*&& (obj.TypeDescriptor.Name != "MasterPage")*/ && !objColl.Contains(objRef))
                        {
                            mains += MainsOf(objRef, objColl, callTree);
                        }
                    }
                }
            }
            return(mains);
        }
예제 #19
0
        private static void GenerateKBModuleGraph(string name, string fileName)
        {
            IKBService       kbserv     = UIServices.KB;
            KBModel          model      = kbserv.CurrentModel;
            StreamWriter     scriptFile = new StreamWriter(fileName);
            IOutputService   output     = CommonServices.Output;
            StringCollection aristas    = new StringCollection();

            output.AddLine("Generating " + name);

            scriptFile.WriteLine("<?xml version = '1.0' encoding = 'UTF-8'?>");

            scriptFile.WriteLine("<gexf xmlns='http://www.gexf.net/1.2draft'  xmlns:viz='http://www.gexf.net/1.2draft/viz' ");
            scriptFile.WriteLine("     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd' version = '1.2' > ");

            scriptFile.WriteLine("  <graph mode = 'static' defaultedgetype = 'directed' > ");
            scriptFile.WriteLine("<attributes class='node'> <attribute id='0' title = 'module' type = 'string' />  </attributes >");

            scriptFile.WriteLine("      <nodes>");

            foreach (Module mdl in Module.GetAll(model))

            {
                string modulename = mdl.Name;

                scriptFile.WriteLine("          <node id='" + mdl.Name + "' label='" + mdl.Description + "' >");
                scriptFile.WriteLine("              <attvalues>  <attvalue for='0' value = '" + mdl.Name + "' /> </attvalues>");
                scriptFile.WriteLine("          </node>");

                foreach (KBObject obj in mdl.GetAllMembers())
                {
                    if (obj is Procedure || obj is Table)
                    {
                        foreach (EntityReference r in obj.GetReferences())
                        {
                            KBObject objRef = KBObject.Get(obj.Model, r.To);
                            if ((objRef != null) && (Functions.isRunable(objRef) || objRef is Table) && modulename != ModulesHelper.ObjectModuleName(objRef))

                            {
                                String edge = "          <edge id='XXXX' source='" + modulename + "' target='" + ModulesHelper.ObjectModuleName(objRef) + "' />  ";
                                if (!aristas.Contains(edge))
                                {
                                    aristas.Add(edge);
                                }
                            }
                        }
                    }
                }
            }
            scriptFile.WriteLine("      </nodes>");

            //Grabo las aristas
            scriptFile.WriteLine("      <edges>");

            int i = 0;

            foreach (String s in aristas)
            {
                string s2 = s.Replace("XXXX", i.ToString());
                scriptFile.WriteLine("          " + s2);
                i += 1;
            }
            ;
            scriptFile.WriteLine("      </edges>");
            scriptFile.WriteLine("  </graph>");
            scriptFile.WriteLine("</gexf>");
            scriptFile.Close();
        }
예제 #20
0
        private static void GenerateKBObjectEdgesTxt(string name, string fileName)
        {
            IKBService kbserv = UIServices.KB;
            KBModel    model  = kbserv.CurrentModel;
            Graph      g      = new Graph();

            Module rootModule = kbserv.CurrentModel.GetDesignModel().RootModule;

            IOutputService   output  = CommonServices.Output;
            StringCollection aristas = new StringCollection();

            output.AddLine("Generating " + name);

            Dictionary <string, Tuple <int, string> > dictionary = new Dictionary <string, Tuple <int, string> >();
            Dictionary <int, int> initialpartition = new Dictionary <int, int>();

            // Dictionary<string, Tuple<int,string>> dictionary = new Dictionary<string, Tuple<int,string>>();

            Dictionary <string, int>    NameToId     = new Dictionary <string, int>();
            Dictionary <string, string> NameToModule = new Dictionary <string, string>();
            Dictionary <int, string>    IdToName     = new Dictionary <int, string>();
            Dictionary <int, string>    IdToModule   = new Dictionary <int, string>();
            Dictionary <int, EntityKey> IdToKey      = new Dictionary <int, EntityKey>();

            int objId = 0;

            foreach (KBObject obj in model.Objects.GetAll())
            {
                if (Functions.hasModule(obj) || (obj is Module))
                {
                    string objName    = NombreNodo(obj);
                    string modulename = ModulesHelper.ObjectModuleName(obj);

                    try
                    {
                        objId += 1;
                        NameToId.Add(objName, objId);
                        NameToModule.Add(objName, modulename);
                        IdToName.Add(objId, objName);
                        IdToModule.Add(objId, modulename);
                        IdToKey.Add(objId, obj.Key);
                    }
                    catch (Exception e)
                    {// output.AddWarningLine("Can't add : " + objName + " Exception: " + e.Message + " " + e.InnerException);
                    };
                }
            }


            foreach (KBObject obj in model.Objects.GetAll())
            {
                string objName = "";

                if (Functions.hasModule(obj) || (obj is Module)) //((Functions.isRunable(obj) && ObjectsHelper.isGenerated(obj)) || (obj is Table))
                {
                    /*
                     * objName = NombreNodo(obj);
                     * string modulename = ModulesHelper.ObjectModuleName(obj);
                     *
                     * try
                     * {
                     *  objId += 1;
                     *  NameToId.Add(objName, objId);
                     *  NameToModule.Add(objName, modulename);
                     *  IdToName.Add(objId, objName);
                     *  IdToModule.Add(objId, modulename);
                     *  IdToKey.Add(objId, obj.Key);
                     * }
                     * catch (Exception e) { //output.AddWarningLine("Can't add : " + objName);
                     * };
                     */

                    //Tomo las referencias que no sean tablas.
                    foreach (EntityReference r in obj.GetReferencesTo())
                    {
                        KBObject objRef = KBObject.Get(obj.Model, r.From);
                        if ((objRef != null) && (Functions.isRunable(objRef)) || (objRef is Table))

                        {
                            string objRefName = NombreNodo(objRef);
                            if (objName != objRefName)
                            {
                                int    weight = ReferenceWeight(objRef, obj);
                                String edge   = objRefName + " " + objName;

                                if (!aristas.Contains(edge))
                                {
                                    aristas.Add(edge);
                                    GraboArista(g, NameToId, objRefName, objName, weight);
                                }
                            }
                        }
                    }
                }
            }
            ;


            foreach (int node in g.Nodes)
            {
                string moduleName = IdToModule[node];
                int    moduleId   = NameToId[moduleName];
                initialpartition.Add(node, moduleId);
            }

            output.AddLine("Before automatic modularization. TurboMQ = " + TurboMQ(g, initialpartition).ToString());

            //Empiezo modularizacion
            Stopwatch stopwatch = new Stopwatch();
            // stopwatch.Restart();
            Dictionary <int, int> partition = Community.BestPartition(g);

            output.AddLine("BestPartition: " + stopwatch.Elapsed);
            var communities = new Dictionary <int, List <int> >();

            foreach (var kvp in partition)
            {
                List <int> nodeset;
                if (!communities.TryGetValue(kvp.Value, out nodeset))
                {
                    nodeset = communities[kvp.Value] = new List <int>();
                }
                nodeset.Add(kvp.Key);
                //    output.AddLine(kvp.Key.ToString() +"  "+kvp.Value);
            }
            output.AddLine(communities.Count + " modules found");
            Dictionary <string, int> modu = new Dictionary <string, int>();
            int counter = 0;

            foreach (var kvp in communities)
            {
                output.AddLine(String.Format("module {0}: {1} objects", counter, kvp.Value.Count));
                foreach (var objid in kvp.Value)
                {
                    var objname  = IdToName[objid];
                    int cantidad = 0;
                    // output.AddLine("Module :" + counter.ToString() + " " + objname);
                    string pareja = IdToModule[objid] + " " + counter.ToString();
                    if (modu.ContainsKey(pareja))
                    {
                        modu[pareja] = modu[pareja] + 1;
                    }
                    else
                    {
                        modu.Add(pareja, 1);
                    }
                }


                var sortedDict = from entry in modu orderby entry.Value descending select entry;

                //Cantidad de modulo nuevo y modulo viejo.
                foreach (KeyValuePair <string, int> entry in sortedDict)
                {
                    //   output.AddLine(entry.Key + " " + entry.Value.ToString());
                    Module m = new Module(model);
                    m.Name = entry.Key.Replace(" ", "_") + string.Format("_{0:yyyy_MM_dd_hh_mm_ss}", DateTime.Now);
                    output.AddLine(m.Name);
                    m.Module = kbserv.CurrentModel.GetDesignModel().RootModule;
                    m.Save();

                    foreach (var objid in kvp.Value)
                    {
                        KBObject objToChange = KBObject.Get(model, IdToKey[objid]);
                        if (objToChange != null)
                        {
                            if (objToChange is Table)
                            {
                                try
                                {
                                    KBObject trnBest = GenexusBLServices.Tables.GetBestAssociatedTransaction(model, objToChange.Key);
                                    trnBest.Module = m;
                                    trnBest.Save();
                                }
                                catch (Exception e) { output.AddErrorLine(objToChange.Name + e.Message); }
                            }
                            else
                            {
                                try
                                {
                                    objToChange.Module = m;
                                    objToChange.Save();
                                }
                                catch (Exception e) { output.AddErrorLine(objToChange.Name + e.Message); }
                            }
                        }
                    }

                    break;
                }
                counter++;
                modu.Clear();
            }
        }
예제 #21
0
        private static void GenerateMDGGraph(string name, string fileName)
        {
            IKBService       kbserv     = UIServices.KB;
            KBModel          model      = kbserv.CurrentModel;
            StreamWriter     scriptFile = new StreamWriter(fileName);
            IOutputService   output     = CommonServices.Output;
            StringCollection aristas    = new StringCollection();

            output.AddLine("Generating MDG " + name);

            string           objName = "";
            StringCollection nodos   = new StringCollection();

            foreach (KBObject obj in model.Objects.GetAll())
            {
                bool includedInGraph = (Functions.isRunable(obj) && ObjectsHelper.isGenerated(obj)) || (obj is Table);
                if (includedInGraph)
                {
                    objName = NombreNodo(obj);
                    string modulename = ModulesHelper.ObjectModuleName(obj);

                    if (!nodos.Contains(objName))
                    {
                        scriptFile.WriteLine("          <node id='" + objName + "' label='" + objName + "' >");
                        scriptFile.WriteLine("              <attvalues>  <attvalue for='0' value = '" + modulename + "' /> </attvalues>");
                        scriptFile.WriteLine("          </node>");
                        nodos.Add(objName);
                    }

                    foreach (EntityReference r in obj.GetReferencesTo())
                    {
                        KBObject objRef = KBObject.Get(obj.Model, r.From);
                        if ((objRef != null) && (Functions.isRunable(objRef) || objRef is Table))

                        {
                            string objRefName = NombreNodo(objRef);
                            if (objName != objRefName)
                            {
                                String edge = " source='" + objRefName + "' target='" + objName + "' weight= '1.0' ";
                                if (!aristas.Contains(edge))
                                {
                                    aristas.Add(edge);
                                }
                            }
                        }
                    }
                }
            }
            ;
            scriptFile.WriteLine("      </nodes>");

            //Grabo las aristas
            scriptFile.WriteLine("      <edges>");

            int i = 0;

            foreach (String s in aristas)
            {
                scriptFile.WriteLine("                     <edge id=" + i.ToString() + s + " />  ");
                i += 1;
            }
            ;
            scriptFile.WriteLine("      </edges>");
            scriptFile.WriteLine("  </graph>");
            scriptFile.WriteLine("</gexf>");
            scriptFile.Close();
        }
예제 #22
0
        private static void GenerateKBObjectGraph(string name, string fileName)
        {
            IKBService       kbserv     = UIServices.KB;
            KBModel          model      = kbserv.CurrentModel;
            StreamWriter     scriptFile = new StreamWriter(fileName);
            IOutputService   output     = CommonServices.Output;
            StringCollection aristas    = new StringCollection();

            output.AddLine("Generating " + name);

            scriptFile.WriteLine("<?xml version = '1.0' encoding = 'UTF-8'?>");

            scriptFile.WriteLine("<gexf xmlns='http://www.gexf.net/1.2draft'  xmlns:viz='http://www.gexf.net/1.2draft/viz' ");
            scriptFile.WriteLine("     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd' version = '1.2' > ");

            scriptFile.WriteLine("  <graph mode = 'static' defaultedgetype = 'directed' > ");
            scriptFile.WriteLine("<attributes class='node'> <attribute id='0' title = 'module' type = 'string' />  </attributes >");

            scriptFile.WriteLine("      <nodes>");

            string           objName = "";
            StringCollection nodos   = new StringCollection();

            foreach (KBObject obj in model.Objects.GetAll())
            {
                if ((Functions.isRunable(obj) && ObjectsHelper.isGenerated(obj)) || (obj is Table))
                {
                    objName = NombreNodo(obj);
                    string modulename = ModulesHelper.ObjectModuleName(obj);

                    if (!nodos.Contains(objName))
                    {
                        scriptFile.WriteLine("          <node id='" + objName + "' label='" + objName + "' >");
                        scriptFile.WriteLine("              <attvalues>  <attvalue for='0' value = '" + modulename + "' /> </attvalues>");
                        scriptFile.WriteLine("          </node>");
                        nodos.Add(objName);
                    }

                    foreach (EntityReference r in obj.GetReferencesTo())
                    {
                        KBObject objRef = KBObject.Get(obj.Model, r.From);
                        if ((objRef != null) && (Functions.isRunable(objRef) || objRef is Table))

                        {
                            string objRefName = NombreNodo(objRef);
                            if (objName != objRefName)
                            {
                                String edge = " source='" + objRefName + "' target='" + objName + "' weight= '1.0' ";
                                if (!aristas.Contains(edge))
                                {
                                    aristas.Add(edge);
                                }
                            }
                        }
                    }
                }
            }
            ;
            scriptFile.WriteLine("      </nodes>");

            //Grabo las aristas
            scriptFile.WriteLine("      <edges>");

            int i = 0;

            foreach (String s in aristas)
            {
                scriptFile.WriteLine("                     <edge id=" + i.ToString() + s + " />  ");
                i += 1;
            }
            ;
            scriptFile.WriteLine("      </edges>");
            scriptFile.WriteLine("  </graph>");
            scriptFile.WriteLine("</gexf>");
            scriptFile.Close();
        }
예제 #23
0
        public static void KBInterfaces()
        {
            IKBService kbserv = UIServices.KB;
            KBModel    design = kbserv.CurrentModel;
            SpecificationListHelper helper = new SpecificationListHelper(design.Environment.TargetModel);

            string outputFile = kbserv.CurrentKB.UserDirectory + @"\kbdoctor.KBInterfaces.html";

            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }

            string         titulo = "KBDoctor - KB Interfaces";
            IOutputService output = CommonServices.Output;

            output.StartSection(titulo);


            KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(titulo);
            writer.AddTableHeader(new string[] { "Object", "Variable", "Type", "mains" });

            foreach (KBObject obj in kbserv.CurrentModel.Objects.GetAll())
            {
                if (obj != null)
                {
                    output.AddLine("Procesing  " + obj.Name);

                    IEnumerable <int> generatorTypes = KbStats.GetObjectGenerators(obj.Key);

                    string             objNamePrior = "";
                    KBObjectCollection objColl      = new KBObjectCollection();
                    string             tipo         = "";

                    string mainss = "";


                    foreach (EntityReference reference in obj.GetReferences())
                    {
                        KBObject objRef = KBObject.Get(obj.Model, reference.To);

                        if (objRef != null)
                        {
                            if (objRef is ExternalObject)
                            {
                                tipo = "External Object:" + objRef.GetPropertyValueString("ExoType");
                                writer.AddTableData(new string[] { Functions.linkObject(obj), Functions.linkObject(objRef), tipo, mainss });
                            }
                            else
                            {
                                if (objRef is MissingKBObject)
                                {
                                    tipo = "Missing Object";
                                    writer.AddTableData(new string[] { Functions.linkObject(obj), Functions.linkObject(objRef), tipo, mainss });
                                }
                            }
                        }
                    }


                    string sourceWOComments = Functions.ExtractComments(Functions.ObjectSourceUpper(obj));

                    sourceWOComments = sourceWOComments.Replace("\t", " ");

                    AddLineKBInterfazSource(writer, obj, "SHELL ", "CMD.", sourceWOComments, mainss);
                    AddLineKBInterfazSource(writer, obj, "JAVA ", "CMD.", sourceWOComments, mainss);
                    AddLineKBInterfazSource(writer, obj, "CSHARP ", "CMD.", sourceWOComments, mainss);
                    AddLineKBInterfazSource(writer, obj, "SQL ", "CMD.", sourceWOComments, mainss);


                    ObjectsVariablesExternal(obj, writer, mainss);
                    if (obj is Transaction || obj is WebPanel)
                    {
                        UserControlUsageCheck(obj, writer, mainss);
                    }
                }
            }

            writer.AddFooter();
            writer.Close();

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
            bool success = true;

            output.EndSection(titulo, success);
        }
예제 #24
0
        public static void ListTableAttributesUsingDomain()
        {
            // Object with parm() rule without in: out: or inout:
            IKBService     kbserv = UIServices.KB;
            IOutputService output = CommonServices.Output;
            string         title  = "KBDoctor - Domain to change";

            output.StartSection("KBDoctor", title);
            try
            {
                string outputFile = Functions.CreateOutputFile(kbserv, title);


                KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);
                writer.AddHeader(title);
                writer.AddTableHeader(new string[] { "Domain", "Table", "Description", "Attribute", "Descripcion", "Module" });
                int cantObjChanged = 0;

                SelectObjectOptions selectObjectOption = new SelectObjectOptions();
                selectObjectOption.MultipleSelection = true;
                selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Domain>());

                //Pido dominios
                foreach (KBObject dom in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
                {
                    //Atributos con ese dominio
                    foreach (EntityReference reference in dom.GetReferencesTo())
                    {
                        KBObject att = KBObject.Get(dom.Model, reference.From);

                        if ((att != null) && (att is Artech.Genexus.Common.Objects.Attribute))
                        {
                            foreach (EntityReference reference2 in att.GetReferencesTo())
                            {
                                KBObject tbl = KBObject.Get(att.Model, reference2.From);

                                if ((tbl != null) && (tbl is Table))
                                {
                                    writer.AddTableData(new string[] { Functions.linkObject(dom), Functions.linkObject(tbl), tbl.Description, Functions.linkObject(att), att.Description, ModulesHelper.ObjectModuleName(tbl) });
                                }
                            }
                        }
                    }
                }

                //Agrego Atributos sin dominios
                foreach (Artech.Genexus.Common.Objects.Attribute a in Artech.Genexus.Common.Objects.Attribute.GetAll(kbserv.CurrentModel))
                {
                    if (a.DomainBasedOn == null)
                    {
                        foreach (EntityReference reference2 in a.GetReferencesTo())
                        {
                            KBObject tbl = KBObject.Get(a.Model, reference2.From);

                            if ((tbl != null) && (tbl is Table))
                            {
                                writer.AddTableData(new string[] { Utility.FormattedTypeAttribute(a), Functions.linkObject(tbl), tbl.Description, Functions.linkObject(a), a.Description, ModulesHelper.ObjectModuleName(tbl) });
                            }
                        }
                    }
                }

                writer.AddFooter();
                writer.Close();

                bool success = true;

                KBDoctorHelper.ShowKBDoctorResults(outputFile);
            }
            catch
            {
                bool success = false;
                KBDoctor.KBDoctorOutput.EndSection(title, success);
            }
        }
예제 #25
0
        public static void AttFormula()
        {
            IKBService kbserv = UIServices.KB;


            string title      = "KBDoctor - Attributes Formula";
            string outputFile = Functions.CreateOutputFile(kbserv, title);

            IOutputService output = CommonServices.Output;

            output.StartSection(title);


            KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Attribute", "Description", "DataType", "Formula", "Tables", "Redundant in Tables", "#References" });
            string description;
            string titlesuggested;
            string columnTitle;

            foreach (Artech.Genexus.Common.Objects.Attribute a in Artech.Genexus.Common.Objects.Attribute.GetAll(kbserv.CurrentModel))
            {
                description    = a.Description;
                titlesuggested = a.Title;
                columnTitle    = a.ColumnTitle;
                Formula formula = a.Formula;
                if (formula == null)
                {
                    //  output.AddLine(a.Name);
                }
                else
                {
                    output.AddLine("Formula " + a.Name);
                    string Picture           = Functions.ReturnPicture(a);
                    string attNameLink       = Functions.linkObject(a);
                    string redundantInTables = "";
                    string tables            = "";
                    GetTablesAttIsRedundant(kbserv.CurrentModel, a, out tables, out redundantInTables);

                    int Count = 0;
                    foreach (EntityReference entityRef in kbserv.CurrentModel.GetReferencesTo(a.Key))
                    {
                        KBObject objRef = KBObject.Get(kbserv.CurrentModel, entityRef.From);
                        if (objRef != null)
                        {
                            if (!(objRef is Table) && !(objRef is Transaction))
                            {
                                Count += 1;
                            }
                        }
                    }
                    if (Count == 0)  //Solo es referido por transacciones o por tablas


                    {
                        foreach (EntityReference entityRef in kbserv.CurrentModel.GetReferencesTo(a.Key))
                        {
                            KBObject objRef = KBObject.Get(kbserv.CurrentModel, entityRef.From);
                            if (objRef != null)
                            {
                                if (objRef is Transaction)
                                {
                                    foreach (KBObjectPart part in objRef.Parts)
                                    {
                                        if (!(part is StructurePart))
                                        {
                                            foreach (EntityReference ref2 in part.GetPartReferences())
                                            {
                                                if (ref2.To.Id == a.Id)
                                                {
                                                    Count += 1;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }


                    writer.AddTableData(new string[] { attNameLink, description, Picture, formula.ToString(), tables, redundantInTables, Count.ToString() });
                }
            }

            writer.AddFooter();
            writer.Close();

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
            bool success = true;

            output.EndSection(title, success);
        }
예제 #26
0
        public static void ObjectsWINWEB()
        {
            IKBService kbserv = UIServices.KB;
            KBModel    design = kbserv.CurrentModel;
            SpecificationListHelper helper = new SpecificationListHelper(design.Environment.TargetModel);


            string title      = "KBDoctor - Objects called win y web";
            string outputFile = Functions.CreateOutputFile(kbserv, title);


            IOutputService output = CommonServices.Output;

            output.StartSection(title);


            KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Name", "Value", "Observation" });
            foreach (KBObject obj in kbserv.CurrentModel.Objects.GetAll())
            {
                if (obj is Procedure || obj is Transaction)
                {
                    output.AddLine("Procesing up " + obj.Name);
                    IEnumerable <int> generatorTypes = GetObjectGenerators(obj.Key);

                    string objNamePrior = "";
                    int    count        = 0;
                    foreach (int genType in generatorTypes)
                    {
                        count += 1;
                    }
                    if (count > 1)
                    {
                        KBObjectCollection objColl = new KBObjectCollection();
                        string             mainss  = "";

                        output.AddLine("Procesing down " + obj.Name);
                        foreach (EntityReference reference in obj.GetReferences())
                        {
                            KBObject objRef = KBObject.Get(obj.Model, reference.To);
                            if ((objRef != null) && (objRef is WorkPanel || objRef is WebPanel) && (reference.ReferenceType == ReferenceType.Hard)) //&& (objRef.TypeDescriptor.Name != "MasterPage") )
                            {
                                if (objNamePrior != obj.Name)
                                {
                                    string callTree = "";
                                    mainss = MainsOf(obj, objColl, callTree);
                                }
                                writer.AddTableData(new string[] { Functions.linkObject(obj), Functions.linkObject(objRef), mainss });
                                objNamePrior = obj.Name;
                            }
                        }
                    }
                }
            }

            writer.AddFooter();
            writer.Close();

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
            bool success = true;

            output.EndSection(title, success);
        }
예제 #27
0
        internal static void ObjectsToDivide()

        {
            IKBService     kbserv     = UIServices.KB;
            KBModel        kbModel    = UIServices.KB.CurrentModel;
            IOutputService output     = CommonServices.Output;
            bool           success    = true;
            int            objInRoot  = 0;
            int            objSinRoot = 0;
            string         title      = "KBDoctor - Objects to divide";

            output.StartSection(title);
            string            outputFile = Functions.CreateOutputFile(kbserv, title);
            KBDoctorXMLWriter writer     = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Object", "Module", "Type", "Is referenced by" });

            KBObjectCollection objRefCollection = new KBObjectCollection();

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = false;
            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Module>());
            Module module2 = new Module(kbModel);

            foreach (Module module in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                module2 = module;

                output.AddLine("Procesing " + module.Name + "....");

                foreach (KBObject obj in ModuleObjects(module))
                {
                    foreach (EntityReference reference in obj.GetReferences())
                    {
                        KBObject objref = KBObject.Get(obj.Model, reference.To);
                        if (objref != null && objref.TypeDescriptor.Name != "Attribute" && objref.TypeDescriptor.Name != "MasterPage")
                        {
                            Module objrefModule = ((objref is Table) ? TablesHelper.TableModule(objref.Model, (Table)objref) : objref.Module);

                            if (objrefModule != module)
                            {
                                if (!(objref is Domain) && !(objref is Image) && !(objref is Theme) && !(objref is ThemeClass) &&
                                    !(objref is GeneratorCategory) && !(objref is KBCategory) && !(objref is SDT))
                                {
                                    bool contain = objRefCollection.Any(p => p.Guid == objref.Guid);
                                    if (!contain)
                                    {
                                        objRefCollection.Add(objref);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            string listObj = "";

            //Listo todos los objetos externos referenciados desde el modulo
            foreach (KBObject o in objRefCollection)
            {
                listObj = "";
                //Armo lista de objetos de mi modulo que referencian al objeto externo
                foreach (EntityReference refe in o.GetReferencesTo())
                {
                    KBObject objref = KBObject.Get(o.Model, refe.From);
                    if (objref != null)
                    {
                        Module objrefModule = ((objref is Table) ? TablesHelper.TableModule(objref.Model, (Table)objref) : objref.Module);
                        if (objrefModule == module2)
                        {
                            listObj += " " + Functions.linkObject(objref);
                        }
                    }
                }
                Module oModule = ((o is Table) ? TablesHelper.TableModule(o.Model, (Table)o) : o.Module);
                writer.AddTableData(new string[] { Functions.linkObject(o), oModule.Name, o.TypeDescriptor.Name, listObj });
            }
            output.AddLine("");
            output.EndSection(title, success);

            writer.AddFooter();
            writer.Close();
            KBDoctorHelper.ShowKBDoctorResults(outputFile);
        }
예제 #28
0
        public static void ListAttDescWithoutUniqueIndex()
        {
            IKBService kbserv = UIServices.KB;

            string title      = "KBDoctor - Descriptor attribute without unique index";
            string outputFile = Functions.CreateOutputFile(kbserv, title);


            IOutputService output = CommonServices.Output;

            output.StartSection(title);

            string tabla    = "";
            string atributo = "";
            string add      = "";


            KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Table", "Description", "Attribute", "Data Type", "" });

            // voy borrando todos los atributos que estan en alguna tabla
            foreach (Table t in Table.GetAll(kbserv.CurrentModel))
            {
                int  idAttDesc    = t.TableStructure.DescriptionAttribute.Id;
                bool existeIndice = false;

                tabla    = t.Name + " - " + t.Description;
                atributo = t.TableStructure.DescriptionAttribute.Name;

                foreach (TableIndex index in t.TableIndexes.Indexes)
                {
                    int  nroAtributos = 0;
                    bool esta         = false;
                    foreach (EntityReference reference in index.Index.GetReferences(LinkType.UsedObject))
                    {
                        if (!existeIndice)
                        {
                            KBObject objRef = KBObject.Get(kbserv.CurrentModel, reference.To);
                            if (objRef is Artech.Genexus.Common.Objects.Attribute)
                            {
                                if (objRef.Id == idAttDesc)
                                {
                                    esta = true;
                                }
                                nroAtributos = nroAtributos + 1;
                            }
                            if ((esta) && (nroAtributos == 1))
                            {
                                existeIndice = true;
                            }
                        }
                    }
                }
                if (!existeIndice)
                {
                    add = "<a href=\"gx://?Command=fa2c542d-cd46-4df2-9317-bd5899a536eb;AddDescriptorIndex&tabName=" + t.Name + "\">Add index</a>";
                    writer.AddTableData(new string[] { Functions.linkObject((KBObject)t), t.Description, atributo, Functions.ReturnPicture(t.TableStructure.DescriptionAttribute.Attribute), add });
                }
            }

            writer.AddFooter();
            writer.Close();

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
            bool success = true;

            output.EndSection(title, success);
        }
예제 #29
0
 internal static void CleanKBObjectVariables(KBObject kbObj, IOutputService output, ref string recomendations)
 {
     try
     {
         VariablesPart variablesPart = null;
         if (!kbObj.IsCurrentVersion || kbObj.Dirty)
         {
             kbObj = KBObject.Get(kbObj.Model, kbObj.Key);
         }
         List <Variable> list = new List <Variable>();
         List <IEnumerable <VariableReference> > list2 = new List <IEnumerable <VariableReference> >();
         List <VariableReference> list3 = new List <VariableReference>();
         string text = null;
         foreach (KBObjectPart current in kbObj.Parts)
         {
             if (current is VariablesPart)
             {
                 variablesPart = (VariablesPart)current;
             }
             else
             {
                 if (current is IHasVariableReferences)
                 {
                     list2.Add(((IHasVariableReferences)current).GetReferencedVariables());
                 }
             }
             if (current is LayoutPart && ((LayoutPart)current).Layout != null)
             {
                 using (IEnumerator <IReportBand> enumerator2 = ((LayoutPart)current).Layout.ReportBands.GetEnumerator())
                 {
                     while (enumerator2.MoveNext())
                     {
                         IReportBand current2 = enumerator2.Current;
                         foreach (IReportComponent current3 in current2.Controls)
                         {
                             if (current3 is ReportAttribute)
                             {
                                 VariableReference item = new VariableReference(current3.Name);
                                 list3.Add(item);
                             }
                         }
                     }
                     continue;
                 }
             }
             if (current is WebFormPart && ((WebFormPart)current).Document != null)
             {
                 text = ((WebFormPart)current).Document.OuterXml;
             }
         }
         if (list3.Count > 0)
         {
             list2.Add(list3);
         }
         if (variablesPart != null && !variablesPart.GetPropertyValue <bool>("IsDefault"))
         {
             foreach (Variable current4 in variablesPart.Variables)
             {
                 if (!current4.IsAutoDefined && !current4.IsStandard && (Artech.Genexus.Common.Properties.ATT.Dimensions_Enum)Enum.Parse(typeof(Artech.Genexus.Common.Properties.ATT.Dimensions_Enum), current4.GetPropertyValue <string>("AttNumDim")) == Artech.Genexus.Common.Properties.ATT.Dimensions_Enum.Scalar)
                 {
                     bool flag = false;
                     foreach (IEnumerable <VariableReference> current5 in list2)
                     {
                         foreach (VariableReference current6 in current5)
                         {
                             if (current6.Name.Replace("&", "").Equals(current4.Name.Replace("&", ""), StringComparison.InvariantCultureIgnoreCase))
                             {
                                 flag = true;
                                 break;
                             }
                         }
                         if (flag)
                         {
                             break;
                         }
                     }
                     if (!flag && (text == null || !text.Contains("\"var:" + current4.Id + "\"")))
                     {
                         list.Add(current4);
                     }
                 }
             }
             if (list.Count > 0)
             {
                 string text2 = "";
                 foreach (Variable current7 in list)
                 {
                     text2 = text2 + ", " + current7.Name;
                     variablesPart.Remove(current7);
                 }
                 OutputMessages outputMessages = new OutputMessages();
                 if (kbObj.Validate(outputMessages))
                 {
                     kbObj.Save();
                     string recommend = "Object '" + kbObj.Name + "' cleaned successfully. Variables deleted: " + text2.Substring(2);
                     KBDoctorOutput.Message(recommend);
                     recomendations += recommend + "<br>";
                 }
                 using (IEnumerator <BaseMessage> enumerator8 = outputMessages.GetEnumerator())
                 {
                     while (enumerator8.MoveNext())
                     {
                         BaseMessage current8 = enumerator8.Current;
                         if (current8.Level == MessageLevel.Error)
                         {
                             output.AddErrorLine("KBDoctor", current8.Text);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         output.AddWarningLine("KBDoctor", "Object '" + kbObj.Name + "' was not cleaned because an error ocurred: " + ex.Message);
     }
 }
예제 #30
0
        public static void AttInOneTrnOnly()
        {
            IKBService kbserv = UIServices.KB;

            string title      = "KBDoctor - Attributes in Transaction only";
            string outputFile = Functions.CreateOutputFile(kbserv, title);


            IOutputService output = CommonServices.Output;

            output.StartSection(title);


            KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Attribute", "can delete", "Description", "Data type", "Tables", "Transactions" });

            // grabo todos los atributos en una colección
            output.AddLine("Loading attributes..");
            List <Artech.Genexus.Common.Objects.Attribute> attTodos = new List <Artech.Genexus.Common.Objects.Attribute>();

            foreach (Artech.Genexus.Common.Objects.Attribute a in Artech.Genexus.Common.Objects.Attribute.GetAll(kbserv.CurrentModel))
            {
                attTodos.Add(a);
            }

            output.AddLine("Procesiong objects..");

            foreach (KBObject obj in kbserv.CurrentModel.Objects.GetAll())
            {
                // output.AddLine("Procesing .. " + obj.Name);

                if ((!(obj is Transaction) && !(obj is Table) && !(obj is SDT)) || obj.GetPropertyValue <bool>("idISBUSINESSCOMPONENT"))
                {
                    foreach (EntityReference reference in obj.GetReferences(LinkType.UsedObject))
                    {
                        KBObject objRef = KBObject.Get(kbserv.CurrentModel, 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 a in attTodos)
            {
                output.AddLine("Procesing .. " + a.Name);

                string attNameLink = Functions.linkObject(a); // "<a href=\"gx://?Command=fa2c542d-cd46-4df2-9317-bd5899a536eb;OpenObject&name=" + a.Guid.ToString() + "\">" + a.Name + "</a>";
                string Picture     = Functions.ReturnPicture(a);
                string table       = TableOfAtt(a);
                bool   canDelete;
                string trns         = TransactionsOfAtt(a, out canDelete);
                string strCanDelete = canDelete ? "Yes" : "";
                writer.AddTableData(new string[] { attNameLink, strCanDelete, a.Description, Picture, table, trns });
            }

            writer.AddFooter();
            writer.Close();

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
            bool success = true;

            output.EndSection(title, success);
        }