public static void KillAttribute(Artech.Genexus.Common.Objects.Attribute a) { IOutputService output = CommonServices.Output; foreach (EntityReference reference in a.GetReferencesTo()) { KBObject objRef = KBObject.Get(a.Model, reference.From); if (objRef != null) { CleanVariablesBasedInAttribute(a, output, objRef); CleanSDT(a, output, objRef); } if (!(objRef is DataView)) { try { objRef.Save(); } catch (Exception e) { output.AddErrorLine("ERROR: Can't save object: " + objRef.Name + e.Message); } } } }
public static void ReplaceDomain() { IKBService kbserv = UIServices.KB; bool success = true; string title = "KBDoctor - Replace domain "; IOutputService output = CommonServices.Output; ReplaceDomain rd = new ReplaceDomain(); DialogResult dr = new DialogResult(); dr = rd.ShowDialog(); if (dr == DialogResult.OK) { output.StartSection(title); Domain od = Functions.DomainByName(rd.originalDomainName); Domain ud = Functions.DomainByName(rd.destDomainName); if (od != null && ud != null) { foreach (EntityReference reference in od.GetReferencesTo()) // LinkType.UsedObject)) { KBObject objRef = KBObject.Get(UIServices.KB.CurrentModel, reference.From); output.AddLine("Procesing " + objRef.Name); if (objRef is Artech.Genexus.Common.Objects.Attribute) { Artech.Genexus.Common.Objects.Attribute att = (Artech.Genexus.Common.Objects.Attribute)objRef; att.DomainBasedOn = ud; att.Save(); } else { VariablesPart vp = objRef.Parts.Get <VariablesPart>(); if (vp != null) { foreach (Variable v in vp.Variables) { if (v.DomainBasedOn == od && !v.IsStandard) { v.DomainBasedOn = ud; } } objRef.Save(); } else { output.AddLine("Replace " + od.Name + " domain manually in object " + objRef.Name); success = false; } } } } output.EndSection(title, success); } }
public static void SaveObject(IOutputService output, KBObject obj) { try { obj.Save(); } catch (Exception e) { output.AddErrorLine(e.Message + " - " + e.InnerException); } }
public static void CleanObject(KBObject obj, IOutputService output) { int totalvarremoved = 0; KBDoctorOutput.Message("Cleaning object " + obj.Name); if (obj is Transaction) { KBDoctorCore.Sources.API.CleanKBObjectVariables(obj, output); CleanAllRules(obj); CleanAllWebForm(obj); CleanAllWInForm(obj); CleanAllEvents(obj); CleanAllVars(obj); obj.SetPropertyValue(Artech.Genexus.Common.Properties.TRN.MasterPage, WebPanelReference.NoneRef); } if (obj is Procedure) { CleanAllRules(obj); CleanAllProcedurePart(obj); CleanAllConditions(obj); CleanAllVars(obj); } if (obj is WebPanel) { CleanAllRules(obj); CleanAllWebForm(obj); CleanAllEvents(obj); CleanAllConditions(obj); CleanAllVars(obj); } if (obj is WorkPanel) { CleanAllRules(obj); CleanAllWInForm(obj); CleanAllEvents(obj); CleanAllConditions(obj); CleanAllVars(obj); } try { obj.Save(); } catch (Exception e) { KBDoctorOutput.Message("Can't clean " + obj.Name + " Message: " + e.Message + "--" + e.StackTrace); } }
public static void SaveObjectNewParm(IOutputService output, KBObject obj, string oldParm, string newParm) { RulesPart rulPart = obj.Parts.Get <RulesPart>(); string newRules = ""; try { newParm = newParm.Replace(";", " "); newRules = rulPart.Source.Replace(oldParm, newParm); rulPart.Source = newRules; } catch (Exception e) { output.AddLine(e.Message); }; try { obj.Save(); } catch (Exception e) { output.AddLine("Error SAVING " + obj.Name + " New parm rule " + newParm + " " + e.Message); } }
internal static void CleanKBObjectVariables(KBObject kbObj, IOutputService output, ref string recomendations) { try { VariablesPart variablesPart = null; if (!kbObj.IsCurrentVersion || kbObj.Dirty) { kbObj = KBObject.Get(kbObj.Model, kbObj.Key); } List <Variable> list = new List <Variable>(); List <IEnumerable <VariableReference> > list2 = new List <IEnumerable <VariableReference> >(); List <VariableReference> list3 = new List <VariableReference>(); string text = null; foreach (KBObjectPart current in kbObj.Parts) { if (current is VariablesPart) { variablesPart = (VariablesPart)current; } else { if (current is IHasVariableReferences) { list2.Add(((IHasVariableReferences)current).GetReferencedVariables()); } } if (current is LayoutPart && ((LayoutPart)current).Layout != null) { using (IEnumerator <IReportBand> enumerator2 = ((LayoutPart)current).Layout.ReportBands.GetEnumerator()) { while (enumerator2.MoveNext()) { IReportBand current2 = enumerator2.Current; foreach (IReportComponent current3 in current2.Controls) { if (current3 is ReportAttribute) { VariableReference item = new VariableReference(current3.Name); list3.Add(item); } } } continue; } } if (current is WebFormPart && ((WebFormPart)current).Document != null) { text = ((WebFormPart)current).Document.OuterXml; } } if (list3.Count > 0) { list2.Add(list3); } if (variablesPart != null && !variablesPart.GetPropertyValue <bool>("IsDefault")) { foreach (Variable current4 in variablesPart.Variables) { if (!current4.IsAutoDefined && !current4.IsStandard && (Artech.Genexus.Common.Properties.ATT.Dimensions_Enum)Enum.Parse(typeof(Artech.Genexus.Common.Properties.ATT.Dimensions_Enum), current4.GetPropertyValue <string>("AttNumDim")) == Artech.Genexus.Common.Properties.ATT.Dimensions_Enum.Scalar) { bool flag = false; foreach (IEnumerable <VariableReference> current5 in list2) { foreach (VariableReference current6 in current5) { if (current6.Name.Replace("&", "").Equals(current4.Name.Replace("&", ""), StringComparison.InvariantCultureIgnoreCase)) { flag = true; break; } } if (flag) { break; } } if (!flag && (text == null || !text.Contains("\"var:" + current4.Id + "\""))) { list.Add(current4); } } } if (list.Count > 0) { string text2 = ""; foreach (Variable current7 in list) { text2 = text2 + ", " + current7.Name; variablesPart.Remove(current7); } OutputMessages outputMessages = new OutputMessages(); if (kbObj.Validate(outputMessages)) { kbObj.Save(); string recommend = "Object '" + kbObj.Name + "' cleaned successfully. Variables deleted: " + text2.Substring(2); KBDoctorOutput.Message(recommend); recomendations += recommend + "<br>"; } using (IEnumerator <BaseMessage> enumerator8 = outputMessages.GetEnumerator()) { while (enumerator8.MoveNext()) { BaseMessage current8 = enumerator8.Current; if (current8.Level == MessageLevel.Error) { output.AddErrorLine("KBDoctor", current8.Text); } } } } } } catch (Exception ex) { output.AddWarningLine("KBDoctor", "Object '" + kbObj.Name + "' was not cleaned because an error ocurred: " + ex.Message); } }
private static void GenerateKBObjectEdgesTxt(string name, string fileName) { IKBService kbserv = UIServices.KB; KBModel model = kbserv.CurrentModel; Graph g = new Graph(); Module rootModule = kbserv.CurrentModel.GetDesignModel().RootModule; IOutputService output = CommonServices.Output; StringCollection aristas = new StringCollection(); output.AddLine("Generating " + name); Dictionary <string, Tuple <int, string> > dictionary = new Dictionary <string, Tuple <int, string> >(); Dictionary <int, int> initialpartition = new Dictionary <int, int>(); // Dictionary<string, Tuple<int,string>> dictionary = new Dictionary<string, Tuple<int,string>>(); Dictionary <string, int> NameToId = new Dictionary <string, int>(); Dictionary <string, string> NameToModule = new Dictionary <string, string>(); Dictionary <int, string> IdToName = new Dictionary <int, string>(); Dictionary <int, string> IdToModule = new Dictionary <int, string>(); Dictionary <int, EntityKey> IdToKey = new Dictionary <int, EntityKey>(); int objId = 0; foreach (KBObject obj in model.Objects.GetAll()) { if (Functions.hasModule(obj) || (obj is Module)) { string objName = NombreNodo(obj); string modulename = ModulesHelper.ObjectModuleName(obj); try { objId += 1; NameToId.Add(objName, objId); NameToModule.Add(objName, modulename); IdToName.Add(objId, objName); IdToModule.Add(objId, modulename); IdToKey.Add(objId, obj.Key); } catch (Exception e) {// output.AddWarningLine("Can't add : " + objName + " Exception: " + e.Message + " " + e.InnerException); }; } } foreach (KBObject obj in model.Objects.GetAll()) { string objName = ""; if (Functions.hasModule(obj) || (obj is Module)) //((Functions.isRunable(obj) && ObjectsHelper.isGenerated(obj)) || (obj is Table)) { /* * objName = NombreNodo(obj); * string modulename = ModulesHelper.ObjectModuleName(obj); * * try * { * objId += 1; * NameToId.Add(objName, objId); * NameToModule.Add(objName, modulename); * IdToName.Add(objId, objName); * IdToModule.Add(objId, modulename); * IdToKey.Add(objId, obj.Key); * } * catch (Exception e) { //output.AddWarningLine("Can't add : " + objName); * }; */ //Tomo las referencias que no sean tablas. foreach (EntityReference r in obj.GetReferencesTo()) { KBObject objRef = KBObject.Get(obj.Model, r.From); if ((objRef != null) && (Functions.isRunable(objRef)) || (objRef is Table)) { string objRefName = NombreNodo(objRef); if (objName != objRefName) { int weight = ReferenceWeight(objRef, obj); String edge = objRefName + " " + objName; if (!aristas.Contains(edge)) { aristas.Add(edge); GraboArista(g, NameToId, objRefName, objName, weight); } } } } } } ; foreach (int node in g.Nodes) { string moduleName = IdToModule[node]; int moduleId = NameToId[moduleName]; initialpartition.Add(node, moduleId); } output.AddLine("Before automatic modularization. TurboMQ = " + TurboMQ(g, initialpartition).ToString()); //Empiezo modularizacion Stopwatch stopwatch = new Stopwatch(); // stopwatch.Restart(); Dictionary <int, int> partition = Community.BestPartition(g); output.AddLine("BestPartition: " + stopwatch.Elapsed); var communities = new Dictionary <int, List <int> >(); foreach (var kvp in partition) { List <int> nodeset; if (!communities.TryGetValue(kvp.Value, out nodeset)) { nodeset = communities[kvp.Value] = new List <int>(); } nodeset.Add(kvp.Key); // output.AddLine(kvp.Key.ToString() +" "+kvp.Value); } output.AddLine(communities.Count + " modules found"); Dictionary <string, int> modu = new Dictionary <string, int>(); int counter = 0; foreach (var kvp in communities) { output.AddLine(String.Format("module {0}: {1} objects", counter, kvp.Value.Count)); foreach (var objid in kvp.Value) { var objname = IdToName[objid]; int cantidad = 0; // output.AddLine("Module :" + counter.ToString() + " " + objname); string pareja = IdToModule[objid] + " " + counter.ToString(); if (modu.ContainsKey(pareja)) { modu[pareja] = modu[pareja] + 1; } else { modu.Add(pareja, 1); } } var sortedDict = from entry in modu orderby entry.Value descending select entry; //Cantidad de modulo nuevo y modulo viejo. foreach (KeyValuePair <string, int> entry in sortedDict) { // output.AddLine(entry.Key + " " + entry.Value.ToString()); Module m = new Module(model); m.Name = entry.Key.Replace(" ", "_") + string.Format("_{0:yyyy_MM_dd_hh_mm_ss}", DateTime.Now); output.AddLine(m.Name); m.Module = kbserv.CurrentModel.GetDesignModel().RootModule; m.Save(); foreach (var objid in kvp.Value) { KBObject objToChange = KBObject.Get(model, IdToKey[objid]); if (objToChange != null) { if (objToChange is Table) { try { KBObject trnBest = GenexusBLServices.Tables.GetBestAssociatedTransaction(model, objToChange.Key); trnBest.Module = m; trnBest.Save(); } catch (Exception e) { output.AddErrorLine(objToChange.Name + e.Message); } } else { try { objToChange.Module = m; objToChange.Save(); } catch (Exception e) { output.AddErrorLine(objToChange.Name + e.Message); } } } } break; } counter++; modu.Clear(); } }