Beispiel #1
0
        private static void ListVariables(KBObject obj, StreamWriter file)
        {
            VariablesPart vp = obj.Parts.Get <VariablesPart>();

            if (vp != null)
            {
                file.WriteLine(Environment.NewLine + "=== VARIABLES ===");
                file.WriteLine(String.Format("{0,2} {1,-30} {2,-30} {3,-30}", "Ch", "Name", "Type", "Based on "));


                foreach (Variable v in vp.Variables)
                {
                    if (!v.IsStandard)
                    {
                        string CheckVar = " ";
                        string DataType = v.GetPropertyValue <string>(Properties.ATT.DataTypeString);

                        if (v.AttributeBasedOn == null && v.DomainBasedOn == null)
                        {
                            CheckVar = "*";
                        }

                        if (v.IsAutoDefined)
                        {
                            CheckVar = "*";
                        }

                        file.WriteLine(String.Format("{0,2} {1,-30} {2,-30} {3,-30}", CheckVar, v.Name, Functions.ReturnPictureVariable(v), DataType));
                    }
                }
            }
        }
Beispiel #2
0
        public static void ObjectsVariablesExternal(KBObject obj, KBDoctorXMLWriter writer, string mainss)
        {
            IKBService kbserv = UIServices.KB;

            string type      = "";
            string name      = "";
            string variables = "";


            if (KBDoctorCore.Sources.Utility.isGenerated(obj))
            {
                VariablesPart vp = obj.Parts.Get <VariablesPart>();
                if (vp != null)
                {
                    foreach (Variable v in vp.Variables)
                    {
                        type = v.Type.ToString();
                        name = v.Name;

                        if ((!v.IsStandard) && (v.AttributeBasedOn == null) && (type == "GX_USRDEFTYP")) //|| (type==) || (type == "GX_BUSCOMP_LEVEL") )
                        {
                            variables += name + " " + type + " ";
                            string txtDimensions = v.GetPropertyValue <string>(Properties.ATT.DataTypeString);
                            writer.AddTableData(new string[] { Functions.linkObject(obj), name, "Data Type." + txtDimensions, mainss });
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public AssignDomToVar(KBObject obj)
        {
            InitializeComponent();

            objName.Text = obj.Name + " (" + obj.TypeDescriptor.Name + "): " + obj.Description;
            objSource    = ObjectsHelper.ObjectSource(obj);
            objRules     = obj.Parts.Get <RulesPart>().Source;

            model = obj.Model;


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

            if (vp != null)
            {
                foreach (Variable v in vp.Variables)
                {
                    if ((!v.IsStandard) && (v.AttributeBasedOn == null) && (v.DomainBasedOn == null) && (v.Type != eDBType.GX_USRDEFTYP) &&
                        (v.Type != eDBType.GX_SDT) && (v.Type != eDBType.GX_EXTERNAL_OBJECT) && (v.Type != eDBType.Boolean) && v.Type != eDBType.GX_BUSCOMP && v.Type != eDBType.GX_BUSCOMP_LEVEL)
                    {
                        comboVar.Items.Add(new Item(v.Name + "  " + Utility.FormattedTypeVariable(v), v));
                    }
                    cantVariables.Text = comboVar.Items.Count.ToString() + " not based variables";
                }
            }
        }
Beispiel #4
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;
                        }
                    }
                }
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        //        private static void ListProperties(KBObject obj, StreamWriter file)
        //        {
        //            PrintSectionHeader("PROPERTIES", file);
        //            //foreach (Property prop in obj.Properties)
        //            //{
        //            //if (!prop.IsDefault)
        //            //{
        //            //    file.WriteLine(prop.Name + " -> " + prop.Value.ToString());
        //            //}
        //            //else
        //            //{
        //            //if ((prop.Name == "CommitOnExit") || (prop.Name == "TRNCMT") || (prop.Name == "GenerateObject"))
        //            //{
        //            //    file.WriteLine(prop.Name + " -> " + prop.Value.ToString());
        //            //}
        //            //}
        //            //}

        //            foreach (Property prop in obj.Properties)
        //            {
        //<<<<<<< HEAD
        //                //EVO3:
        //                //if (!prop.IsDefault)
        //                //{
        //                //    file.WriteLine(prop.Name + " -> " + prop.Value.ToString());
        //                //}
        //                //else
        //                //{
        //                    if ((prop.Name == "CommitOnExit") || (prop.Name == "TRNCMT") || (prop.Name == "GenerateObject"))
        //=======
        //                if (prop.Value != null)
        //                {
        //                    if ((prop.Name == "Name") || (prop.Name == "Description") || (prop.Name == "IsDefault") ||
        //                        (prop.Name == "CommitOnExit") || (prop.Name == "TRNCMT") || (prop.Name == "GenerateObject"))
        //>>>>>>> origin/Navigation
        //                    {

        //                        file.WriteLine(prop.Name + " -> " + prop.Value.ToString());
        //                    }
        //               // }
        //            }


        //        }

        private static void ListVariables(KBObject obj, StreamWriter file)
        {
            bool hasUnusedVars = false;

            PrintSectionHeader("VARIABLE DEFINITION", file);
            file.WriteLine(String.Format("{0,-3} {1,-30} {2,-30} {3,-30} {4,-30}", "", "Name", "Type", "Based on", "Desc"));

            VariablesPart vars       = obj.Parts.Get <VariablesPart>();
            int           alertCount = 0;

            foreach (Variable var in vars.Variables)
            {
                if (!var.IsStandard)
                {
                    string chrAlert = Functions.ReturnVariableDefinitionAlert(var);
                    string dataType = Functions.ReturnPictureVariable(var);
                    string basedOn  = var.AttributeBasedOn == null & var.DomainBasedOn == null ? "" : var.GetPropertyValue <string>(Properties.ATT.DataTypeString);
                    bool   inUse    = Functions.CheckObjUsesVariable(var, obj);

                    if (chrAlert != "")
                    {
                        alertCount += 1;
                    }

                    if (!inUse)
                    {
                        chrAlert     += "@";
                        hasUnusedVars = true;
                    }

                    file.WriteLine(String.Format("{0,-3} {1,-30} {2,-30} {3,-30} {4,-30}",
                                                 chrAlert,
                                                 var.Name,
                                                 dataType,
                                                 basedOn,
                                                 var.Description
                                                 ));
                }
            }

            if (alertCount > 0 || hasUnusedVars)
            {
                file.WriteLine(Environment.NewLine + "--> ATTENTION REVIEWER:");
            }

            if (alertCount > 0)
            {
                file.WriteLine("-Sign ! indicates Autodefined variables");
                file.WriteLine("-Sign * indicates variables poorly defined");
            }

            if (hasUnusedVars)
            {
                file.WriteLine("-Sign @ indicates variables not used in the code");
            }
        }
Beispiel #7
0
        public static void CleanAllVars(KBObject obj)
        {
            ArrayList idVasrBorrar = new ArrayList();

            VariablesPart vp        = obj.Parts.Get <VariablesPart>();
            ArrayList     variables = new ArrayList();

            foreach (Variable v in vp.Variables)
            {
                if (!v.IsStandard)
                {
                    variables.Add(v);
                }
            }
            foreach (Variable v in variables)
            {
                vp.Remove(v);
            }
        }
Beispiel #8
0
        public static List <Variable> VariablesToRename(KBObject obj)
        {
            IKBService kbserv = UIServices.KB;
            KBModel    kbmod  = kbserv.CurrentModel;

            List <Variable> variables = new List <Variable>();
            VariablesPart   vp        = obj.Parts.Get <VariablesPart>();

            if (vp != null)
            {
                foreach (Variable v in vp.Variables)
                {
                    if ((!v.IsStandard) && (v.Type != eDBType.GX_USRDEFTYP) && (v.Type != eDBType.GX_SDT) && (v.Type != eDBType.GX_EXTERNAL_OBJECT))
                    {
                        if (v.AttributeBasedOn != null && !v.Name.ToLower().Contains(v.AttributeBasedOn.Name.ToLower()))
                        {
                            AddVariableToFile(v);
                            variables.Add(v);
                        }
                        else
                        {
                            if (v.DomainBasedOn != null && !v.Name.ToLower().Contains(v.DomainBasedOn.Name.ToLower()))
                            {
                                AddVariableToFile(v);
                                variables.Add(v);
                            }
                            else
                            {
                                if ((v.AttributeBasedOn == null) && (v.DomainBasedOn == null))
                                {
                                    AddVariableToFile(v);
                                    variables.Add(v);
                                }
                            }
                        }
                    }
                }
            }
            return(variables);
        }
Beispiel #9
0
        public void Variables(VariablesPart variables)
        {
            if (mActions.isMenuContext)
            {
                string vname = "gxuiButtonCollection";
                if (variables.GetVariable(vname) == null)
                {
                    Variable var = new Variable(variables);
                    var.Name = vname;
                    DataType.ParseInto(mActions.Parent.Instance.Model, "gxuiButton", var);
                    var.IsCollection = true;
                    variables.Variables.Add(var);
                }
                vname = "gxuiButton";
                if (variables.GetVariable(vname) == null)
                {
                    Variable var = new Variable(variables);
                    var.Name = vname;
                    DataType.ParseInto(mActions.Parent.Instance.Model, "gxuiButton", var);
                    variables.Variables.Add(var);
                }

            }
        }
Beispiel #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);
        }
Beispiel #11
0
 internal static void ObjectsWithVarNotBasedOnAtt(List <KBObject> objs, IOutputService output)
 {
     foreach (KBObject obj in objs)
     {
         string  vnames    = "";
         Boolean hasErrors = false;
         Boolean SaveObj   = false;
         if (isGenerated(obj) && (obj is Transaction || obj is WebPanel || obj is WorkPanel || obj is Procedure))
         {
             string        pic2 = (string)obj.GetPropertyValue("ATT_PICTURE");
             VariablesPart vp   = obj.Parts.Get <VariablesPart>();
             if (vp != null)
             {
                 foreach (Variable v in vp.Variables)
                 {
                     if ((!v.IsStandard) && Utility.VarHasToBeInDomain(v))
                     {
                         string attname = (v.AttributeBasedOn == null) ? "" : v.AttributeBasedOn.Name;
                         string domname = (v.DomainBasedOn == null) ? "" : v.DomainBasedOn.Name;
                         if (attname == "" && domname == "")
                         {
                             string vname = v.Name.ToLower();
                             vnames   += vname + " ";
                             hasErrors = true;
                         }
                     }
                 }
             }
             if (hasErrors)
             {
                 OutputError err = new OutputError("Variables not based in attributes or domain: " + vnames, MessageLevel.Error, new KBObjectPosition(vp));
                 output.Add("KBDoctor", err);
             }
         }
     }
 }
        private static Variable AddVariable(VariablesPart variables, string name)
        {
            if (variables.GetVariable(name) == null)
            {
                Variable var = new Variable(variables);
                var.Name = name;
                variables.Variables.Add(var);
                return var;
            }

            return null;
        }
Beispiel #13
0
 internal static Variable getVariable(VariablesPart obj, string nome, out bool IsNovo)
 {
     if (nome.StartsWith("&"))
         nome = nome.Substring(1);
     Variable var = obj.GetVariable(nome);
     if (var == null)
     {
         IsNovo = true;
         var = new Variable(obj);
         var.Name = nome;
         obj.Variables.Add(var);
     }
     else
     {
         IsNovo = false;
         if (var.Name != nome)
             var.Name = nome;
     }
     return var;
 }
Beispiel #14
0
 internal int MergeVariables(VariablesPart obj, PatternInstanceElement c, string template, bool overwrite)
 {
     string oldValue = serializeVariables(obj);
     if (overwrite)
     {
         obj.Clear();
     }
     if (!String.IsNullOrEmpty(template))
     {
         XmlDocument x = AppendTemplateOutputInner(obj.KBObject, obj, c, template);
         List<string> tem = new List<string>();
         foreach (XmlNode xn in x.FirstChild.SelectNodes("Variable"))
         {
             string nome = xn.Attributes["Name"].Value.ToUpper();
             if (!tem.Contains(nome))
             {
                 tem.Add(nome);
                 XmlToVariable(obj, c, xn);
             }
         }
     }
     if (serializeVariables(obj) != oldValue)
     {
         return 1;
     }
     return 0;
 }
Beispiel #15
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);
     }
 }
Beispiel #16
0
 internal string serializeVariables(VariablesPart obj)
 {
     StringBuilder sb = new StringBuilder();
     foreach(Variable v in obj.Variables)
     {
         sb.Append(v.SerializeToXml());
     }
     return sb.ToString();
 }
Beispiel #17
0
        internal void XmlToVariable(VariablesPart obj,PatternInstanceElement c,XmlNode xn)
        {
            string nome = xn.Attributes["Name"].Value;
            bool IsNovo = false;
            if (Variable.IsValidName(nome))
            {
                try
                {
                    Variable var = getVariable(obj, nome, out IsNovo);
                    foreach (XmlNode xi in xn.SelectNodes("Properties/Property"))
                    {
                        string pnome = xi.SelectSingleNode("Name").InnerText;
                        string pvalue = xi.SelectSingleNode("Value").InnerText;
                        if (pnome == "ATTCUSTOMTYPE" && pvalue.ToUpper().Trim() == "BITMAP" && GXVersion.Version == GXVersion.Versions.Ev2)
                        {
                            pvalue = "IMAGE";
                        }

                        object vs = var.GetPropertyValueFromString(pnome, pvalue);
                        object v = var.GetPropertyValue(pnome);
                        bool atu = true;
                        if (v != null)
                        {
                            if (vs is AttCustomType)
                            {
                                AttCustomType act = (AttCustomType)vs;
                                AttCustomType act2 = (AttCustomType)v;
                                if (act.DataType == act2.DataType && (act.Guid == act2.Guid || (act.Guid == null && act2.Guid == "")))
                                {
                                    atu = false;
                                }
                            }
                            else if (vs is BasedOnReference)
                            {
                                BasedOnReference bof = (BasedOnReference)vs;
                                BasedOnReference bof2 = (BasedOnReference)v;
                                if (bof.ObjData == bof2.ObjData && bof.ObjKey.Equals(bof2.ObjKey))
                                {
                                    atu = false;
                                }
                            }
                            else if (vs is CT_GXTXVAL_type)
                            {
                                CT_GXTXVAL_type gxt = (CT_GXTXVAL_type)vs;
                                CT_GXTXVAL_type gxt2 = (CT_GXTXVAL_type)v;
                                if (gxt.Data.Count == gxt2.Data.Count)
                                {
                                    atu = false;
                                    foreach (KeyValuePair<string, string> current in gxt.Data)
                                    {
                                        if (!gxt2.Data.Contains(current))
                                        {
                                            atu = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (atu && vs != v)
                        {
                            var.SetPropertyValue(pnome, vs);
                        }

                    }
                }
                catch (Exception e)
                {
                    throw new HPatternException(String.Format("Erro ao criar variável: {0}", nome),e);
                }
            }
        }
 private static void addLinkCallBack(HPatternInstance instance,VariablesPart variables)
 {
     if (instance.Settings.Template.GenerateCallBackLink)
     {
         Variable var = AddVariable(variables,HPatternInstance.PARMCALLBACK);
         if (var != null)
             var.DomainBasedOn = Domain.Get(instance.Model,HPatternInstance.PARMCALLBACK);
     }
 }