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); }
protected void OnChildGroupsChanged(VMHostGroup group, bool added) { if (ChildGroupsChanged != null) { ChildGroupsChanged(this, new ChildHostGroupsChangedEventArgs(group, added)); } OnPropertyChanged("ChildGroups"); }
public VMHostGroup(string name) { this.name = name; this.parentGroup = null; this.childGroups = new List <VMHostGroup> (); this.IsRoot = true; hostList = new List <VMHost> (); }
public override Group CreateGroup(string name) { VMHostGroup newGroup = null; if (this.DataObject is XElement) { newGroup = new VMHostGroup(name); this.AddGroup(newGroup); } return(newGroup); }
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); } } }
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(); }
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); }
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); } } } }
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); }
/// <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; }
public ChildHostGroupsChangedEventArgs(VMHostGroup group, bool added) { this.involvedGroup = group; this.isGroupAdded = added; }