Example #1
0
        public static void AssignDescriptionToAttribute(object[] parameters, int descriptionToSet)
        {
            foreach (object o in parameters)
            {
                Dictionary <string, string> dic = (Dictionary <string, string>)o;
                int cant = 0;

                string            attName = "";
                string            mensaje = "";
                PromptDescription pd;
                DialogResult      dr;

                foreach (string s in dic.Values)
                {
                    if (cant == 1)
                    {
                        attName = s;
                        switch (descriptionToSet)
                        {
                        case 0:
                            mensaje = "Insert description for attribute " + attName;
                            break;

                        case 1:
                            mensaje = "Insert title for attribute " + attName;
                            break;

                        case 2:
                            mensaje = "Insert column title for attribute " + attName;
                            break;
                        }

                        pd = new PromptDescription(mensaje);
                        dr = pd.ShowDialog();

                        if (dr == DialogResult.OK)
                        {
                            Artech.Genexus.Common.Objects.Attribute a = Artech.Genexus.Common.Objects.Attribute.Get(UIServices.KB.CurrentModel, attName);
                            switch (descriptionToSet)
                            {
                            case 0:
                                a.Description = pd.Description;
                                break;

                            case 1:
                                a.Title = pd.Description;
                                break;

                            case 2:
                                a.ColumnTitle = pd.Description;
                                break;
                            }
                            a.Save();
                        }
                    }

                    cant++;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Search and replace text in objects
        /// </summary>
        public static void SearchAndReplace() //SearchAndReplace()
        {
            IKBService     kB     = UIServices.KB;
            IOutputService output = CommonServices.Output;

            string mensaje = "";
            string title   = "Search and replace";

            output.StartSection(title);
            if (kB != null && kB.CurrentModel != null)
            {
                PromptDescription pd;
                DialogResult      dr;
                mensaje = "Find";

                pd = new PromptDescription(mensaje);
                dr = pd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    string txtfind = pd.Description;
                    mensaje = "Replace with";
                    pd      = new PromptDescription(mensaje);
                    dr      = pd.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        string txtreplace = pd.Description;
                        SelectObjectOptions selectObjectOption = new SelectObjectOptions();
                        selectObjectOption.MultipleSelection = true;
                        KBModel kbModel = UIServices.KB.CurrentModel;

                        int objcambiados = 0;
                        int objtotales   = 0;
                        //SELECCIONO OBJETOS A BUSCAR
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Procedure>());
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <Transaction>());
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <WebPanel>());
                        selectObjectOption.ObjectTypes.Add(KBObjectDescriptor.Get <WorkPanel>());

                        foreach (KBObject obj in UIServices.SelectObjectDialog.SelectObjects(selectObjectOption))
                        {
                            objtotales += 1;
                            Application.DoEvents();
                            if ((objtotales % 100) == 0)
                            {
                                output.AddLine("Searching in " + objtotales + " objects ");
                            }

                            StringBuilder buffer = new StringBuilder();
                            using (TextWriter writer = new StringWriter(buffer))
                                obj.Serialize(writer);

                            string objxml    = buffer.ToString();
                            string newobjxml = objxml.Replace(txtfind, txtreplace, StringComparison.InvariantCultureIgnoreCase);

                            using (StringReader strReader = new StringReader(newobjxml))
                                using (XmlTextReader reader = new XmlTextReader(strReader))
                                    BLServices.KnowledgeManager.ImportInObject(reader, obj);
                            if (objxml != newobjxml)
                            {
                                try
                                {
                                    obj.Save();
                                    output.AddLine("Changed >> '" + txtfind + "' to '" + txtreplace + "' in object " + obj.Name);
                                    objcambiados += 1;
                                }
                                catch (Exception e)
                                {
                                    if (e.InnerException == null)
                                    {
                                        output.AddErrorLine(e.Message);
                                    }
                                    else
                                    {
                                        output.AddErrorLine(e.Message + " - " + e.InnerException);
                                    }
                                };
                            }
                        }
                        title = "Changed objects " + objcambiados.ToString();
                        output.EndSection(title, true);
                    }
                }
            }
        }