private static void ListCategories(KBObject obj, StreamWriter file) { //CATEGORIES IEnumerable <Artech.Udm.Framework.References.EntityReference> refe = obj.GetReferences(); string GUIDCatString = "00000000-0000-0000-0000-000000000006"; List <string> categories = new List <string>(); foreach (Artech.Udm.Framework.References.EntityReference reference in refe) { Guid GUIDRefTo = reference.To.Type; string GUIDRefToString = GUIDRefTo.ToString(); if (GUIDRefToString == GUIDCatString) { KBCategory cat = KBCategory.Get(UIServices.KB.CurrentModel, reference.To.Id); categories.Add(cat.Name); } } if (categories.Count > 0) { PrintSectionHeader("CATEGORIES", file); foreach (string name in categories) { file.WriteLine(name); } } }
private static KBObjectCollection CreatLocationCollection(string location) { KBObjectCollection objColl = new KBObjectCollection(); IKBService kB = UIServices.KB; IOutputService output = CommonServices.Output; KBCategory mainCategory = KBCategory.Get(kB.CurrentModel, "Main Programs"); foreach (KBObject obj in mainCategory.AllMembers) { string objLocation = (string)obj.GetProperty("AppLocation").Value; if (objLocation == "") { obj.SilentSetPropertyValue("AppLocation", "WEB"); } string objAppGenerator = obj.GetPropertyValueString("AppGenerator"); string Dircopia; if (objAppGenerator.ToUpper().Contains("WEB")) { Dircopia = "Web\\bin\\"; } else { Dircopia = "bin\\"; } if (objLocation == null) { objLocation = "none"; } string letra = ""; if (location == objLocation) { output.AddLine("set DESTINO=" + objLocation); output.AddLine("XCOPY " + Dircopia + obj.Name + ".dll %DESTINO%"); if (obj is Procedure) { letra = "a"; } if (obj is WorkPanel) { letra = "u"; } if (obj is Transaction) { letra = ""; } output.AddLine("XCOPY " + Dircopia + letra + obj.Name + ".dll %DESTINO%"); AddReferencedObj(objColl, obj, ""); } } return(objColl); }
public static void ListMainObj() { IKBService kbserv = UIServices.KB; Dictionary <string, KBObjectCollection> dic = new Dictionary <string, KBObjectCollection>(); string title = "KBDoctor - Main Objects"; 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", "Object", "Description", "Module", "Public", "Generator", "Protocol", "Last Update" }); KBCategory mainCategory = Functions.MainCategory(kbserv.CurrentModel); foreach (KBObject obj in mainCategory.AllMembers) { if (obj != null) { string desc = obj.Description.Replace(",", " "); desc = desc.Replace(">", ""); desc = desc.Replace("<", ""); string objAppGenerator = obj.GetPropertyValueString("AppGenerator"); string objProtocol = obj.GetPropertyValueString("CALL_PROTOCOL"); string isGenerated = KBDoctorCore.Sources.Utility.isGenerated(obj) ? "Yes" : ""; writer.AddTableData(new string[] { obj.TypeDescriptor.Name + " ", Functions.linkObject(obj), desc, obj.Module.Name, obj.IsPublic.ToString(), objAppGenerator, objProtocol, obj.LastUpdate.ToShortDateString() }); KBDoctorOutput.Message(obj.TypeDescriptor.Name + "," + obj.Name + "," + obj.Description); //+ "," + obj.Timestamp.ToString()); } } writer.AddFooter(); writer.Close(); KBDoctorHelper.ShowKBDoctorResults(outputFile); bool success = true; output.EndSection("KBDoctor", title, success); } catch { bool success = false; KBDoctor.KBDoctorOutput.EndSection(title, success); } }
private static void ProcessObjectsInCategory(IOutputService output, KBCategory Category) { bool stay = true; int pasada = 1; int borrados = 0; do { output.AddLine("Pass number " + pasada.ToString() + ". Cleaned objects: " + borrados.ToString()); stay = false; foreach (KBObject obj in Category.AllMembers) { if ((obj is Transaction) || (obj is Table) || (obj is Image) || (obj is Artech.Genexus.Common.Objects.Group) || (obj is DataView)) { output.AddLine("Skipping " + obj.Name); } else { try { obj.Delete(); output.AddLine("Removing : " + obj.Name); stay = true; borrados += 1; } catch { output.AddLine("ERROR: Can't remove :" + obj.Name); } } } pasada += 1; } while (stay); }
public static void CleanKBAsMuchAsPossible() { IKBService kbserv = UIServices.KB; IOutputService output = CommonServices.Output; string mensaje = "Do you have a backup?. Are you sure you want to clean the KB? Some objects will be modified and deleted."; DialogResult dr = MessageBox.Show(mensaje, "Clean KB", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { ObjectsHelper.CleanVarsNotUsed(); CleanKBHelper.RemoveAttributeWithoutTable(); ObjectsHelper.Unreachables(); KBCategory UnreachableCategory = KBCategory.Get(kbserv.CurrentModel, "KBDoctor.UnReachable"); foreach (KBObject obj in UnreachableCategory.AllMembers) { KBDoctorCore.Sources.API.CleanKBObject(obj, output); } ProcessObjectsInCategory(output, UnreachableCategory); output.AddLine("Finish"); } }
internal static KBCategory MainCategory(KBModel model) { return(KBCategory.Get(model, "Main Programs")); }
private static void WriteObjectContent(KBObject obj, StreamWriter file) { RulesPart rp = obj.Parts.Get <RulesPart>(); if (rp != null) { file.WriteLine(Environment.NewLine + "=== RULES ==="); file.WriteLine(rp.Source); } EventsPart ep = obj.Parts.Get <EventsPart>(); if (ep != null) { file.WriteLine(Environment.NewLine + "=== EVENTS SOURCE ==="); file.WriteLine(ep.Source); } switch (obj.TypeDescriptor.Name) { case "Attribute": Artech.Genexus.Common.Objects.Attribute att = (Artech.Genexus.Common.Objects.Attribute)obj; file.WriteLine(Functions.ReturnPicture(att)); if (att.Formula == null) { file.WriteLine(""); } else { file.WriteLine(att.Formula.ToString()); } break; case "Procedure": ProcedurePart pp = obj.Parts.Get <ProcedurePart>(); if (pp != null) { file.WriteLine(Environment.NewLine + "=== PROCEDURE SOURCE ==="); file.WriteLine(pp.Source); } break; case "Transaction": StructurePart sp = obj.Parts.Get <StructurePart>(); if (sp != null) { file.WriteLine(Environment.NewLine + "=== STRUCTURE ==="); file.WriteLine(sp.ToString()); } break; case "WorkPanel": break; case "WebPanel": break; case "WebComponent": break; case "Table": Table tbl = (Table)obj; foreach (TableAttribute attr in tbl.TableStructure.Attributes) { String line = ""; if (attr.IsKey) { line = "*"; } else { line = " "; } line += attr.Name + " " + attr.GetPropertiesObject().GetPropertyValueString("DataTypeString") + "-" + attr.GetPropertiesObject().GetPropertyValueString("Formula"); if (attr.IsExternalRedundant) { line += " External_Redundant"; } line += " Null=" + attr.IsNullable; if (attr.IsRedundant) { line += " Redundant"; } file.WriteLine(line); } break; case "SDT": SDT sdtToList = (SDT)obj; if (sdtToList != null) { file.WriteLine(Environment.NewLine + "=== STRUCTURE ==="); ListStructure(sdtToList.SDTStructure.Root, 0, file); } break; default: //Unknown object. Use export format. file.Write(SerializeObject(obj).ToString()); break; } file.WriteLine(Environment.NewLine + "====== PROPERTIES ======="); foreach (Property prop in obj.Properties) { if (!prop.IsDefault) { file.WriteLine(prop.Name + " -> " + prop.Value.ToString()); } else { if ((prop.Name == "CommitOnExit") || (prop.Name == "TRNCMT") || (prop.Name == "GenerateObject")) { file.WriteLine(prop.Name + " -> " + prop.Value.ToString()); } } } //CATEGORIES IEnumerable <Artech.Udm.Framework.References.EntityReference> refe = obj.GetReferences(); string GUIDCatString = "00000000-0000-0000-0000-000000000006"; List <string> categories = new List <string>(); foreach (Artech.Udm.Framework.References.EntityReference reference in refe) { Guid GUIDRefTo = reference.To.Type; string GUIDRefToString = GUIDRefTo.ToString(); if (GUIDRefToString == GUIDCatString) { KBCategory cat = KBCategory.Get(UIServices.KB.CurrentModel, reference.To.Id); categories.Add(cat.Name); } } if (categories.Count > 0) { file.WriteLine(Environment.NewLine + "====== CATEGORIES ======="); foreach (string name in categories) { file.WriteLine(name); } } }