public static void ProcesoDirNavigations(string directoryArg, IOutputService output, TextWriter writer2) { IKBService kbserv = UIServices.KB; string fileWildcard = @"*.xml"; var searchSubDirsArg = System.IO.SearchOption.AllDirectories; string[] xFiles = System.IO.Directory.GetFiles(directoryArg, fileWildcard, searchSubDirsArg); int numFiles = 0; foreach (string x in xFiles) { if (!Path.GetFileNameWithoutExtension(x).StartsWith("Gx0")) { if ((numFiles % 200) == 0) { output.AddLine(x); } numFiles += 1; string xmlstring = AddXMLHeader(x); KBObject obj = ExtractObject(xmlstring); if (!ObjectsHelper.isGeneratedbyPattern(obj)) { ProcesoNavigation(xmlstring, output, writer2, obj); } } } }
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); }
internal static void RenameVariables() { IKBService kbserv = UIServices.KB; string title = "KBDoctor - Object with variables not based on attribute/domain"; 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[] { "Type", "Name", "Variable", "Attribute", "Domain" }); Domain dom = Functions.DomainByName("Fecha"); //All useful objects are added to a collection foreach (KBObject obj in kbserv.CurrentModel.Objects.GetAll()) { KBDoctorOutput.Message("Procesing.... " + obj.Name + " - " + obj.Type.ToString()); Boolean SaveObj = false; if (Utility.isGenerated(obj) && !ObjectsHelper.isGeneratedbyPattern(obj) && (obj is Transaction || obj is WebPanel || obj is WorkPanel)) { Functions.AddLine("RenameVariables.txt", "##" + obj.Name); List <Variable> lstVariables = VariablesToRename(obj); } } string inputFile = kbserv.CurrentKB.UserDirectory + @"\RenameVariables.txt"; // Input List <String> data = File.ReadAllLines(inputFile).Distinct(StringComparer.CurrentCultureIgnoreCase).ToList(); // Processing data.Sort(); // Output string outputFile2 = kbserv.CurrentKB.UserDirectory + @"\RenameVariables2.txt"; File.WriteAllLines(outputFile2, data.ToArray()); writer.AddFooter(); writer.Close(); KBDoctorHelper.ShowKBDoctorResults(outputFile); bool success = true; output.EndSection("KBDoctor", title, success); } catch { bool success = false; KBDoctor.KBDoctorOutput.EndSection(title, success); } }
public static void RenameAttributesAndTables() { string message = "This option rename Objects (attributes, tables and objects) to significant name length. " + Environment.NewLine + Environment.NewLine + "Do you have KB BACKUP? "; const string caption = "ATTENTION!!"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); // If the no button was pressed ... if (result == DialogResult.Yes) { IKBService kbserv = UIServices.KB; KBModel model = kbserv.CurrentKB.DesignModel; int ATTNAME_LEN = model.GetPropertyValue <int>("ATTNAME_LEN"); int TBLNAME_LEN = model.GetPropertyValue <int>("TBLNAME_LEN"); int OBJNAME_LEN = model.GetPropertyValue <int>("OBJNAME_LEN"); string title = "KBDoctor - Rename Objects to significant name length"; string outputFile = Functions.CreateOutputFile(kbserv, title); KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8); writer.AddHeader(title); writer.AddTableHeader(new string[] { "Type", "Object", "Description" }); IOutputService output = CommonServices.Output; output.StartSection(title); foreach (KBObject obj in kbserv.CurrentModel.Objects.GetAll()) { Boolean SaveObj = false; if ((obj is Artech.Genexus.Common.Objects.Attribute) && (obj.Name.Length > ATTNAME_LEN)) { output.AddLine("RENAMING ATTRIBUTE " + obj.Name + " to " + obj.Name.Substring(0, ATTNAME_LEN)); obj.Name = obj.Name.Substring(0, ATTNAME_LEN); SaveObj = true; } else { if (((obj is Table) || (obj is Index)) && (obj.Name.Length > TBLNAME_LEN)) { output.AddLine("RENAMING TABLE/INDEX " + obj.Name + " to " + obj.Name.Substring(0, TBLNAME_LEN)); obj.Name = obj.Name.Substring(0, TBLNAME_LEN); SaveObj = true; } else { if ((obj.Name.Length > OBJNAME_LEN) && ObjectsHelper.isGeneratedbyPattern(obj)) { output.AddLine("RENAMING OBJECT " + obj.Name + " to " + obj.Name.Substring(0, OBJNAME_LEN)); obj.Name = obj.Name.Substring(0, OBJNAME_LEN); SaveObj = true; } } } if (SaveObj) { string attNameLink = Functions.linkObject(obj); writer.AddTableData(new string[] { attNameLink, obj.Description, obj.TypeDescriptor.Name }); try { obj.Save(); } catch (Exception e) { output.AddLine("ERROR saving .. " + obj.Name + " - " + e.Message); } } } writer.AddFooter(); writer.Close(); KBDoctorHelper.ShowKBDoctorResults(outputFile); bool success = true; output.EndSection(title, success); } }