Example #1
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);
        }
Example #2
0
        private static void GenerateSILFile(string name, string fileName)
        {
            IKBService   kbserv     = UIServices.KB;
            KBModel      model      = kbserv.CurrentModel;
            StreamWriter scriptFile = new StreamWriter(fileName);
            Dictionary <string, HashSet <string> > dic = new Dictionary <string, HashSet <string> >();

            KBDoctorOutput.Message("Generating " + name);

            string[] modulosGeneXus = new string[] { "Client", "Common", "SD", "Server", "Social", "Configuration", "Notifications"
                                                     , "UI", "iOS", "Media", "Notifications", "Store", "Synchronization" };

            foreach (KBObject obj in model.Objects.GetAll())
            {
                string objName    = obj.Name;
                string nombrenodo = NombreNodoMinimized(obj);
                string mdlObjName = ModulesHelper.ObjectModuleName(obj);

                if (!modulosGeneXus.Contains(mdlObjName))
                {
                    if (mdlObjName != null && IncludedInGraph(obj))
                    {
                        if (!dic.ContainsKey(mdlObjName))
                        {
                            HashSet <string> set = new HashSet <string>(new List <string> {
                                nombrenodo
                            });
                            dic.Add(mdlObjName, set);
                        }
                        else
                        {
                            dic[mdlObjName].Add(nombrenodo);
                        }
                    }
                }
            }

            foreach (string mdl in dic.Keys)
            {
                string modulename = mdl;
                string nodos      = "";

                string vacioOcoma = " ";

                foreach (string objname in dic[mdl])
                {
                    nodos     += vacioOcoma + objname;
                    vacioOcoma = ", ";
                }
                if (nodos != "")
                {
                    scriptFile.WriteLine("SS(" + modulename + ".ss) = " + nodos);
                }
            }
            scriptFile.Close();
        }
Example #3
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();
        }
Example #4
0
 /// <summary>
 /// Lista las tablas de los modulos.
 /// </summary>
 /// <param name="cmdData"></param>
 /// <returns></returns>
 public bool ExecListTablesInModules(CommandData cmdData)
 {
     ModulesHelper.ListTableInModules();
     return(true);
 }
Example #5
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();
        }
Example #6
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();
            }
        }
Example #7
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();
        }
Example #8
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();
        }
Example #9
0
 public bool ExecBuildModule(CommandData cmdData)
 {
     //Hace el Build with this only de los objetos de un modulo y de los que lo referencian
     ModulesHelper.BuildModule();
     return(true);
 }
Example #10
0
 public bool ExecModuleDependencies(CommandData cmdData)
 {
     ModulesHelper.ModuleDependencies();
     return(true);
 }
Example #11
0
 /// <summary>
 /// Lista las objetos con tablas en modulos diferentes al suyo.
 /// </summary>
 /// <param name="cmdData"></param>
 /// <returns></returns>
 public bool ExecListObjectsWithTableInOtherModule(CommandData cmdData)
 {
     ModulesHelper.ListObjectsWithTableInOtherModule();
     return(true);
 }
Example #12
0
 public bool ExecRecomendedModule(CommandData cmdData)
 {
     ModulesHelper.RecomendedModule();
     return(true);
 }
Example #13
0
 public bool ExecMoveTransactions(CommandData cmdData)
 {
     ModulesHelper.MoveTransactions();
     return(true);
 }
Example #14
0
 public bool ExecListModulesStatistics(CommandData cmdData)
 {
     ModulesHelper.ListModulesStatisticsTotal();
     return(true);
 }
Example #15
0
 public bool ExecListModules(CommandData cmdData)
 {
     ModulesHelper.ListModulesErrors();
     return(true);
 }
Example #16
0
 public bool ExecMarkPublicObjects(CommandData cmdData)
 {
     ModulesHelper.MarkPublicObjects();
     return(true);
 }
Example #17
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);
            }
        }