public void CSVSelectObjectSkipPartialDataTest() { const string key = "CSVSelectObjectSkipPartialDataTest"; try { var buffer = new byte[256]; byte[] binaryData = Encoding.ASCII.GetBytes("abc,def\nefg\nhij,klm\n"); var stream = new MemoryStream(binaryData); _ossClient.PutObject(_bucketName, key, stream); var request = new SelectObjectRequest(_bucketName, key); request.Expression = "select _1, _2 from ossobject"; //with SkipPartial var inputFormat = new SelectObjectCSVInputFormat(); request.InputFormat = inputFormat; var options = new SelectObjectOptions(); options.SkipPartialDataRecord = true; request.Options = options; try { _ossClient.SelectObject(request); Assert.IsTrue(false); } catch (OssException e) { Assert.AreEqual("InvalidCsvLine", e.ErrorCode); } //without SkipPartial binaryData = Encoding.ASCII.GetBytes("abc,def\nefg\nhij,klm\n123,456\n"); stream = new MemoryStream(binaryData); _ossClient.PutObject(_bucketName, key, stream); request = new SelectObjectRequest(_bucketName, key); request.Expression = "select _1, _2 from ossobject"; inputFormat = new SelectObjectCSVInputFormat(); request.InputFormat = inputFormat; options = new SelectObjectOptions(); options.SkipPartialDataRecord = false; request.Options = options; var result = _ossClient.SelectObject(request); var got = result.Content.Read(buffer, 0, buffer.Length); Assert.AreEqual("abc,def\nefg,\nhij,klm\n123,456\n", Encoding.Default.GetString(buffer, 0, got)); } finally { _ossClient.DeleteObject(_bucketName, key); } }
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); }
/// <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(); } }
public static IList <KBObject> SelectObjects() { SelectObjectOptions selectObjectOption = new SelectObjectOptions(); selectObjectOption.Filters.Add(obj => IsCodeReviewExportable(obj)); selectObjectOption.MultipleSelection = true; IList <KBObject> objects = UIServices.SelectObjectDialog.SelectObjects(selectObjectOption); return(objects); }
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); }
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("KBDoctor", title); try { string outputFile = Functions.CreateOutputFile(kbserv, title); KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8); writer.AddHeader(title); writer.AddTableHeader(new string[] { "Object", "Description", "Tipo" }); int cantObjChanged = 0; SelectObjectOptions selectObjectOption = new SelectObjectOptions { MultipleSelection = true }; // selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get<Procedure>()); // selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get<WebPanel>()); foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption)) { if (obj.Description.StartsWith("Work With")) { writer.AddTableData(new string[] { obj.Name, obj.Description, obj.TypeDescriptor.Name }); obj.Description = obj.Description.Replace("Work With ", "Trabajar con "); obj.Save(); } } writer.AddFooter(); writer.Close(); bool success = true; KBDoctorOutput.EndSection(title, success); KBDoctorOutput.Message("Object changed " + cantObjChanged.ToString()); KBDoctorHelper.ShowKBDoctorResults(outputFile); } catch { bool success = false; KBDoctor.KBDoctorOutput.EndSection(title, success); } }
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); }
/* * * 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); }
// Get object in a bucket public async static Task Run(MinioClient minio, string bucketName = "my-bucket-name", string objectName = "my-object-name", string fileName = "my-file-name") { try { Console.WriteLine("Running example for API: SelectObjectContentAsync"); var opts = new SelectObjectOptions() { ExpressionType = QueryExpressionType.SQL, Expression = "select count(*) from s3object", InputSerialization = new SelectObjectInputSerialization() { CompressionType = SelectCompressionType.NONE, CSV = new CSVInputOptions() { FileHeaderInfo = CSVFileHeaderInfo.None, RecordDelimiter = "\n", FieldDelimiter = ",", } }, OutputSerialization = new SelectObjectOutputSerialization() { CSV = new CSVOutputOptions() { RecordDelimiter = "\n", FieldDelimiter = ",", } } }; var resp = await minio.SelectObjectContentAsync(bucketName, objectName, opts); resp.Payload.CopyTo(Console.OpenStandardOutput()); Console.WriteLine("Bytes scanned:" + resp.Stats.BytesScanned); Console.WriteLine("Bytes returned:" + resp.Stats.BytesReturned); Console.WriteLine("Bytes processed:" + resp.Stats.BytesProcessed); if (resp.Progress != null) { Console.WriteLine("Progress :" + resp.Progress.BytesProcessed); } } catch (Exception e) { Console.WriteLine($"[Bucket] Exception: {e}"); } }
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); } } }
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); }
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); }
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); }
/// <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); } }
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); }
public bool ExecReviewObjects(CommandData cmdData) { IOutputService output = CommonServices.Output; output.SelectOutput("KBDoctor"); SelectObjectOptions selectObjectOption = new SelectObjectOptions(); selectObjectOption.MultipleSelection = true; KBModel kbModel = UIServices.KB.CurrentModel; List <KBObject> selectedObjects = new List <KBObject>(); foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption)) { if (obj != null) { selectedObjects.Add(obj); } } Thread thread = new Thread(() => KBDoctorCore.Sources.API.PreProcessPendingObjects(UIServices.KB.CurrentKB, output, selectedObjects)); thread.Start(); return(true); }
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); } }
public SelectObjectContentArgs() { this.RequestMethod = Method.POST; this.SelectOptions = new SelectObjectOptions(); }
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); }
public override void Exec(CommandData cmdData) { SelectObjectOptions dialogInfo = new SelectObjectOptions(); dialogInfo.ObjectTypes.Add(KBObjectDescriptor.Get<Gx.WebPanel>()); dialogInfo.ObjectTypes.Add(KBObjectDescriptor.Get<Gx.Transaction>()); dialogInfo.MultipleSelection = true; IList<KBObject> selectedObjects = UIServices.SelectObjectDialog.SelectObjects(dialogInfo); if (selectedObjects != null && selectedObjects.Count != 0) { foreach (KBObject selectedObj in selectedObjects) { PatternInstanceElement tabAttElement = BaseElement.Children.AddNewElement(InstanceChildren.Tabs.Tab); tabAttElement.Attributes[InstanceAttributes.Tab.Name] = selectedObj.Name; tabAttElement.Attributes[InstanceAttributes.Tab.Code] = selectedObj.Name; tabAttElement.Attributes[InstanceAttributes.Tab.Description] = selectedObj.Description; String tipo = TabElement.TypeValue.UserDefined; if (selectedObj is Gx.Transaction) { string[] btns = { "UserDefined", "Tabular", "Grid"}; int i = StandardMessageBox.Show("Qual tipo de aba ?", "Adicionar Aba", btns, ExceptionMessageBoxSymbol.Question, 0, ExceptionMessageBoxOptions.None); switch (i) { case 1: tipo = TabElement.TypeValue.Tabular; break; case 2: tipo = TabElement.TypeValue.Grid; break; } } tabAttElement.Attributes[InstanceAttributes.Tab.Type] = tipo; switch (tipo) { case TabElement.TypeValue.UserDefined: tabAttElement.Attributes[InstanceAttributes.Tab.Wcname] = selectedObj.Name; break; case TabElement.TypeValue.Tabular: tabAttElement.Attributes[InstanceAttributes.Tab.Wcname] = BaseElement.Instance.Parent.Name+selectedObj.Name; if (selectedObj is Gx.Transaction) { Gx.Transaction gxt = (Gx.Transaction)selectedObj; AddTrn(tabAttElement, gxt); PatternInstanceElement actsElement = tabAttElement.Children.AddNewElement(InstanceChildren.Tab.Actions); actsElement.Children.AddNewElement(InstanceChildren.Actions.Action).Attributes[InstanceAttributes.Action.Name] = Helpers.StandardAction.Update; actsElement.Children.AddNewElement(InstanceChildren.Actions.Action).Attributes[InstanceAttributes.Action.Name] = Helpers.StandardAction.Delete; } break; case TabElement.TypeValue.Grid: tabAttElement.Attributes[InstanceAttributes.Tab.Wcname] = BaseElement.Instance.Parent.Name+selectedObj.Name + "WC"; if (selectedObj is Gx.Transaction) { Gx.Transaction gxt = (Gx.Transaction)selectedObj; AddTrn(tabAttElement, gxt); PatternInstanceElement modesElement = tabAttElement.Children.AddNewElement(InstanceChildren.Tab.Modes); HPatternSettings sett = HPatternSettings.Get(BaseElement.Instance.Model); modesElement.Attributes[InstanceAttributes.Modes.InsertCondition] = sett.StandardActions.Insert.Condition; modesElement.Attributes[InstanceAttributes.Modes.UpdateCondition] = sett.StandardActions.Update.Condition; modesElement.Attributes[InstanceAttributes.Modes.DeleteCondition] = sett.StandardActions.Delete.Condition; modesElement.Attributes[InstanceAttributes.Modes.DisplayCondition] = sett.StandardActions.Display.Condition; modesElement.Attributes[InstanceAttributes.Modes.ExportCondition] = sett.StandardActions.Export.Condition; } break; } } } }
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); }
/// <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); } } } }
public static void ObjectsReferenced() { // Object with parm() rule without in: out: or inout: IKBService kbserv = UIServices.KB; IOutputService output = CommonServices.Output; string title = "KBDoctor - Object referenced by object "; output.StartSection(title); string outputFile = Functions.CreateOutputFile(kbserv, title); KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8); SelectObjectOptions selectObjectOption = new SelectObjectOptions(); selectObjectOption.MultipleSelection = false; KBModel kbModel = UIServices.KB.CurrentModel; KBObjectCollection objRefCollection = new KBObjectCollection(); foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption)) { if (obj != null) { title += obj.Name + "-" + obj.Description; writer.AddHeader(title); writer.AddTableHeader(new string[] { "Object", "Description", "Commit on Exit", "Update DB?", "Commit in Source", "Do Commit", "Timestamp", "Last Update" }); MarkReachables(output, obj, objRefCollection); } } string commitOnExit = ""; string commitInSource = ""; string UpdateInsertDelete = ""; string doCommit = ""; foreach (KBObject objRef in objRefCollection) { if (objRef is Procedure) { object aux = objRef.GetPropertyValue("CommitOnExit"); if (aux != null) { commitOnExit = aux.ToString() == "Yes" ? "YES" : " "; } UpdateInsertDelete = ObjectUpdateDB(objRef)?"YES":""; Procedure prc = (Procedure)objRef; if (Functions.ExtractComments(prc.ProcedurePart.Source.ToString().ToUpper()).Contains("COMMIT")) { commitInSource = "YES"; } else { commitInSource = ""; } if (((commitOnExit == "YES") && (UpdateInsertDelete == "YES")) || (commitInSource == "YES")) { doCommit = "YES"; } else { doCommit = ""; } writer.AddTableData(new string[] { Functions.linkObject(objRef), objRef.Description, commitOnExit, UpdateInsertDelete, commitInSource, doCommit, objRef.Timestamp.ToString(), objRef.LastUpdate.ToString() }); } } writer.AddFooter(); writer.Close(); bool success = true; output.EndSection(title, success); KBDoctorHelper.ShowKBDoctorResults(outputFile); }
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); }