Esempio n. 1
0
        protected override void OnItemDrag(ItemDragEventArgs e)
        {
            RepositoryNode item = e.Item as RepositoryNode;

            if (((item != null) && (item.Repository != null)) && item.Repository.IsQueryable)
            {
                base.SelectedNode = item;
                base.DoDragDrop(new RepositoryDragData(item.Repository), DragDropEffects.Link | DragDropEffects.Copy);
            }
            else
            {
                BaseNode node = e.Item as BaseNode;
                if ((node != null) && !string.IsNullOrEmpty(node.DragText))
                {
                    base.SelectedNode = node;
                    RepositoryNode queryableRespositoryParent = this.GetQueryableRespositoryParent(node);
                    if (queryableRespositoryParent != null)
                    {
                        DragRepository = queryableRespositoryParent.Repository;
                    }
                    try
                    {
                        base.DoDragDrop(node.DragText, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll);
                    }
                    finally
                    {
                        DragRepository = null;
                    }
                }
            }
            base.OnItemDrag(e);
        }
Esempio n. 2
0
 internal void Edit(RepositoryNode node)
 {
     if (RepositoryDialogManager.Show(node.Repository, false))
     {
         this.UpdateRepositoryNode(node);
     }
 }
Esempio n. 3
0
        private void loadTree()
        {
            this.treeView1.Nodes.Clear();
            TreeNode root = this.treeView1.Nodes.Add("Repositorios", "Repositorios", 0, 1);

            try
            {
                foreach (RepositoryInfo repository in OfficeApplication.OfficeApplicationProxy.getRepositories())
                {
                    RepositoryNode repositoryNode = new RepositoryNode(repository);
                    root.Nodes.Add(repositoryNode);
                    foreach (CategoryInfo category in OfficeApplication.OfficeApplicationProxy.getCategories(repository.name))
                    {
                        CategoryNode categoryNode = new CategoryNode(category, repository);
                        repositoryNode.Nodes.Add(categoryNode);
                        if (category.childs > 0)
                        {
                            TreeNode dummyNode = new DummyNode();
                            categoryNode.Nodes.Add(dummyNode);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                OfficeApplication.WriteError(e);
            }
            if (this.treeView1.Nodes.Count > 0)
            {
                this.treeView1.Nodes[0].Expand();
            }
        }
Esempio n. 4
0
        public void CompileTemplates(RepositoryNode repository)
        {
            var compilerParams = new CompilerParameters
            {
                GenerateInMemory      = true,
                TreatWarningsAsErrors = false,
                GenerateExecutable    = false,
                CompilerOptions       = "/optimize"
            };

            compilerParams.ReferencedAssemblies.AddRange(new[] { "System.dll", "mscorlib.dll", "System.Core.dll", Assembly.GetEntryAssembly()?.Location, typeof(ProtoContractAttribute).Assembly.Location });

            var provider  = new CSharpCodeProvider();
            var usingList = string.Join("", DefaultNamespaces.Select(u => $"using {u}; "));
            var codes     = repository.GetFiles().Select(template => usingList + template).ToArray();

            var compile = provider.CompileAssemblyFromSource(compilerParams, codes);

            if (compile.Errors.HasErrors)
            {
                // TODO: conveniently display on form
                var text = compile.Errors.Cast <CompilerError>().Aggregate("Compile error: ", (current, ce) => current + ("rn" + ce));

                throw new Exception(text);
            }

            _assembly = compile.CompiledAssembly;
        }
Esempio n. 5
0
        public void LoadTemplate(RepositoryNode source)
        {
            _source = source;

            templateEditor.Text = source.Content;

            ParentTab.Text = _source.Name;
        }
Esempio n. 6
0
 public void LoadProtocol(RepositoryNode repository)
 {
     if (repository.Type == EntryType.Protocol)
     {
         CompileTemplates(repository);
         ParseAssembly();
     }
 }
        private static void CreateXML(List <TreeNode> nodeHierarchyElements)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                MessageBox.Show("Please select the newly created xml file");
                return;
            }
            RepositoryUtility utility  = new RepositoryUtility();
            RepositoryNode    nodeInfo = utility.ReadData(fileName);

            if (nodeInfo == null)
            {
                nodeInfo = new RepositoryNode();
            }
            List <UIControl> controlNodeColl = nodeInfo.ChildNodes;

            bool isChildAdded = false;

            foreach (var nodeElement in nodeHierarchyElements)
            {
                UIControl control = new UIControl();
                //Add Technology and ApplicationType
                control.ApplicationType = ApplicationTypes.Windows;
                control.TechnologyType  = TechnologyTypes.White;

                var aeNode        = (AutomationElementTreeNode)nodeElement.Tag;
                var currentNodeAE = aeNode.AutomationElement.Current;

                //Set display name to XML
                SetDisplayName(control, currentNodeAE);

                //Set Search Properties to XML
                SetSearchProperties(control, currentNodeAE);
                int index = -1;
                //
                if (FindControl(controlNodeColl, control, out index))
                {
                    //if control already eist in the file , index is the postion of the control
                    controlNodeColl = controlNodeColl[index].ChildNodes;
                }
                else
                {
                    // if control not exist then adding childern
                    controlNodeColl = AddChild(controlNodeColl, control);
                    isChildAdded    = true;
                }
            }
            if (!isChildAdded)
            {
                DialogResult d = MessageBox.Show("Element already existing ...", "Duplicate Element !!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (d == DialogResult.OK)
                {
                    return;
                }
            }
            utility.WriteData(nodeInfo, fileName);
            MessageBox.Show("Element added successfully... \n\nFile Name: " + fileName, "Success !!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 8
0
 private void DataContextGenerationError(DataContextInfo dcInfo)
 {
     base.BeginInvoke(delegate {
         RepositoryNode node = this.GetAllRepositoryNodes(true).FirstOrDefault <RepositoryNode>(db => db.Repository == dcInfo.Repository);
         if (node != null)
         {
             node.ShowErrorIfUninitialized(dcInfo.Error);
         }
     });
 }
Esempio n. 9
0
        protected override void OnAfterCollapse(TreeViewEventArgs e)
        {
            RepositoryNode node = e.Node as RepositoryNode;

            if (node != null)
            {
                node.ExpandOnUpdate = false;
            }
            base.OnAfterCollapse(e);
        }
Esempio n. 10
0
        public void RepositoryNode()
        {
            TestingConfiguration config = new TestingConfiguration();

            config.Load("repository-node");

            RepositoryNode node = config.RepositoryNodes["css-path"];

            Assert.IsNotNull(node);
            Assert.AreEqual(Path.Combine(config.Location, "css"), node.RelativePath);
        }
Esempio n. 11
0
        // TODO: a racing condition occurs here when new packets are arrived while we are in the process of applying protocol,
        //  leading to new packet events appearing on top of the table
        public async void ApplyProtocol(RepositoryNode protocol)
        {
            eventsTable.Rows.Clear();
            _eventIndex = 1;

            await Task.Factory.StartNew(() => ApplyProtocolThreaded(protocol));

            if (_templateParser != null)
            {
                UpdateUI();
                ToggleEventsView();
            }
        }
Esempio n. 12
0
 private void ApplyProtocolThreaded(RepositoryNode protocol)
 {
     try
     {
         _templateParser = new TemplateParser();
         _templateParser.LoadProtocol(protocol);
         _connectionInfo.ParseEvents(_templateParser);
     }
     catch (Exception e)
     {
         _templateParser = null;
         MessageBox.Show(e.Message, "Error applying protocol", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 13
0
        public static ImportNode FilesToTree(string[] files, RepositoryNode target)
        {
            var tree = new ImportNode(target.Name, target.Name, EntryType.Folder);

            foreach (var file in files)
            {
                var newNode = PathToTree(file, target);

                tree.SubNodes.Add(newNode);
                tree.TotalConflicts += newNode.TotalConflicts;
            }

            return(tree);
        }
Esempio n. 14
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "XML File Only |*.XML";
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                selectedFileName = openFile.FileName;
                MessageBox.Show("File loaded: " + selectedFileName);
            }
            RepositoryUtility            utility  = new RepositoryUtility();
            RepositoryNode               nodeInfo = utility.ReadData(OpenFileLocation);
            AutomationElementTreeControl aetc     = new AutomationElementTreeControl();

            aetc.FileName = OpenFileLocation;
        }
Esempio n. 15
0
        internal void Delete(RepositoryNode node)
        {
            if (node.Repository.Persist)
            {
                node.Repository.Persist = false;
                node.Repository.SaveToDisk();
            }
            base.Nodes.Remove(node);
            node.Dispose();
            RepositoryArgs args = new RepositoryArgs {
                Repository = node.Repository
            };

            this.OnRepositoryDeleted(args);
            this.UpdateAllNodeText();
        }
Esempio n. 16
0
        private void CreateTemplateEditorTab(RepositoryNode repositoryNode)
        {
            var newTab     = new TabPage($"{repositoryNode.Name}");
            var newControl = new TemplateEditorControl()
            {
                Dock       = DockStyle.Fill,
                ParentForm = this,
                ParentTab  = newTab
            };

            newTab.Controls.Add(newControl);
            newTab.Tag = repositoryNode;

            tabControl.TabPages.Add(newTab);
            tabControl.SelectTab(newTab);

            newControl.LoadTemplate(repositoryNode);
        }
Esempio n. 17
0
        private void OnCreateProtocolMenuClick(object sender, EventArgs e)
        {
            if (configView.SelectedNode != null && configView.SelectedNode.Tag is ApplicationNode appNode)
            {
                var newProtocol = new RepositoryNode(EntryType.Protocol);
                var newNode     = new TreeNode("New Protocol", 0, 0)
                {
                    Tag = newProtocol
                };

                appNode.Protocols.Add(newProtocol);
                configView.SelectedNode.Nodes.Add(newNode);
                configView.SelectedNode = newNode;

                configView.LabelEdit = true;
                configView.SelectedNode.BeginEdit();
            }
        }
        private static void CreateXML_Old(List <TreeNode> parents)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                MessageBox.Show("Please select the newly created xml file");
                return;
            }
            RepositoryUtility utility  = new RepositoryUtility();
            RepositoryNode    nodeInfo = utility.ReadData(fileName);

            if (nodeInfo == null)
            {
                nodeInfo = new RepositoryNode();
            }

            List <UIControl> childList    = nodeInfo.ChildNodes;
            bool             isChildAdded = false;

            foreach (var node in parents)
            {
                UIControl control = new UIControl();
                control.ApplicationType = ApplicationTypes.Windows;
                control.TechnologyType  = TechnologyTypes.White;

                var aeNode      = (AutomationElementTreeNode)node.Tag;
                var ElementInfo = aeNode.AutomationElement.Current;
                control.Name = ElementInfo.Name;
                SetSearchProperties(control, ElementInfo);
                int index = -1;
                if (FindControl(childList, control, out index))
                {
                    childList = childList[index].ChildNodes;
                }
                else
                {
                    childList = AddChild(childList, control); isChildAdded = true;
                }
            }
            if (!isChildAdded)
            {
                MessageBox.Show("Element already existing ...");
            }
            utility.WriteData(nodeInfo, fileName);
        }
Esempio n. 19
0
        public static ImportNode PathToTree(string path, RepositoryNode target = null)
        {
            var attributes = File.GetAttributes(path);
            var filename   = Path.GetFileNameWithoutExtension(path);
            var tree       = new ImportNode()
            {
                Path = path, Name = filename
            };

            if (attributes.HasFlag(FileAttributes.Directory))
            {
                tree.Type = EntryType.Folder;

                RepositoryNode folderNode = null;
                target?.TryGetFolder(filename, out folderNode);

                foreach (var file in Directory.GetFiles(path))
                {
                    var newNode = PathToTree(file, folderNode);

                    tree.SubNodes.Add(newNode);

                    if (newNode.FileExistsInConfig)
                    {
                        tree.TotalConflicts++;
                    }
                }
            }
            else
            {
                tree.Type = EntryType.Template;

                RepositoryNode fileNode = null;
                target?.TryGetFile(filename, out fileNode);

                if (fileNode != null)
                {
                    tree.FileExistsInConfig = true;
                    tree.TotalConflicts++;
                }
            }

            return(tree);
        }
Esempio n. 20
0
        private TreeNode RepositoryToTreeNodes(RepositoryNode repository)
        {
            var node = new TreeNode(repository.Name, repository.IconIndex, repository.IconIndex)
            {
                Tag = repository
            };

            foreach (var childRepository in repository.Items)
            {
                node.Nodes.Add(RepositoryToTreeNodes(childRepository));
            }

            if (repository.NodeOpened)
            {
                node.Expand();
            }

            return(node);
        }
Esempio n. 21
0
 private void addCategoryToRepository(RepositoryNode repository)
 {
     try
     {
         foreach (CategoryInfo category in OfficeApplication.OfficeApplicationProxy.getCategories(repository.Repository.name))
         {
             CategoryNode categoryNode = new CategoryNode(category, repository.Repository);
             repository.Nodes.Add(categoryNode);
             if (category.childs > 0)
             {
                 TreeNode dummyNode = new DummyNode();
                 categoryNode.Nodes.Add(dummyNode);
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 22
0
        public void EmptyRelation()
        {
            this.Explorer.AddRepository(this.Repository);

            var domain = this.Repository.Domain;

            domain.Name = "MyDomain";

            var relationType = domain.AddDeclaredRelationType(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid());

            relationType.SendChangedEvent();
            domain.SendChangedEvent();

            Assert.AreEqual(1, RepositoryNode.FindByTagType(typeof(RelationTypeTag)).Length);

            var relationNode = RepositoryNode.FindByTagType(typeof(RelationTypeTag))[0];

            Assert.AreEqual(relationType.Id.ToString(), relationNode.Target.Text);
            Assert.AreEqual(new RelationTypeTag(this.Repository, relationType), relationNode.Target.Tag);
        }
Esempio n. 23
0
        protected override void OnAfterExpand(TreeViewEventArgs e)
        {
            TreeNode nodeAt = base.GetNodeAt(this._lastMousePos);

            if (nodeAt == e.Node)
            {
                base.SelectedNode = e.Node;
            }
            RepositoryNode node2 = nodeAt as RepositoryNode;

            if (node2 != null)
            {
                node2.ExpandOnUpdate = true;
            }
            base.OnAfterExpand(e);
            if (e.Node is BaseNode)
            {
                ((BaseNode)e.Node).OnAfterExpand();
            }
        }
Esempio n. 24
0
        public Repository GetCurrentRepository(bool queryableOnly)
        {
            TreeNode selectedNode = base.SelectedNode;

            while (!(selectedNode is RepositoryNode))
            {
                if (selectedNode == null)
                {
                    return(null);
                }
                selectedNode = selectedNode.Parent;
            }
            RepositoryNode node2 = selectedNode as RepositoryNode;

            if (queryableOnly && ((node2 == null) || !node2.Repository.IsQueryable))
            {
                return(null);
            }
            return(node2.Repository);
        }
Esempio n. 25
0
        private static void CreateXML(List <TreeNode> parents)
        {
            var               fileName = @"C:\Temp\ObjectRepo.xml";
            UIControl         control;
            RepositoryUtility utility  = new RepositoryUtility();
            RepositoryNode    nodeInfo = utility.ReadData(fileName);

            if (nodeInfo == null)
            {
                nodeInfo = new RepositoryNode();
            }

            List <UIControl> childList    = nodeInfo.ChildNodes;
            bool             isChildAdded = false;

            foreach (var node in parents)
            {
                control = new UIControl();
                control.ApplicationType = ApplicationTypes.Windows;
                control.TechnologyType  = TechnologyTypes.White;

                var aeNode      = (AutomationElementTreeNode)node.Tag;
                var ElementInfo = aeNode.AutomationElement.Current;
                control.Name = ElementInfo.Name;
                checkEmptyElement(control, ElementInfo);
                int index = -1;
                if (FindControl(childList, control, out index))
                {
                    childList = childList[index].ChildNodes;
                }
                else
                {
                    childList = AddChild(childList, control); isChildAdded = true;
                }
            }
            if (!isChildAdded)
            {
                MessageBox.Show("Element already existing ...");
            }
            utility.WriteData(nodeInfo, fileName);
        }
Esempio n. 26
0
        private void ImportTreeToConfig(ImportNode tree, RepositoryNode target, OverwriteAction action)
        {
            foreach (var entry in tree.SubNodes)
            {
                if (entry.Type == EntryType.Folder)
                {
                    if (!target.TryGetFolder(entry.Name, out var folderNode))
                    {
                        folderNode = target.AddItem(EntryType.Folder, entry.Name);
                    }

                    ImportTreeToConfig(entry, folderNode, action);
                }
                else if (entry.Type == EntryType.Template)
                {
                    if (target.TryGetFile(entry.Name, out var fileNode))
                    {
                        switch (action)
                        {
                        case OverwriteAction.OverwriteAll:
                            fileNode.Content = File.ReadAllText(entry.Path);
                            break;

                        case OverwriteAction.SkipAll:
                            break;

                        case OverwriteAction.PromptEvery:
                            // TODO: prompt user for file overwriting
                            break;
                        }
                    }
                    else
                    {
                        target.AddItem(EntryType.Template, entry.Name, File.ReadAllText(entry.Path));
                    }
                }
            }
        }
Esempio n. 27
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "XML File Only |*.XML";
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                selectedFileName = openFile.FileName;
                MessageBox.Show("File loaded: " + selectedFileName, "Success!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            RepositoryUtility utility = new RepositoryUtility();

            if (!string.IsNullOrEmpty(OpenFileLocation))
            {
                RepositoryNode nodeInfo           = utility.ReadData(OpenFileLocation);
                AutomationElementTreeControl aetc = new AutomationElementTreeControl();
                aetc.FileName = OpenFileLocation;
                this.Text     = "Visual UI Automation Verify : Client Side Provider - File Name : " + OpenFileLocation;
            }
            else if (string.IsNullOrEmpty(OpenFileLocation))
            {
                this.Text = "Visual UI Automation Verify : Client Side Provider";
            }
        }
Esempio n. 28
0
        public static string CreateOrUpdatePhysicalInstanceForFile <TImporter>(Guid fileId, string filePath, string agencyId, PhysicalInstance existingPhysicalInstance)
            where TImporter : IDataImporter, new()
        {
            var logger = LogManager.GetLogger("Curation");

            logger.Debug("File import: " + fileId);

            IDataImporter    importer         = new TImporter();
            var              client           = RepositoryHelper.GetClient();
            PhysicalInstance physicalInstance = existingPhysicalInstance;

            // For PhysicalInstances that do not exist yet, create from scratch.
            if (physicalInstance == null)
            {
                // Extract metadata.
                ResourcePackage rp = importer.Import(filePath, agencyId);
                logger.Debug("Imported metadata from data file.");

                if (rp.PhysicalInstances.Count == 0)
                {
                    logger.Debug("No dataset could be extracted from SPSS");
                    return(string.Empty);
                }

                physicalInstance            = rp.PhysicalInstances[0];
                physicalInstance.Identifier = fileId;
            }
            else
            {
                // If there is an existing PhysicalInstance, update it from the data file.
                var updateCommand = new UpdatePhysicalInstanceFromFile();
                updateCommand.DataImporters = new List <IDataImporter>();
                updateCommand.DataImporters.Add(new SpssImporter());
                updateCommand.DataImporters.Add(new StataImporter());
                updateCommand.DataImporters.Add(new SasImporter());
                updateCommand.DataImporters.Add(new RDataImporter());
                updateCommand.DataImporters.Add(new CsvImporter());


                var context = new Algenta.Colectica.ViewModel.Commands.VersionableCommandContext();

                // Update the PhysicalInstance from the data file.
                var repoNode     = new RepositoryNode(client, null);
                var repoItemNode = new RepositoryItemNode(existingPhysicalInstance.GetMetadata(), repoNode, client);
                context.Node = repoItemNode;
                context.Item = physicalInstance;

                try
                {
                    updateCommand.Execute(context);

                    physicalInstance.Version++;
                    foreach (var item in updateCommand.Result.ModifiedItems)
                    {
                        item.Version++;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Problem updating PhysicalInstance.", ex);
                    return("Problem updating PhysicalInstance. " + ex.Message);
                }
            }

            // Calculate summary statistics, for both new and updated files.
            try
            {
                logger.Debug("Calculating summary statistics");
                var calculator = new PhysicalInstanceSummaryStatisticComputer();
                SummaryStatisticsOptions options = new SummaryStatisticsOptions()
                {
                    CalculateQuartiles = true
                };
                var stats = calculator.ComputeStatistics(importer, filePath, physicalInstance,
                                                         physicalInstance.FileStructure.CaseQuantity, options, (percent, message) => { });
                logger.Debug("Done calculating summary statistics");

                if (stats != null)
                {
                    physicalInstance.Statistics.Clear();
                    foreach (VariableStatistic stat in stats)
                    {
                        physicalInstance.Statistics.Add(stat);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Problem calculating summary statistics.", ex);
                return("Problem calculating summary statistics. " + ex.Message);
            }


            // Register all items that were created with the repository.
            DirtyItemGatherer visitor = new DirtyItemGatherer(false, true);

            physicalInstance.Accept(visitor);

            logger.Debug("Setting agency IDs");

            // The static default agency id is not thread safe, so set it explicitly here
            foreach (var item in visitor.DirtyItems)
            {
                item.AgencyId = agencyId;
            }

            logger.Debug("Done setting agency IDs");
            logger.Debug("Registering items with the repository");

            var repoOptions = new Algenta.Colectica.Model.Repository.CommitOptions();

            repoOptions.NamedOptions.Add("RegisterOrReplace");
            client.RegisterItems(visitor.DirtyItems, repoOptions);

            logger.Debug("Done registering items with the repository");
            logger.Debug("Done with CreatePhysicalInstanceForFile");

            return(string.Empty);
        }
        private void openXML(List <TreeNode> nodeHierarchyElements)
        {
            List <string> controlNames = new List <string>();

            foreach (var nodeElement in nodeHierarchyElements)
            {
                controlNames.Add(((AutomationElementTreeNode)nodeElement.Tag).AutomationElement.Current.Name);
            }

            var query = controlNames.GroupBy(x => x).Where(g => g.Count() > 1).ToDictionary(x => x.Key, y => y.Count());

            if (string.IsNullOrEmpty(fileName))
            {
                MessageBox.Show("Please select the newly created xml file");
                return;
            }

            RepositoryUtility utility  = new RepositoryUtility();
            RepositoryNode    nodeInfo = (utility.ReadData(fileName) == null) ? new RepositoryNode() : utility.ReadData(fileName);

            List <UIControl> controlNodeColl = nodeInfo.ChildNodes;
            bool             isChildAdded = false;
            UIControl        control = null;
            List <string>    nameList = new List <string>(); int inc = 0;
            int i = 0; XDocument doc = null;

            foreach (var nodeElement in nodeHierarchyElements)
            {
                control = ConstructUIControlFromXMLNode(control, nodeElement);

                int index = -1; nameList.Add(control.Name);
                if (FindControl(controlNodeColl, control, out index, nameList))
                {
                    //if control already eist in the file , index is the postion of the control
                    controlNodeColl = controlNodeColl[index].ChildNodes;
                    int maxNumber = 0;
                    doc = new XDocument();
                    try
                    {
                        doc = XDocument.Load(fileName);
                        var count = doc.Descendants().Elements("ControlNode").Where(x => x.Attribute("DisplayName").Value.StartsWith(control.Name));
                        if (count.Count() > 0)
                        {
                            maxNumber = count.Count() + inc++;
                        }
                    }
                    catch
                    {
                        if (controlNames.Where(r => r.Equals(control.Name)).Count() > 1)
                        {
                            maxNumber = i++;
                        }
                    }
                    control.Name = control.Name + (maxNumber > 0 ? "_" + maxNumber.ToString() : "");
                }
                else
                {
                    int maxNumber = 0;
                    doc = new XDocument();
                    try
                    {
                        doc = XDocument.Load(fileName);
                    }
                    catch
                    {
                        if (controlNames.Where(r => r.Equals(control.Name)).Count() > 1)
                        {
                            maxNumber = i++;
                        }
                    }

                    var subfolders = doc.Descendants().Elements("ControlNode").Where(x => x.Attribute("DisplayName").Value.StartsWith(control.Name));
                    // if control not exist then adding childern
                    if (subfolders.Count() > 0)
                    {
                        maxNumber = subfolders.Count() + inc++;
                    }

                    // int.TryParse(maxuinode.Name.Substring(node.Name.Length).Remove(0, 1), out maxNumber);
                    control.Name    = control.Name + (maxNumber > 0 ? "_" + maxNumber.ToString() : "");
                    controlNodeColl = AddChild(controlNodeColl, control);
                    isChildAdded    = true;
                }
            }
            //UIControl topParent = GetTopParent(control);
            if (!isChildAdded)
            {
                DialogResult d = MessageBox.Show("Element already existing ...", "Duplicate Element !!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (d == DialogResult.OK)
                {
                    return;
                }
            }
            utility.WriteData(nodeInfo, fileName);
            MessageBox.Show("Element added successfully... \n\nFile Name: " + fileName, "Success !!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }