public override void Generate(KBObject baseObject, PatternInstance instance)
        {
            if (baseObject is Transaction)
            {

                //modMain.SetGXPath(Artech.Common.Helpers.IO.PathHelper.StartupPath);

                pinstance = instance;
                Transaction transaction = (Transaction)baseObject;
                HPatternInstance wwInstance = new HPatternInstance(transaction.Model);

                settings = wwInstance.Settings;

                //Dictionary<string, object> propertiesg = new Dictionary<string, object>();
                //propertiesg[Properties.HTMLATT.ReadOnly] = true;
                //settings.Grid.Rules

                //Dictionary<string, object> propertiesg = new Dictionary<string, object>();
                //propertiesg[Properties.HTMLSFL.Rules] = Properties.HTMLSFL.Rules_Values.Rows;

                //System.Text.Encoding.w
                // string template = System.Text.Encoding.Default.GetString(file.BlobPart.Data);

                // testes
                /*
                KBModel model = Artech.Architecture.UI.Framework.Services.UIServices.KB.CurrentModel;
                foreach (WikiFileKBObject file in WikiFileKBObject.GetAll(model)) {
                    System.Windows.Forms.MessageBox.Show("File: " + file.Name);
                    byte[] b = file.BlobPart.Data;
                    string saida = System.Text.StringBuilder .GetString(b);
                    System.Text.StringBuilder sb = System.Text.StringBuilder();

                }
                */

                //Antlr.StringTemplate.FileSystemTemplateLoader st = new Antlr.StringTemplate.FileSystemTemplateLoader("");

                Generate(transaction, wwInstance);
                wwInstance.SaveTo(instance);
            }
            else if (baseObject is WebPanel)
            {
                HPatternInstance wwInstance = new HPatternInstance(instance);
                if (wwInstance.WebPanelRoot == null)
                {
                    wwInstance.WebPanelRoot = new WebPanelRootElement();
                }
                wwInstance.SaveTo(instance);
            } else {
                throw new PatternException(Messages.ParentMustBeTransaction);
            }
        }
Example #2
0
        public override void UpdateParentObject(KBObject parent, PatternInstance instance)
        {
            base.UpdateParentObject(parent, instance);
            if (!GXVersion.IsGenexusServer)
            {
                Debug.Assert(parent != null && (parent is Transaction || parent is WebPanel));

                if (parent is Transaction)
                {
                    Transaction transaction = (Transaction)parent;
                    HPatternTransactionUpdater.Clear(instance, transaction);
                }
            }
        }
Example #3
0
        public static string ExtractRuleParm(KBObject obj)
        {
            RulesPart rulesPart = obj.Parts.Get <RulesPart>();
            string    aux       = "";

            if (rulesPart != null)
            {
                Regex  myReg    = new Regex("//.*", RegexOptions.None);
                Regex  paramReg = new Regex(@"parm\(.*\)", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
                string reglas   = rulesPart.Source;
                reglas = myReg.Replace(reglas, "");
                Match match = paramReg.Match(reglas);
                if (match != null)
                {
                    aux = match.ToString();
                }
                else
                {
                    aux = "";
                }
            }
            return(aux);
        }
Example #4
0
        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) { KBDoctorOutput.Message(e.Message); };


            try
            {
                obj.Save();
            }
            catch (Exception e)
            {
                KBDoctorOutput.Message("Error SAVING " + obj.Name + " New parm rule " + newParm + " " + e.Message);
            }
        }
Example #5
0
        private static KBObjectCollection ObjectsReferencesFromOutside(KBObject obj)
        {
            KBObjectCollection objCol = new KBObjectCollection();

            string mdlName = ObjectModuleName(obj);

            foreach (EntityReference refer in obj.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(obj.Model, refer.From);
                if (objRef != null && Functions.isRunable(objRef))
                {
                    string mdlNameRef = ObjectModuleName(objRef);
                    if (mdlNameRef != mdlName)
                    {
                        if (obj is Table)
                        {
                            objCol.Add(obj);
                        }
                    }
                }
            }
            return(objCol);
        }
Example #6
0
        /// <summary>
        /// Cambia los objetos que tienen source o eventos.
        /// </summary>
        /// <param name="obj">Objeto a cambiar</param>
        /// <param name="txtfind">texto a buscar</param>
        /// <param name="txtreplace">texto a remplazar</param>
        public static bool ReplaceEvents(KBObject obj, string txtfind, string txtreplace)
        {
            bool cambio = false;

            if ((obj is Transaction) || (obj is WebPanel) || (obj is WorkPanel))
            {
                EventsPart evPart = obj.Parts.Get <EventsPart>();
                if (evPart != null)
                {
                    string evsource = evPart.Source;

                    string source2 = Regex.Replace(evsource, txtfind, txtreplace, RegexOptions.IgnoreCase);
                    source2 = source2.Replace(txtfind.ToLower(), txtreplace);
                    source2 = source2.Replace(txtfind.ToUpper(), txtreplace);
                    if (evsource != source2)
                    {
                        evPart.Source = source2;
                        cambio        = true;
                    }
                }
            }
            return(cambio);
        }
Example #7
0
        public static IEnumerable <KBObject> GetGXLObjects(KBModel model, string gxlFileName)
        {
            GxlDocumentHelper gxlDocumentHelper = new GxlDocumentHelper(gxlFileName);

            foreach (XmlNode current in gxlDocumentHelper.GetObjects())
            {
                KBObject kBObject   = null;
                Guid     objectGuid = gxlDocumentHelper.GetObjectGuid(current);
                Guid     guid;
                string   name;
                if (objectGuid != Guid.Empty)
                {
                    kBObject = model.Objects.Get(objectGuid);
                }
                else if (gxlDocumentHelper.GetObjectTypeName(current, out guid, out name))
                {
                    if (guid != Guid.Empty)
                    {
                        QualifiedName qname = new QualifiedName(guid, name);
                        model.Objects.Get(guid, qname);
                        kBObject = ObjectHelperGet(model, guid, name);
                    }
                    else
                    {
                        kBObject = ObjectHelperGet(model, name);
                    }
                }
                if (kBObject != null)
                {
                    yield return(kBObject);
                }
            }
            IEnumerator <XmlNode> enumerator = null;

            yield break;
            yield break;
        }
Example #8
0
        public static int ReferenceWeight(KBObject obj, KBObject objRef)
        {
            int weight = 2;

            //2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, and 97
            if (objRef is WebPanel)
            {
                weight = 1;
            }

            if ((objRef is Transaction) & (objRef.GetPropertyValue <bool>("idISBUSINESSCOMPONENT")))
            {
                weight = 1;
            }

            if (objRef is Table)
            {
                if (obj is Transaction)
                {
                    Table t = (Table)objRef;
                    foreach (Transaction trn in t.AssociatedTransactions)
                    {
                        if (obj == trn)
                        {
                            weight = 89; //Esta tabla es generada por esa transaccion
                        }
                    }
                }
                else
                {
                    weight = 13;
                }
            }


            return(weight);
        }
Example #9
0
        private static void ListStats(KBObject obj, StreamWriter file)
        {
            PrintSectionHeader("QUALITIY INDICATORS", file);

            int sourceLines = ObjectsHelper.CountSourceCodeLines(obj);

            file.WriteLine("LINES of Code :   {0,-10}", sourceLines.ToString());

            float commentPct = ObjectsHelper.SourceCodeCommentPct(obj);

            file.WriteLine("COMMENTS %    :   {0,-10}", commentPct.ToString());

            int maxBlock = ObjectsHelper.MaxBlockOfCode(obj);

            file.WriteLine("MAX BLOCK     :   {0,-10}", maxBlock.ToString());

            int complexityLevel = ObjectsHelper.ComplexityLevel(obj);

            file.WriteLine("COMPLEXITY    :   {0,-10}", complexityLevel.ToString());

            int maxNest = ObjectsHelper.MaxNestLevel(obj);

            file.WriteLine("MAX NEST LEVEL:   {0,-10}", maxNest.ToString());
        }
Example #10
0
        public bool ExecuteRemoveVariables(CommandData data)
        {
            KBObject obj = data.Context as KBObject;

            if (obj == null)
            {
                return(true);
            }

            foreach (KBObjectPart p in obj.Parts)
            {
                if (p is VariablesPart)
                {
                    VariablesPart vars = p as VariablesPart;
                    foreach (var variable in vars.Variables.Where(v => !v.IsStandard))
                    {
                        CommonServices.Output.AddLine(string.Format("var {0} will be deleted", variable.Name));
                    }
                    break;
                }
            }

            return(true);
        }
Example #11
0
        private static List <string> MostReferencedInFolder(Table tbl)
        {
            IOutputService output = CommonServices.Output;
            List <string>  list   = new List <string>();

            foreach (EntityReference refe in tbl.GetReferencesTo())
            {
                KBObject objRef = KBObject.Get(tbl.Model, refe.From);
                if (objRef != null)
                {
                    bool read, insert, update, delete, isBase;

                    ReferenceTypeInfo.ReadTableInfo(refe.LinkTypeInfo, out read, out insert, out update, out delete, out isBase);

                    string updated = (update || delete || insert) ? "UPDATED" : "";

                    if (objRef.Parent is Folder)
                    {
                        list.Add("FOLDER:" + objRef.Parent.Name + " |  " + updated);
                    }
                    if (objRef.Parent is Module)
                    {
                        list.Add("MODULE:" + objRef.Parent.Name + " |  " + updated);
                    }
                }
            }
            output.AddLine(" ");
            output.AddLine("============> " + tbl.Name);

            list.Sort();
            foreach (string s in list)
            {
                output.AddLine(s);
            }
            return(list);
        }
Example #12
0
        public bool ExecuteRebuildAndRun(CommandData data)
        {
            KBObject obj = data.Context as KBObject;

            if (obj == null)
            {
                return(true);
            }

            List <EntityKey> keys = new List <EntityKey>();

            keys.Add(obj.Key);

            GenexusUIServices.Build.Rebuild(obj.Key);

            BackgroundWorker worker = new BackgroundWorker();

            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.DoWork             += new DoWorkEventHandler(worker_DoWork);

            worker.RunWorkerAsync(obj);

            return(true);
        }
Example #13
0
        public static string MainsOf(KBObject obj, KBObjectCollection objColl, string callTree)
        {
            string mains = "";

            if (!objColl.Contains(obj))
            {
                objColl.Add(obj);

                if (obj.GetPropertyValue <bool>("IsMain"))
                {
                    string objAppGenerator = obj.GetPropertyValueString("AppGenerator");
                    if (objAppGenerator.Contains("Java Win") && callTree.Contains("HMaster"))
                    {
                        mains = "";
                    }
                    else
                    {
                        mains = callTree + "/" + Functions.linkObject(obj) + "(" + objAppGenerator + ")<BR> ";
                    }
                }
                else
                {
                    callTree += obj.Name + "/";
                    foreach (EntityReference reference in obj.GetReferencesTo())
                    {
                        KBObject objRef = KBObject.Get(obj.Model, reference.From);

                        if ((objRef != null) && (obj.Name != objRef.Name) && (reference.ReferenceType == ReferenceType.Hard) && reference.LinkType == LinkType.UsedObject /*&& (obj.TypeDescriptor.Name != "MasterPage")*/ && !objColl.Contains(objRef))
                        {
                            mains += MainsOf(objRef, objColl, callTree);
                        }
                    }
                }
            }
            return(mains);
        }
Example #14
0
 private void DeleteObjectAndReferences(KBModel model, List <KBObject> parents)
 {
     parents.ForEach(p => parents.AddRange(model.Objects.GetAllChildren(p)));
     KBObject.Delete(parents);
 }
Example #15
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);
        }
        bool IsObjectSelected(CommandData data, bool mustBeMain, out KBObject obj)
        {
            obj = null;
            if (data.Context == null)
                return false;

            obj = KBObjectSelectionHelper.TryGetOnlyOneKBObjectFrom(data.Context);
            if (obj != null && mustBeMain)
                return obj.GetPropertyValue<bool>("IsMain");

            return true;
        }
Example #17
0
 private void ChangeDocumentation(DocumentationPart docp, KBObject obj, HPatternInstance wwInstance, HPatternSettings settings)
 {
     TemplateInternal.DocumentationSave(docp, obj, wwInstance, settings);
 }
Example #18
0
        private static void CleanAllRules(KBObject obj)
        {
            RulesPart rulesPart = obj.Parts.Get <RulesPart>();

            rulesPart.Source = "";
        }
Example #19
0
 internal XmlDocument AppendTemplateOutputInner(KBObject obj, KBObjectPart part, PatternInstanceElement element, String template)
 {
     Generator.GeneratorParameters parms = new Generator.GeneratorParameters();
     DefaultProvider.PrepareTemplateParameters(parms);
     parms.Properties["Object"] = obj;
     parms.Properties["Part"] = part;
     parms.Properties["Instance"] = Instance;
     parms.Properties["Element"] = element;
     StringBuilder sb = new StringBuilder();
     Heurys.Patterns.HPattern.HPatternTransactionUpdater.AppendTemplateOutput(sb, template, parms);
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.LoadXml(sb.ToString());
     return xmlDocument;
 }
Example #20
0
 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);
     }
 }
Example #21
0
        private static void ApplyRow(StringBuilder atts, RowElement row, KBObject objeto, Boolean geraBC, String sigla, HPatternSettings settings, bool overwrite)
        {
            atts.AppendLine("<tr>");

            Transaction transaction = null;
            if (objeto is Transaction) transaction = (Transaction)objeto;

            foreach (ColumnElement col in row.Columns)
            {
                atts.AppendLine("<td align=\"" + col.GetAlign() + "\" colspan='" + col.ColSpan.ToString() + "' rowspan='" + col.RowSpan.ToString() + "'>");

                foreach (Object obj in col.Items)
                {
                    if (obj is AttributeElement)
                    {
                        AttributeElement att = (AttributeElement)obj;
                        if (geraBC)
                        {
                            Dictionary<string, object> properties = new Dictionary<string, object>();
                            properties[Properties.HTMLATT.FieldSpecifier] = att.AttributeName;
                            bool vreadonly = false;
                            TransactionAttribute ta = null;
                            if (transaction != null)
                            {
                                ta = transaction.Structure.Root.GetAttribute(att.AttributeName);
                                if (ta == null)
                                {
                                    vreadonly = true;
                                }
                                else
                                {
                                    if (ta.IsInferred)
                                    {
                                        vreadonly = true;
                                    }
                                }
                            }

                            if (att.Readonly)
                            {
                                vreadonly = true;
                            }

                            if (vreadonly)
                            {
                                properties[Properties.HTMLATT.ReadOnly] = true;
                            }

                            string themeClass = "Attribute";
                            if (transaction != null && ta != null)
                            {
                                if (ta.IsKey && !String.IsNullOrEmpty(settings.Theme.AttributeKey))
                                    themeClass = settings.Theme.AttributeKey;
                            }
                            if (att.ThemeClass != String.Empty)
                                themeClass = att.ThemeClass;

                            if (vreadonly)
                            {
                                if (att.Format.ToLower() == "text")
                                    properties[Properties.HTMLATT.Format] = Properties.HTMLATT.Format_Values.Text;

                                if (att.Format.ToLower() == "html")
                                    properties[Properties.HTMLATT.Format] = Properties.HTMLATT.Format_Values.Html;

                                if (att.Format.ToLower() == "raw html")
                                    properties[Properties.HTMLATT.Format] = Properties.HTMLATT.Format_Values.RawHtml;

                                if (att.Format.ToLower() == "text with meaningful spaces")
                                    properties[Properties.HTMLATT.Format] = Properties.HTMLATT.Format_Values.TextWithMeaningfulSpaces;

                            }

                            GetControlInfo(att, properties);

                            atts.AppendLine(WebForm.Variable((transaction != null ? transaction.Name : "") + sigla, themeClass, null, properties));
                        }
                        else
                        {
                            string themeClass = null;
                            if (transaction != null)
                            {
                                TransactionAttribute ta = transaction.Structure.Root.GetAttribute(att.AttributeName);
                                if (ta.IsKey && !String.IsNullOrEmpty(settings.Theme.AttributeKey))
                                    themeClass = settings.Theme.AttributeKey;
                            }
                            if (att.ThemeClass != String.Empty)
                                themeClass = att.ThemeClass;
                            Dictionary<string, object> properties = new Dictionary<string, object>();
                            if (att.Readonly)
                            {
                                properties[Properties.HTMLATT.ReadOnly] = true;
                            }

                            GetControlSize(att, properties);

                            atts.AppendLine(WebForm.Attribute(att.AttributeName, themeClass, null, properties));
                        }
                        LinkBuild(atts, att, settings);
                        if (!String.IsNullOrEmpty(att.MaskPicture))
                        {
                            Dictionary<string, object> props = new Dictionary<string, object>();
                            props.Add("Picture", att.MaskPicture);
                            props.Add("Reverse", att.Reverse);
                            props.Add("Signed", att.Signed);
                            props.Add("UnmaskedChars", att.UnmaskedChars);
                            props.Add("UnmaskedValue",att.UnmaskedValue);
                            atts.AppendLine(WebFormHelper.BeginControl("HMask2", att.AttributeName + "HMask", props));
                            atts.AppendLine(WebFormHelper.EndControl("HMask2"));
                        }
                    }
                    if (obj is VariableElement)
                    {
                        VariableElement var = (VariableElement)obj;

                        string themeClass = "Attribute";
                        if (var.ThemeClass != String.Empty)
                            themeClass = var.ThemeClass;

                        Dictionary<string, object> properties = new Dictionary<string, object>();
                        GetControlSize(var, properties);

                        atts.AppendLine(WebForm.Variable(var.Name, themeClass, null, properties));
                        LinkBuild(atts, var, settings);
                        if (!String.IsNullOrEmpty(var.MaskPicture))
                        {
                            Dictionary<string, object> props = new Dictionary<string, object>();
                            props.Add("Picture", var.MaskPicture);
                            props.Add("Reverse", var.Reverse);
                            props.Add("Signed", var.Signed);
                            props.Add("UnmaskedChars", var.UnmaskedChars);
                            props.Add("UnmaskedValue", var.UnmaskedValue);
                            atts.AppendLine(WebFormHelper.BeginControl("HMask2", var.Name + "HMask", props));
                            atts.AppendLine(WebFormHelper.EndControl("HMask2"));
                        }
                    }
                    if (obj is TextElement)
                    {
                        TextElement text = (TextElement)obj;
                        TemplateInternal.RenderText(text, row,atts,transaction);
                    }
                    if (obj is GroupElement)
                    {
                        GroupElement gobj = (GroupElement)obj;

                        contaGroup++;
                        string name = "Group"+contaGroup.ToString().Trim();

                        string tema = settings.Theme.Group;
                        if (String.IsNullOrEmpty(tema)) tema = "Group";
                        if (!String.IsNullOrEmpty(gobj.Class)) tema = gobj.Class;

                        atts.AppendLine(WebForm.BeginGroup(name, tema, gobj.Caption));
                        atts.AppendLine(WebForm.BeginTable("Table"+name,null));
                        foreach (RowElement row2 in gobj.Rows) {
                            ApplyRow(atts, row2, objeto, geraBC, sigla, settings, overwrite);
                        }
                        atts.AppendLine(WebForm.EndTable());
                        atts.AppendLine(WebForm.EndGroup());
                    }
                    if (obj is UserTableElement)
                    {
                        WebFormPart wform = null;
                        if (transaction != null)
                        {
                            wform = transaction.WebForm;
                        }
                        else if (objeto is WebPanel)
                        {
                            wform = ((WebPanel)objeto).WebForm;
                        }
                        AddUserTable((UserTableElement)obj, atts, wform, overwrite);
                    }
                    if (!geraBC)
                    {
                        if (obj is GridFreeStyleElement)
                        {
                            GridFreeStyleElement grid = obj as GridFreeStyleElement;
                            AddGridFreeStyle(atts, grid, settings);
                        }
                        if (obj is GridStandardElement)
                        {
                            GridStandardElement grid = obj as GridStandardElement;
                            AddGridStandard(atts, grid, settings);
                        }
                    }
                }

                atts.AppendLine("</td>");
            }

            atts.AppendLine("</tr>");
        }
 string GetObjectPath(KBObject obj, string platform)
 {
     return Path.Combine(Path.Combine(Path.Combine(Path.Combine(UIServices.KB.CurrentKB.Location, UIServices.KB.CurrentModel.Environment.TargetModel.TargetPath), "mobile"), platform), obj.QualifiedName.ToString().Replace(".","_"));
 }
Example #23
0
 internal int DeleteVariables(PatternInstanceElement element, KBObject obj, bool overwrite)
 {
     if (mDelVar != null) {
         return mDelVar.DeleteVariables(element, obj, overwrite);
     }
     return 0;
 }
Example #24
0
            public int DeleteVariables(PatternInstanceElement element, KBObject obj, bool overwrite)
            {
                int ret = 0;
                if (obj is WebPanel
                    && (element.Type == InstanceElements.Selection || element.Type == InstanceElements.Tab)
                    && element.SelectElements("actions/action[@multiRowSelection=\"True\"]").Count == 0)
                {
                    bool canDelete = true;
                    WebPanel webp = (WebPanel)obj;

                    if (overwrite == false)
                    {
                        if (webp.Events.Source.IndexOf("&SelectedRows.") >= 0)
                        {
                            canDelete = false;
                        }
                        else if (webp.Events.Source.IndexOf("&SelectedRow.") >= 0)
                        {
                            canDelete = false;
                        }
                    }
                    if (canDelete)
                    {
                        Variable var = webp.Variables.GetVariable("SelectedRows");
                        if (var != null)
                        {
                            ret = 1;
                            webp.Variables.Remove(var);
                        }
                        var = null;
                        var = webp.Variables.GetVariable("SelectedRow");
                        if (var != null)
                        {
                            ret = 1;
                            webp.Variables.Remove(var);
                        }
                    }
                }

                return ret;
            }
Example #25
0
 internal String AppendTemplateOutputXml(KBObject obj, KBObjectPart part, PatternInstanceElement element, String template)
 {
     return AppendTemplateOutputInner(obj, part, element, template).InnerXml;
 }
Example #26
0
 string GetObjectPath(KBObject obj, string platform)
 {
     return(Path.Combine(Path.Combine(Path.Combine(Path.Combine(UIServices.KB.CurrentKB.Location, UIServices.KB.CurrentModel.Environment.TargetModel.TargetPath), "mobile"), platform), obj.QualifiedName.ToString().Replace(".", "_")));
 }
Example #27
0
        private static void CleanAllProcedurePart(KBObject obj)
        {
            ProcedurePart procPart = obj.Parts.Get <ProcedurePart>();

            procPart.Source = "";
        }
Example #28
0
        private static void CleanVariablesBasedInAttribute(Artech.Genexus.Common.Objects.Attribute a, IOutputService output, KBObject objRef)
        {
            output.AddLine("Cleaning variables references to " + a.Name + " in " + objRef.Name);

            VariablesPart vp = objRef.Parts.Get <VariablesPart>();

            if (vp != null)
            {
                foreach (Variable v in vp.Variables)
                {
                    if (!v.IsStandard)
                    {
                        if ((v.AttributeBasedOn != null) && (a.Name == v.AttributeBasedOn.Name))
                        {
                            output.AddLine("&" + v.Name + " based on  " + a.Name);
                            eDBType type   = v.Type;
                            int     length = v.Length;
                            bool    signed = v.Signed;
                            string  desc   = v.Description;
                            int     dec    = v.Decimals;

                            //Modifico la variable, para que no se base en el atributo.
                            v.AttributeBasedOn = null;
                            v.Type             = type;
                            v.Decimals         = dec;
                            v.Description      = desc;
                            v.Length           = length;
                            v.Signed           = signed;
                        }
                    }
                }
            }
        }
Example #29
0
        public override void UpdateParentObject(KBObject parent, PatternInstance instance)
        {
            if (Messages.Debug())
            {
                CommonServices.Output.AddLine(String.Format(">>> UpdateParentObject Begin {0}", DateTime.Now.ToString()));
            }
            base.UpdateParentObject(parent, instance);

            if (!GXVersion.IsGenexusServer)
            {
                Debug.Assert(parent != null && (parent is Transaction || parent is WebPanel));

                if (parent is Transaction)
                {

                    Transaction transaction = (Transaction)parent;
                    HPatternTransactionUpdater.Apply(instance, transaction);

                    HPatternSettings settings = HPatternSettings.Get(instance.Model);
                    HPatternInstance wwInstance = HPatternInstance.Load(instance);

                    bool gera = wwInstance.Transaction.WebBC;
                    /*
                    bool gera = settings.Template.DataEntryWebPanelBC;
                    if (wwInstance.Transaction.DataEntryWebPanelBC.ToLower() == "true")
                        gera = true;
                    if (wwInstance.Transaction.DataEntryWebPanelBC.ToLower() == "false")
                        gera = false;
                    */

                    if (gera)
                    {
                        if (wwInstance.Levels[0] != null)
                        {
                            if (wwInstance.Levels[0].View != null)
                            {
                                foreach (TabElement tabe in wwInstance.Levels[0].View.Tabs)
                                {
                                    if (tabe.Type == TabElement.TypeValue.Grid && tabe.Transaction != null && tabe.Transaction.Transaction != null)
                                    {
                                        Transaction trn = tabe.Transaction.Transaction;
                                        trn.SetPropertyValue(Properties.TRN.BusinessComponent, true);
                                        trn.Save();
                                    }
                                }
                            }
                        }
                    }

                }
                else if (parent is WebPanel)
                {
                    //CommonServices.Output.AddLine(">>> WebPanel não implementado!");
                    new WebPanelUpdater((WebPanel)parent, instance);
                }
            }

            if (Messages.Debug())
            {
                CommonServices.Output.AddLine(String.Format(">>> UpdateParentObject End {0}", DateTime.Now.ToString()));
            }
        }
Example #30
0
        private static void CleanAllEvents(KBObject obj)
        {
            EventsPart evPart = obj.Parts.Get <EventsPart>();

            evPart.Source = "";
        }
Example #31
0
 //
 public static void CleanKBObjectVariables(KBObject obj, IOutputService output)
 {
     CleanKB.CleanKBObjectVariables(obj, output);
 }
Example #32
0
        private static void CleanAllConditions(KBObject obj)
        {
            ConditionsPart cndPart = obj.Parts.Get <ConditionsPart>();

            cndPart.Source = "";
        }
Example #33
0
        private static void ProcesoNavigation(string xmlstring, IOutputService output, TextWriter writer2, KBObject obj)
        {
            //Create the XmlDocument.
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlstring);

            string ObjName    = "";
            string EventName  = "";
            string LevelType  = "";
            string LevelRow   = "";
            string TableNames = "";
            string AttNames   = "";

            using (XmlReader reader = new XmlTextReader(new System.IO.StringReader(xmlstring)))
            {
                while (reader.Read())
                {
                    //  string inner = reader.ReadInnerXml();

                    switch (reader.Name)
                    {
                    case "ObjName":
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            reader.Read();
                            if (ObjName == "")
                            {
                                ObjName = reader.Value;
                            }
                        }
                        break;

                    case "EventName":      //<EventName>Sbfhoras.Load</EventName>
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            reader.Read();
                            EventName = reader.Value;
                        }
                        //reader.Read();
                        //EventName = reader.Value;
                        break;

                    case "LevelType":      //<LevelType>For First</LevelType>
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            //IMPRIMO EL LEVEL ANTERIOR
                            //      if (LevelType!="")
                            //             output.AddLine(String.Format("OBJECT= {0} EVENTNAME= {1} ROW= {2} LEVELTYPE= {3} TABLES= {4} ATTRIBUTES= {5} ", ObjName, EventName, LevelRow, LevelType, TableNames, AttNames));
                            reader.Read();
                            LevelType = reader.Value;
                            //VACIO TABLAS Y ATRIBUTOS PUES CAMBIO DE LEVEL
                            TableNames = "";
                            AttNames   = "";
                        }
                        break;

                    case "LevelBeginRow":      //<LevelBeginRow>31</LevelBeginRow>
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            reader.Read();
                            LevelRow = reader.Value;
                        }
                        break;

                    case "NavigationTree":

                        while (reader.Read() && !(reader.Name == "NavigationTree" && reader.NodeType == XmlNodeType.EndElement))
                        {
                            switch (reader.Name)
                            {
                            case "TableName":
                                if (reader.NodeType == XmlNodeType.Element)
                                {
                                    reader.Read();
                                    TableNames += reader.Value + " ";
                                }
                                break;

                            case "AttriName":
                                if (reader.NodeType == XmlNodeType.Element)
                                {
                                    reader.Read();
                                    AttNames += reader.Value + " ";
                                }
                                break;
                            }
                        }
                        if (LevelType != "")
                        {
                            string aux = LevelType + "," + TableNames + " ,  " + AttNames;
                            string hash;
                            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
                            {
                                hash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(aux))
                                                             ).Replace("-", String.Empty);
                            }
                            //Cuento Cantidad de tablas.
                            hash = TableNames.Count(Char.IsWhiteSpace).ToString("D2") + hash;

                            // output.AddLine(String.Format("{0} ,  {1} ,  {2} ,  {3} , {4}, {5}  ", ObjName, EventName, LevelRow, LevelType, TableNames, AttNames));
                            // writer.AddTableData(new string[] { hash, Functions.linkObject(obj), EventName, LevelRow, LevelType, TableNames, AttNames });
                            writer2.WriteLine(LevelType + "," + TableNames + "," + AttNames + "," + Functions.linkObject(obj) + "," + EventName + "," + LevelRow.PadLeft(10, ' '));
                            LevelType  = "";
                            LevelRow   = "";
                            TableNames = "";
                            AttNames   = "";
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Example #34
0
 public static bool isRunable(KBObject obj)
 {
     return(obj is Transaction | obj is WorkPanel | obj is WebPanel
            | obj is DataProvider | obj is DataSelector | obj is Procedure | obj is Menubar);
 }
Example #35
0
 public static void DocumentationSave(DocumentationPart docp, KBObject obj, HPatternInstance wwInstance, HPatternSettings settings)
 {
     bool atualiza = false;
     if (docp.Page == null)
     {
         atualiza = true;
     }
     else
     {
         if (String.IsNullOrEmpty(docp.Page.EditableContent))
         {
             atualiza = true;
         }
     }
     if (atualiza)
     {
         docp.Page = new WikiPage(wwInstance.Model, obj.Name, TemplateInternal.DocumentationFactory(obj.Name, obj.Description, wwInstance, settings));
     }
 }
Example #36
0
        public static void AttUpdated()
        {
            IKBService kbserv = UIServices.KB;

            string title      = "KBDoctor - Where update this attribute? :";
            string outputFile = Functions.CreateOutputFile(kbserv, title);

            IOutputService output = CommonServices.Output;

            output.StartSection(title);


            AskAttributeandTable at = new AskAttributeandTable();
            DialogResult         dr = new DialogResult();

            dr = at.ShowDialog();

            if (dr == DialogResult.OK)
            {
                string tblName = at.tblName;
                string attName = at.attName;

                List <string> Objlist = new List <string>();


                KBDoctorXMLWriter writer = new KBDoctorXMLWriter(outputFile, Encoding.UTF8);
                writer.AddHeader(title + attName + " in table " + tblName);
                writer.AddTableHeader(new string[] { "Object", "Description", "Type", "Navigation File" });

                int IndFiles = 0;

                //   IKBService kbserv = UIServices.KB;
                string   directoryArg     = KBDoctorHelper.SpcDirectory(kbserv);
                string   fileWildcard     = @"*.xml";
                var      searchSubDirsArg = System.IO.SearchOption.AllDirectories;
                string[] xFiles           = System.IO.Directory.GetFiles(directoryArg, fileWildcard, searchSubDirsArg);

                foreach (string x in xFiles)
                {
                    // output.AddLine(x);
                    IndFiles += 1;
                    if (IndFiles % 100 == 0)
                    {
                        output.AddLine(" Procesing " + IndFiles.ToString() + " navigation files.");
                    }

                    string filename = Path.GetFileNameWithoutExtension(x);

                    if (!Objlist.Contains(filename))
                    {
                        Objlist.Add(filename);
                        if (!Path.GetFileNameWithoutExtension(x).StartsWith("Gx0"))
                        {
                            string xmlstring = AddXMLHeader(x);

                            if (ObjectUpdateTable(xmlstring, tblName, attName))
                            {
                                KBObject obj = ExtractObject(xmlstring);
                                if (obj == null)
                                {
                                    writer.AddTableData(new string[] { "Can't find object", "", "", x });
                                }
                                else
                                if (KBDoctorCore.Sources.Utility.isGenerated(obj) || obj.GetPropertyValue <bool>("idISBUSINESSCOMPONENT"))
                                {
                                    writer.AddTableData(new string[] { Functions.linkObject(obj), obj.Description, obj.TypeDescriptor.Name, x });
                                }
                            }
                        }
                    }
                }

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

                KBDoctorHelper.ShowKBDoctorResults(outputFile);
                bool success = true;
                output.EndSection(title, success);
            }
        }
Example #37
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);
        }
Example #38
0
 public static string linkObject(KBObject obj)
 {
     return("<a href=\"gx://?Command=fa2c542d-cd46-4df2-9317-bd5899a536eb;OpenObject&name=" + obj.Guid.ToString() + "\">" + obj.Name + "</a>");
 }
        bool IsOkToShow(KBObject obj, string generator)
        {
            if (obj == null)
                return false;

            if (obj.Type != ObjClass.SDPanel && obj.Type != ObjClass.Dashboard)
                return false;

            GxEnvironment environment = UIServices.KB.WorkingEnvironment.TargetModel.GetAs<GxModel>().Environments.FirstOrDefault(env => env.Generator == (int)GeneratorType.SmartDevices);

            return environment != null && environment.Properties.GetPropertyValue<bool>(generator);
        }
Example #40
0
        private static void CleanSDT(Artech.Genexus.Common.Objects.Attribute a, IOutputService output, KBObject objRef)
        {
            if (objRef is SDT)
            {
                output.AddLine("Cleaning SDT references to " + a.Name + " in " + objRef.Name);
                SDTStructurePart sdtstruct = objRef.Parts.Get <SDTStructurePart>();

                foreach (IStructureItem structItem in sdtstruct.Root.Items)
                {
                    SDTItem sdtItem = (SDTItem)structItem;
                    if (sdtItem.BasedOn.Key == a.Key)
                    {
                        output.AddLine("..." + sdtItem.Name + " based on  " + a.Name);
                        eDBType type   = sdtItem.Type;
                        int     length = sdtItem.Length;
                        bool    signed = sdtItem.Signed;
                        string  desc   = sdtItem.Description;
                        int     dec    = sdtItem.Decimals;

                        //Modifico la variable, para que no se base en el atributo.
                        sdtItem.AttributeBasedOn = null;
                        sdtItem.Type             = type;
                        sdtItem.Decimals         = dec;
                        sdtItem.Description      = desc;
                        sdtItem.Length           = length;
                        sdtItem.Signed           = signed;
                    }
                }
            }
        }
Example #41
0
        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();
            }
        }
Example #42
0
 //
 public static void CleanKBObject(KBObject obj, IOutputService output)
 {
     CleanKB.CleanObject(obj, output);
 }
Example #43
0
        private static void GenerateKBModuleGraph(string name, string fileName)
        {
            IKBService       kbserv     = UIServices.KB;
            KBModel          model      = kbserv.CurrentModel;
            StreamWriter     scriptFile = new StreamWriter(fileName);
            IOutputService   output     = CommonServices.Output;
            StringCollection aristas    = new StringCollection();

            output.AddLine("Generating " + name);

            scriptFile.WriteLine("<?xml version = '1.0' encoding = 'UTF-8'?>");

            scriptFile.WriteLine("<gexf xmlns='http://www.gexf.net/1.2draft'  xmlns:viz='http://www.gexf.net/1.2draft/viz' ");
            scriptFile.WriteLine("     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd' version = '1.2' > ");

            scriptFile.WriteLine("  <graph mode = 'static' defaultedgetype = 'directed' > ");
            scriptFile.WriteLine("<attributes class='node'> <attribute id='0' title = 'module' type = 'string' />  </attributes >");

            scriptFile.WriteLine("      <nodes>");

            foreach (Module mdl in Module.GetAll(model))

            {
                string modulename = mdl.Name;

                scriptFile.WriteLine("          <node id='" + mdl.Name + "' label='" + mdl.Description + "' >");
                scriptFile.WriteLine("              <attvalues>  <attvalue for='0' value = '" + mdl.Name + "' /> </attvalues>");
                scriptFile.WriteLine("          </node>");

                foreach (KBObject obj in mdl.GetAllMembers())
                {
                    if (obj is Procedure || obj is Table)
                    {
                        foreach (EntityReference r in obj.GetReferences())
                        {
                            KBObject objRef = KBObject.Get(obj.Model, r.To);
                            if ((objRef != null) && (Functions.isRunable(objRef) || objRef is Table) && modulename != ModulesHelper.ObjectModuleName(objRef))

                            {
                                String edge = "          <edge id='XXXX' source='" + modulename + "' target='" + ModulesHelper.ObjectModuleName(objRef) + "' />  ";
                                if (!aristas.Contains(edge))
                                {
                                    aristas.Add(edge);
                                }
                            }
                        }
                    }
                }
            }
            scriptFile.WriteLine("      </nodes>");

            //Grabo las aristas
            scriptFile.WriteLine("      <edges>");

            int i = 0;

            foreach (String s in aristas)
            {
                string s2 = s.Replace("XXXX", i.ToString());
                scriptFile.WriteLine("          " + s2);
                i += 1;
            }
            ;
            scriptFile.WriteLine("      </edges>");
            scriptFile.WriteLine("  </graph>");
            scriptFile.WriteLine("</gexf>");
            scriptFile.Close();
        }