Exemplo n.º 1
0
        protected XElement GetXElement(VMHostGroup curGroup)
        {
            XElement elem = new XElement("Group", new XAttribute("Name", curGroup.Name), new XAttribute("GUID", curGroup.GUID));
            //defend collection from modifying
            ObservableCollection <VMHost> _hostList;
            ObservableCollection <Group>  _childGroups;

            lock (curGroup.HostList)
            {
                _hostList = new ObservableCollection <VMHost>(curGroup.HostList);
            }
            lock (curGroup.ChildGroups)
            {
                _childGroups = new ObservableCollection <Group>(curGroup.ChildGroups);
            }
            if (_hostList != null)
            {
                foreach (VMHost host in _hostList)
                {
                    elem.Add(new XElement("Host", new XAttribute("Name", host.Name)));
                }
            }
            if (_childGroups != null)
            {
                foreach (Group childGroup in _childGroups)
                {
                    elem.Add(GetXElement(childGroup as VMHostGroup));
                }
            }
            return(elem);
        }
Exemplo n.º 2
0
 protected void OnChildGroupsChanged(VMHostGroup group, bool added)
 {
     if (ChildGroupsChanged != null)
     {
         ChildGroupsChanged(this, new ChildHostGroupsChangedEventArgs(group, added));
     }
     OnPropertyChanged("ChildGroups");
 }
Exemplo n.º 3
0
 public VMHostGroup(string name)
 {
     this.name        = name;
     this.parentGroup = null;
     this.childGroups = new List <VMHostGroup> ();
     this.IsRoot      = true;
     hostList         = new List <VMHost> ();
 }
Exemplo n.º 4
0
        public override Group CreateGroup(string name)
        {
            VMHostGroup newGroup = null;

            if (this.DataObject is XElement)
            {
                newGroup = new VMHostGroup(name);
                this.AddGroup(newGroup);
            }
            return(newGroup);
        }
Exemplo n.º 5
0
        private void CreateVMHost(object args)
        {
            VMHost      host  = new VMHost((args as object [])[0] as string);
            VMHostGroup group = (args as object[])[1] as VMHostGroup;

            if (host != null)
            {
                lock (group)
                {
                    group.AddHost(host);
                }
            }
        }
Exemplo n.º 6
0
        public void SaveToXML(string FilePath)
        {
            //find root element
            VMHostGroup root = this;

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

            SW.Write(root.GetXElement(root).ToString());
            SW.Close();
        }
Exemplo n.º 7
0
        public VMHostGroup FillVMHostGroupAsync(string path, VMHostGroup hostGroup)
        {
            StreamReader SR       = File.OpenText(path);
            string       hostName = SR.ReadLine();

            while (hostName != null)
            {
                if (hostName[0] != '#')
                {
                    Thread HostAdderThead = new Thread(new ParameterizedThreadStart(CreateVMHost));
                    HostAdderThead.Start(new object[] { hostName, hostGroup });
                }
                hostName = SR.ReadLine();
            }
            return(hostGroup);
        }
Exemplo n.º 8
0
 public void FillVMHostTree(object dataObject, VMHostGroup root)
 {
     if (dataObject is XElement)
     {
         XElement hostTree = dataObject as XElement;
         foreach (XElement xHost in hostTree.Elements("Host"))
         {
             root.AddHost(new VMHost(xHost.Attribute("Name").Value));
         }
         if (root.ChildGroups != null)
         {
             foreach (VMHostGroup childgroup in root.ChildGroups)
             {
                 FillVMHostTree(childgroup.DataObject, childgroup);
             }
         }
     }
 }
Exemplo n.º 9
0
        public static VMHostGroup FindParentFor(string hostName, VMHostGroup root)
        {
            VMHostGroup parent = null;

            if (root.HostList.Any((h) => h.Name == hostName))
            {
                parent = root;
            }
            else
            {
                foreach (VMHostGroup group in root.ChildGroups)
                {
                    parent = FindParentFor(hostName, group);
                    if (parent != null)
                    {
                        //parent = group;
                        break;
                    }
                }
            }
            return(parent);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Returns parent group for VM Host
 /// </summary>
 /// <param name="vm">VMHost a parent is searching for</param>
 /// <param name="root">Root VM group</param>
 /// <returns>Parent VMHostGroup if it exists of null otherwise</returns>
 public static VMHostGroup FindParentFor(VMHost host, VMHostGroup root)
 {
     return(FindParentFor(host.Name, root));
     //VMHostGroup parent = null;
     //if (root.HostList.Contains(host))
     //{
     //    parent = root;
     //}
     //else
     //{
     //    foreach (VMHostGroup group in root.ChildGroups)
     //    {
     //        parent = FindParentFor(host, group);
     //        if (parent != null)
     //        {
     //            //parent = group;
     //            break;
     //        }
     //    }
     //}
     //return parent;
 }
Exemplo n.º 11
0
 public ChildHostGroupsChangedEventArgs(VMHostGroup group, bool added)
 {
     this.involvedGroup = group;
     this.isGroupAdded  = added;
 }