示例#1
0
        /// <summary>
        /// Crea un procedure con todos los SDT seleccionados por el usuario.
        /// </summary>
        public static void CreateProcedureSDT()
        {
            IKBService kB = UIServices.KB;

            if (kB != null && kB.CurrentModel != null)
            {
                SelectObjectOptions selectObjectOption = new SelectObjectOptions();
                selectObjectOption.MultipleSelection = true;
                KBModel kbModel = UIServices.KB.CurrentModel;

                Artech.Genexus.Common.Objects.Procedure proc = new Artech.Genexus.Common.Objects.Procedure(kbModel);
                string procName = "SDTForceGenerate";

                proc.Name = procName;
                proc.ProcedurePart.Source = "// Generated by KBDoctor, to generate SDT source";
                proc.SetPropertyValue("IsMain", true);
                proc.Save();

                //MUESTRO LOS SDT A REGENERAR
                selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <SDT>());
                foreach (KBObject kBObject in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
                {
                    SDT sdtObj = (SDT)kBObject;
                    CodeGeneration.AddSDTVariable(kbModel, proc, sdtObj);
                    Application.DoEvents();
                }

                proc.Save();


                //Para cada uno de los generadores del environment, genero el proc con los SDT.

                GxModel gm = UIServices.KB.WorkingEnvironment.TargetModel.GetAs <GxModel>();

                foreach (var gen in gm.Environments)
                {
                    int generator = gen.Generator;

                    KBObject copy = BLServices.KnowledgeManager.Clone(proc);
                    copy.Name = procName + "_" + generator.ToString();
                    copy.SetPropertyValue(Artech.Genexus.Common.Properties.TRN.Generator, new EnvironmentCategoryReference {
                        Definition = gen
                    });
                    UIServices.Objects.Save(copy);

                    GenexusUIServices.Build.Rebuild(copy.Key);

                    do
                    {
                        Application.DoEvents();
                    } while (GenexusUIServices.Build.IsBuilding);
                    copy.Delete();
                }
                proc.Delete();
            }
        }
示例#2
0
        public static void RecomendedModule()
        {
            IKBService kbserv = UIServices.KB;

            Dictionary <string, KBObjectCollection> dic = new Dictionary <string, KBObjectCollection>();

            string title      = "KBDoctor - Recomended module";
            string outputFile = Functions.CreateOutputFile(kbserv, title);

            IOutputService output = CommonServices.Output;

            output.StartSection(title);

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

            writer.AddHeader(title);
            int numObj = 0;

            writer.AddTableHeader(new string[] { "Type", "Object", "Module", "List of modules" });


            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))
            {
                foreach (KBObject obj in module.GetAllMembers())
                {
                    if (Functions.hasModule(obj))
                    {
                        output.AddLine(obj.Name);
                        string moduleListString = "";
                        foreach (Module mod in ListModulesOfReferencedTables(obj))
                        {
                            moduleListString += mod.Name + " ";
                        }

                        if (obj.Module.Name != moduleListString.Trim() && moduleListString.Trim() != "")
                        {
                            writer.AddTableData(new string[] { obj.TypeDescriptor.Name + " ", Functions.linkObject(obj), obj.Module.Name, moduleListString });
                        }
                    }
                }
            }
            writer.AddFooter();
            writer.Close();

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

            output.EndSection(title, success);
        }
示例#3
0
        internal static void CreateModuleNamesFile(KnowledgeBase KB)
        {
            string             pathNvg = Path.Combine(Utility.SpcDirectory(KB), "NvgComparer");
            string             path    = pathNvg + "\\ModuleNames.txt";
            KBObjectDescriptor kbod    = KBObjectDescriptor.Get("Module");
            List <string>      lines   = new List <string>();

            foreach (KBObject obj in KB.DesignModel.Objects.GetAll(kbod.Id))
            {
                lines.Add(obj.QualifiedName.ToString());
            }
            File.WriteAllLines(path, SortModulesByLevel(lines).ToArray());
        }
示例#4
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);
        }
示例#5
0
        /*
         *
         * Dependencias Entrantes
         * Dependencias Salientes
         * IE = Salientes / (Entrantes + Salientes)
         #Componentes Conexos dentro del módulo.
         * Tiene dependencia cíclicla ?
         * Largo máximo de dependencias en la que participa.
         * El módulo tiene objetos públicos no referenciados por externos?
         */

        public static void ListModulesStatistics()
        {
            IKBService     kbserv     = UIServices.KB;
            IOutputService output     = CommonServices.Output;
            bool           success    = true;
            int            objInRoot  = 0;
            int            objSinRoot = 0;
            string         title      = "KBDoctor - List Modules Statistics";

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

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Module", "Description", "Tables", "Public Tables", "Objects", "Public Obj", "Obj/Publ %", "In References", "Out References" });

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;
            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Module>());
            foreach (Module mdl in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                output.AddLine(mdl.Name + "....");
                string[] mdlStat = ModuleStats2(mdl);

                if (mdl.Name == "Root Module")
                {
                    objInRoot = Int32.Parse(mdlStat[4]);
                }
                else
                {
                    if (Int32.Parse(mdlStat[2]) != 0)
                    {
                        objSinRoot = objSinRoot + Int32.Parse(mdlStat[4]);
                    }
                }
                writer.AddTableData(mdlStat);
            }
            output.AddLine("");
            output.EndSection(title, success);
            int    ratio   = (objInRoot == 0) ? 0 : (objSinRoot * 100) / objInRoot;
            string Resumen = "Obj in Modules, Obj Root, Ratio  " + objSinRoot.ToString() + "," + objInRoot.ToString() + "," + ratio.ToString();

            writer.AddTableData(new string[] { Resumen });
            writer.AddFooter();
            writer.Close();
            KBDoctorHelper.ShowKBDoctorResults(outputFile);
            Functions.AddLineSummary("moduleStats.txt", Resumen);
        }
示例#6
0
        public static void CreateProcedureGetSet()
        {
            IKBService kB = UIServices.KB;

            if (kB != null && kB.CurrentModel != null)
            {
                SelectObjectOptions selectObjectOption = new SelectObjectOptions();
                selectObjectOption.MultipleSelection = false;
                KBModel kbModel = UIServices.KB.CurrentModel;

                selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Table>());
                List <Table> tablas = UIServices.SelectObjectDialog.SelectObjects(selectObjectOption) as List <Table>;
                foreach (Table tabla in tablas)
                {
                    string         title  = "KBDoctor - Generating Get/Set/Insert/Delete for table " + tabla.Name;
                    IOutputService output = CommonServices.Output;
                    output.StartSection(title);

                    try
                    {
                        output.AddLine(" Generating SDT");
                        SDT Sdt = GenerateSdt(tabla);

                        output.AddLine(" Generating Procedure GET");
                        GenerateGetProcedure(kbModel, tabla, Sdt);

                        output.AddLine(" Generating Procedure SET");
                        GenerateSetProcedure(kbModel, tabla, Sdt);

                        output.AddLine(" Generating Procedure INSERT");
                        GenerateInsertProcedure(kbModel, tabla, Sdt);

                        output.AddLine(" Generating DataProvider");
                        GenerateDataProvider(kbModel, tabla, Sdt);

                        output.AddLine(" Generating Exist");
                        GenerateExistProcedure(kbModel, tabla, Sdt);
                    }
                    catch (Exception ex)
                    {
                        output.AddErrorLine(ex);
                    }
                    Application.DoEvents();
                    output.EndSection(title, true);
                }
            }
        }
示例#7
0
 public static KBObject ObjectHelperGet(KBModel model, string name, bool checkPrefix)
 {
     if (checkPrefix)
     {
         int num = name.IndexOf(':');
         if (num > 0)
         {
             string             arg_22_0           = name.Substring(0, num);
             string             name2              = name.Substring(num + 1);
             KBObjectDescriptor kBObjectDescriptor = KBObjectDescriptor.Get(arg_22_0);
             if (kBObjectDescriptor != null)
             {
                 return(ObjectHelperGet(model, kBObjectDescriptor.Id, name2));
             }
         }
     }
     return(ObjectHelperGet(model, name));
 }
示例#8
0
        public static void BuildModule()
        {
            IKBService     kbserv  = UIServices.KB;
            KBModel        kbModel = UIServices.KB.CurrentModel;
            IOutputService output  = CommonServices.Output;

            bool   success = true;
            string title   = "KBDoctor - Build Module";

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

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

            KBObjectCollection objToBuild = new KBObjectCollection();

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;

            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Module>());
            foreach (Module mdl in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                foreach (KBObject o in CreateListObjectsModuleAndReferences(kbModel, mdl, writer))
                {
                    objToBuild.Add(o);
                }
            }

            writer.AddFooter();
            writer.Close();
            KBDoctorHelper.ShowKBDoctorResults(outputFile);

            GenexusUIServices.Build.BuildWithTheseOnly(objToBuild.Keys);

            do
            {
                Application.DoEvents();
            } while (GenexusUIServices.Build.IsBuilding);

            output.EndSection("KBDoctor", true);
        }
示例#9
0
        public static void AddINParmRule()
        {
            // Object with parm() rule without in: out: or inout:
            IKBService     kbserv = UIServices.KB;
            IOutputService output = CommonServices.Output;
            string         title  = "KBDoctor - ADD IN: to Parm() rule";

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


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

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Object", "Description", "Param rule" });
            int cantObjChanged = 0;

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

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

            foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                string oldParm = Functions.ExtractRuleParm(obj);
                string newParm = ChangeRuleParmWithIN(obj);
                if (newParm != "")
                {
                    cantObjChanged += 1;
                    PrintNewRuleParm(writer, obj, oldParm, newParm);
                }
            }

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

            bool success = true;

            output.EndSection(title, success);
            output.AddLine("Object changed " + cantObjChanged.ToString());

            KBDoctorHelper.ShowKBDoctorResults(outputFile);
        }
示例#10
0
        public static void MoveTransactions()
        {
            IKBService     kbserv     = UIServices.KB;
            IOutputService output     = CommonServices.Output;
            bool           success    = true;
            int            objInRoot  = 0;
            int            objSinRoot = 0;
            string         title      = "KBDoctor - Move Transaction";

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

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Transaction", "Description", "Table", "Most referenced in Folder" });

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;
            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Transaction>());
            foreach (Transaction trn in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                foreach (TransactionLevel lvl in trn.Structure.GetLevels())
                {
                    Table         tbl      = lvl.AssociatedTable;
                    List <string> fldlist  = MostReferencedInFolder(tbl);
                    string        listatxt = "";
                    foreach (string s in fldlist)
                    {
                        listatxt += s + "<br>";
                    }

                    writer.AddTableData(new string[] { Functions.linkObject(trn), trn.Description, Functions.linkObject(tbl), listatxt });
                }
            }


            writer.AddFooter();
            writer.Close();
            KBDoctorHelper.ShowKBDoctorResults(outputFile);
        }
示例#11
0
        /// <summary>
        /// Clean and destroy objects. Initizlize objects
        /// </summary>
        public static void CleanObjects(KBModel kbmodel, IOutputService output)
        {
            IKBService kB = UIServices.KB;

            if (kB != null && kB.CurrentModel != null)
            {
                SelectObjectOptions selectObjectOption = new SelectObjectOptions();
                selectObjectOption.MultipleSelection = true;
                output.StartSection("Cleaning objects");

                selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Transaction>());
                selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Procedure>());
                selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <WorkPanel>());
                selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <WebPanel>());
                foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
                {
                    CleanObject(obj, output);
                }
                output.EndSection("Cleaning objects", true);
            }
        }
示例#12
0
        public static void ListModulesErrors()
        {
            IKBService     kbserv  = UIServices.KB;
            IOutputService output  = CommonServices.Output;
            bool           success = true;

            string title = "KBDoctor - List Modules Errors";

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

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] {
                "Module", "Warning Public Objects not referenced", "ERROR Private Objects Referenced", "ERROR  Reference private Tables", "ERROR Update outside Module", "Object to Move"
            });

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;
            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Module>());
            foreach (Module mdl in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                if (mdl is Module)
                {
                    output.AddLine(mdl.Name + "....");
                    string[] mdlStat = ModuleStats((Module)mdl);

                    writer.AddTableData(mdlStat);
                }
            }
            output.AddLine("");
            output.EndSection(title, success);

            writer.AddFooter();
            writer.Close();
            KBDoctorHelper.ShowKBDoctorResults(outputFile);
        }
示例#13
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);
        }
示例#14
0
        /// <summary>
        /// Search and replace text in objects
        /// </summary>
        public static void SearchAndReplace() //SearchAndReplace()
        {
            IKBService     kB     = UIServices.KB;
            IOutputService output = CommonServices.Output;

            string mensaje = "";
            string title   = "Search and replace";

            output.StartSection(title);
            if (kB != null && kB.CurrentModel != null)
            {
                PromptDescription pd;
                DialogResult      dr;
                mensaje = "Find";

                pd = new PromptDescription(mensaje);
                dr = pd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    string txtfind = pd.Description;
                    mensaje = "Replace with";
                    pd      = new PromptDescription(mensaje);
                    dr      = pd.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        string txtreplace = pd.Description;
                        SelectObjectOptions selectObjectOption = new SelectObjectOptions();
                        selectObjectOption.MultipleSelection = true;
                        KBModel kbModel = UIServices.KB.CurrentModel;

                        int objcambiados = 0;
                        int objtotales   = 0;
                        //SELECCIONO OBJETOS A BUSCAR
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Procedure>());
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Transaction>());
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <WebPanel>());
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <WorkPanel>());

                        foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
                        {
                            objtotales += 1;
                            Application.DoEvents();
                            if ((objtotales % 100) == 0)
                            {
                                output.AddLine("Searching in " + objtotales + " objects ");
                            }

                            StringBuilder buffer = new StringBuilder();
                            using (TextWriter writer = new StringWriter(buffer))
                                obj.Serialize(writer);

                            string objxml    = buffer.ToString();
                            string newobjxml = objxml.Replace(txtfind, txtreplace, StringComparison.InvariantCultureIgnoreCase);

                            using (StringReader strReader = new StringReader(newobjxml))
                                using (XmlTextReader reader = new XmlTextReader(strReader))
                                    BLServices.KnowledgeManager.ImportInObject(reader, obj);
                            if (objxml != newobjxml)
                            {
                                try
                                {
                                    obj.Save();
                                    output.AddLine("Changed >> '" + txtfind + "' to '" + txtreplace + "' in object " + obj.Name);
                                    objcambiados += 1;
                                }
                                catch (Exception e)
                                {
                                    if (e.InnerException == null)
                                    {
                                        output.AddErrorLine(e.Message);
                                    }
                                    else
                                    {
                                        output.AddErrorLine(e.Message + " - " + e.InnerException);
                                    }
                                };
                            }
                        }
                        title = "Changed objects " + objcambiados.ToString();
                        output.EndSection(title, true);
                    }
                }
            }
        }
示例#15
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);
            }
        }
示例#16
0
        internal static void ListTableInModules()
        {
            IKBService kbserv = UIServices.KB;
            KBModel    model  = kbserv.CurrentModel.GetDesignModel();

            string         title  = "KBDoctor - List tables in modules";
            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", "Visibility", "Best", "Best Module", "Modules", "Transaction", "Trn(NoGenerate)", "Referenced Modules", "Referenced"
            });

            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;
            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Module>());
            foreach (KBObject module in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                foreach (Table t in Table.GetAll(module.Model))

                {
                    if (TablesHelper.TableModule(module.Model, t) == module)
                    {
                        string objNameLink = Functions.linkObject(t);

                        output.AddLine("Processing... " + t.Name);

                        int countAttr     = 0;
                        int countKeyAttr  = 0;
                        int widthKey      = 0;
                        int width         = 0;
                        int widthVariable = 0;
                        int widthFixed    = 0;

                        ObjectVisibility objVisibility = TableVisibility(t);
                        KBObject         trnBest       = GenexusBLServices.Tables.GetBestAssociatedTransaction(model, t.Key);
                        Module           mdlTrnBest    = trnBest.Module;

                        string        trnGen   = "";
                        string        trnNoGen = "";
                        List <string> mdlList  = new List <string>();
                        foreach (Transaction trn in t.AssociatedTransactions)

                        {
                            string trnstr = Functions.linkObject(trn) + "(" + ((trn.IsPublic) ? "Public" : "Private") + ") <br/> ";
                            if (trn.GetPropertyValue <bool>(Properties.TRN.GenerateObject))
                            {
                                trnGen += trnstr;
                            }
                            else
                            {
                                trnNoGen += trnstr;
                            }

                            if (!mdlList.Contains(trn.Module.Name))
                            {
                                mdlList.Add(trn.Module.Name);
                            }
                        }


                        IList <KBObject> objList = (from r in model.GetReferencesTo(t.Key, LinkType.UsedObject)
                                                    where r.ReferenceType == ReferenceType.WeakExternal // las referencias a tablas que agrega el especificador son de este tipo
                                                                                                        //where ReferenceTypeInfo.HasUpdateAccess(r.LinkTypeInfo)
                                                    select model.Objects.Get(r.From)).ToList();

                        IList <KBObject> objList2 = objList.Where(r => r.Module != mdlTrnBest).ToList();

                        string objListQNames = null;
                        objList2.ToList().ForEach(v => objListQNames += " " + Functions.linkObject(v));

                        List <string> mdlReferencedList = new List <string>();
                        foreach (KBObject o in objList)
                        {
                            if (!mdlReferencedList.Contains(o.Module.Name))
                            {
                                mdlReferencedList.Add(o.Module.Name);
                            }
                        }

                        string mdlListstr           = String.Join(" ", mdlList.ToArray());
                        string mdlReferencedListstr = String.Join(" ", mdlReferencedList.ToArray());

                        writer.AddTableData(new string[] {
                            objNameLink, t.Description, objVisibility.ToString(), trnBest.QualifiedName.ToString(), mdlTrnBest.Name,
                            mdlListstr, trnGen, trnNoGen, mdlReferencedListstr, objListQNames
                        });
                    }
                }
            }


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

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

            output.EndSection(title, success);
        }
示例#17
0
        internal static bool CompareLastNVGDirectories(KnowledgeBase KB, IOutputService output)
        {
            try
            {
                bool     isSuccess        = true;
                string   pathNvg          = Path.Combine(Utility.SpcDirectory(KB), "NvgComparer");
                string   fileWildcard     = @"*.*";
                string[] Files            = Directory.GetDirectories(pathNvg, fileWildcard);
                string[] Last2directories = GetLast2Directorys(Files, output);
                int      cant_error       = 0;
                if (Last2directories == null || Last2directories.Length != 2)
                {
                    output.AddErrorLine("Ocurrió un error procesando los directorios de navegaciones.");
                    output.AddErrorLine("Asegúrece de que existen al menos dos directorios con nombres en el formato válido (NVG-AAAA-MM-DD-HHMM)");
                }
                else
                {
                    KBDoctorOutput.Message("Se utilizarán los siguientes directorios para comparar:");
                    KBDoctorOutput.Message("-- " + Last2directories[0].ToString());
                    KBDoctorOutput.Message("-- " + Last2directories[1].ToString());
                    List <string> Diffs = EqualNavigationDirectories(Last2directories[0], Last2directories[1], output);
                    KBDoctorOutput.Message("-- Los directorios se procesaron correctamente.");
                    if (Diffs.Count > 0)
                    {
                        KBDoctorOutput.Message("-- Se encontraron diferencias en las navegaciones de los siguientes objetos:");
                        List <string> FilesDiff = new List <string>();
                        foreach (string x in Diffs)
                        {
                            string[]           objectnametype = Utility.ReadQnameTypeFromNVGFile(x, output);
                            string             filename       = Path.GetFileName(x);
                            string             objtype        = objectnametype[0];
                            string             objmodule      = objectnametype[1];
                            string             objname        = objectnametype[2];
                            KBObjectDescriptor kbod           = KBObjectDescriptor.Get(objtype);
                            QualifiedName      qname          = new QualifiedName(objmodule, objname);
                            //Null in HCIHisMo
                            KBObject obj = KB.DesignModel.Objects.Get(kbod.Id, qname);
                            if (obj != null)
                            {
                                if (obj.Timestamp <= Utility.GetDateTimeNVGDirectory(Last2directories[1].ToString()))
                                {
                                    FilesDiff.Add(filename);
                                    if (objmodule != "")
                                    {
                                        KBDoctorOutput.Message("-- ERROR " + objmodule + '.' + objname + " fue modificado en \t\t" + obj.Timestamp.ToString());
                                    }
                                    else
                                    {
                                        KBDoctorOutput.Message("-- ERROR " + objname + " fue modificado en \t\t" + obj.Timestamp.ToString());
                                    }

                                    isSuccess = false;
                                    cant_error++;
                                }
                                else
                                {
                                    if (objmodule != "")
                                    {
                                        KBDoctorOutput.Message("-- -- OK " + objmodule + '.' + objname + " fue modificado en \t\t" + obj.Timestamp.ToString());
                                    }
                                    else
                                    {
                                        KBDoctorOutput.Message("-- -- OK " + objname + " fue modificado en \t\t" + obj.Timestamp.ToString());
                                    }
                                }
                            }
                            else
                            {
                                KBDoctorOutput.Message("-- NO SE ENCONTRO EL OBJETO: " + qname.ToString());
                            }
                        }
                        CopyDifferences(FilesDiff, Last2directories[0], Last2directories[1], "NvgErrors");
                    }
                    else
                    {
                        DeleteDifferenceDir(KB);
                        KBDoctorOutput.Message("No se encontraron diferencias en las navegaciones");
                    }
                }
                if (cant_error > 0)
                {
                    output.AddErrorLine("Se encontraron " + cant_error + " errores en la comparación.");
                }
                return(isSuccess);
            }
            catch (Exception e)
            {
                KBDoctorOutput.Message(e.Message);
                return(false);
            }
        }
示例#18
0
        public static void ReplaceNullsCompatible()
        {
            IKBService     kbserv     = UIServices.KB;
            IOutputService output     = CommonServices.Output;
            string         title      = "KBDoctor - Replace attribute with Compatible with NO ";
            string         outputFile = Functions.CreateOutputFile(kbserv, title);

            output.StartSection(title);

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

            writer.AddHeader(title);
            writer.AddTableHeader(new string[] { "Object", "Description", "Attribute", "Description", "PK / FK", "Nullable" });


            SelectObjectOptions selectObjectOption = new SelectObjectOptions();

            selectObjectOption.MultipleSelection = true;
            KBModel kbModel = UIServices.KB.CurrentModel;

            selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Transaction>());

            foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
            {
                bool        saveObj = false;
                Transaction trn     = (Transaction)obj;
                if (trn != null)
                {
                    foreach (TransactionLevel LVL in trn.Structure.GetLevels())
                    {
                        bool isLevelRemovable = true;

                        Table TBL = LVL.AssociatedTable;

                        foreach (TransactionAttribute a in LVL.Structure.GetAttributes())
                        {
                            output.AddLine(a.Name);
                            writer.AddTableData(new string[] { Functions.linkObject(trn), trn.Description, Functions.linkObject(a), a.Attribute.Description, a.IsForeignKey.ToString(), a.IsNullable.ToString() });
                            if (!a.IsForeignKey && !a.IsKey && (a.IsNullable == TableAttribute.IsNullableValue.Compatible || a.IsNullable == TableAttribute.IsNullableValue.True))
                            {
                                a.IsNullable = TableAttribute.IsNullableValue.False;
                                saveObj      = true;
                            }
                        }
                    }
                    if (saveObj)
                    {
                        output.AddLine("Saving ." + trn.Name);
                        trn.Save();
                    }
                }
            }

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

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

            output.EndSection(title, success);
        }
示例#19
0
        public static IEnumerable <KBObject> GetObjects(KBModel model, string objects)
        {
            Dictionary <EntityKey, bool> dictionary = new Dictionary <EntityKey, bool>();

            string[] array = objects.Split(new char[]
            {
                ';'
            });
            for (int i = 0; i < array.Length; i++)
            {
                string text = array[i];
                if (text[0] == '@')
                {
                    foreach (KBObject current in GetGXLObjects(model, text.Substring(1)))
                    {
                        if (!dictionary.ContainsKey(current.Key))
                        {
                            dictionary[current.Key] = true;
                            yield return(current);
                        }
                    }
                    IEnumerator <KBObject> enumerator = null;
                }
                else
                {
                    string text2 = null;
                    string text3 = text;
                    int    num   = text.IndexOf(':');
                    if (num > 0)
                    {
                        text2 = text.Substring(0, num);
                        text3 = text.Substring(num + 1);
                    }
                    KBObject kBObject = null;
                    string[] array2   = text3.Split(new char[]
                    {
                        ','
                    });
                    for (int j = 0; j < array2.Length; j++)
                    {
                        string name = array2[j];
                        if (text2 != null)
                        {
                            KBObjectDescriptor kBObjectDescriptor = KBObjectDescriptor.Get(text2);
                            if (kBObjectDescriptor != null)
                            {
                                kBObject = ObjectHelperGet(model, kBObjectDescriptor.Id, name);
                            }
                        }
                        else
                        {
                            kBObject = ObjectHelperGet(model, name);
                        }
                        if (kBObject != null && !dictionary.ContainsKey(kBObject.Key))
                        {
                            dictionary[kBObject.Key] = true;
                            yield return(kBObject);
                        }
                    }
                    array2   = null;
                    text2    = null;
                    kBObject = null;
                }
                text = null;
            }
            array = null;
            yield break;
            yield break;
        }