Пример #1
0
        protected XElement GetXElement(VMGroup curGroup)
        {
            XElement elem = new XElement("Group", new XAttribute("Name", curGroup.Name), new XAttribute("GUID", curGroup.GUID));
            //defend collection from modifying
            ObservableCollection <VM>    _vmList;
            ObservableCollection <Group> _childGroups;

            lock (curGroup.VMList)
            {
                _vmList = new ObservableCollection <VM>(curGroup.VMList);
            }
            lock (curGroup.ChildGroups)
            {
                _childGroups = new ObservableCollection <Group>(curGroup.ChildGroups);
            }
            if (_vmList != null)
            {
                foreach (VM vm in _vmList)
                {
                    elem.Add(new XElement("VM", new XAttribute("GUID", vm.GUID)));
                }
            }
            if (_childGroups != null)
            {
                foreach (Group childGroup in _childGroups)
                {
                    elem.Add(GetXElement(childGroup as VMGroup));
                }
            }
            return(elem);
        }
Пример #2
0
        private void RemoveVMGroup(object selectedItem)
        {
            VMGroup group = this.SelectedItem as VMGroup;

            vmModel.RemoveGroup(group);
            group.Save();
        }
Пример #3
0
        private void RenameNode(object Node)
        {
            //this.View.RenameActiveTreeNode();
            OnRenameActiveTreeNodeRequested();
            VMGroup grp = this.SelectedItem as VMGroup;

            grp.IsInEditMode = true;
        }
Пример #4
0
        public override Group CreateGroup(string name)
        {
            VMGroup newGroup = new VMGroup(new XElement("Group", new XAttribute("Name", name), new XAttribute("GUID", Guid.NewGuid())), this);

            if (this.DataObject is XElement)
            {
                this.AddGroup(newGroup);
            }
            return(newGroup);
        }
Пример #5
0
        private void CreateVMGroup(object selectedItem)
        {
            VMGroup parent = selectedItem as VMGroup;

            if (parent != null)
            {
                VMGroup newGroup = vmModel.CreateGroup(parent) as VMGroup;
                parent.Save();
                parent.IsExpanded     = true;
                newGroup.IsActive     = true;
                newGroup.IsInEditMode = true;
            }
        }
Пример #6
0
        public void SaveToXML(string FilePath)
        {
            //find root element
            VMGroup root = this;

            while (root.ParentGroup != null)
            {
                root = root.ParentGroup as VMGroup;
            }
            StreamWriter SW = File.CreateText(FilePath);

            SW.Write(root.GetXElement(root).ToString());
            SW.Close();
        }
Пример #7
0
        public static VMGroup FindParentForVM(VM vm, object dataObject, VMGroup root)
        {
            VMGroup parent = null;

            if (dataObject is XElement)
            {
                XElement VMTree = dataObject as XElement;

                if ((vm != null) && (VMTree != null))
                {
                    IEnumerable <XElement> children = VMTree.Descendants();
                    var query = from el in VMTree.Descendants() where el.Attribute("GUID").Value == vm.GUID.ToString() select el;
                    foreach (XElement xVM in query)
                    {
                        parent = Group.GetElementByID(xVM.Parent.Attribute("GUID").Value, root) as VMGroup;
                        break;
                    }
                }
            }
            return(parent);
        }
Пример #8
0
        /// <summary>
        /// Returns parent group for VM
        /// </summary>
        /// <param name="vm">VM a parent is searching for</param>
        /// <param name="root">Root VM group</param>
        /// <returns>Parent VMGroup if it exists of null otherwise</returns>
        public static VMGroup FindParentFor(VM vm, VMGroup root)
        {
            VMGroup parent = null;

            if (root.VMList.Contains(vm))
            {
                parent = root;
            }
            else
            {
                foreach (VMGroup group in root.ChildGroups)
                {
                    parent = FindParentFor(vm, group);
                    if (parent != null)
                    {
                        //parent = group;
                        break;
                    }
                }
            }
            return(parent);
        }