Esempio n. 1
0
        /// <summary>
        /// Loads a WeK Hosts File defined with version 1.0 format.
        /// </summary>
        /// <param name="hostsNavigator"></param>
        private void LoadVersionOneXml(XPathNavigator hostsNavigator)
        {
            XPathNodeIterator HostNodes = hostsNavigator.Select("//wekHosts/host");

            while (HostNodes.MoveNext())
            {
                // Create a new object for the host that is about to be read in.
                WolHost NewHost = new WolHost();

                // Add a new network and set those properties that are completely new
                // in the version 2 XML schemata.
                WolHostNetwork NewNetwork = new WolHostNetwork();
                NewNetwork.NetworkId  = Guid.NewGuid();
                NewNetwork.Name       = "New Network";
                NewNetwork.Locality   = WolHostNetwork.NetworkLocality.LocalSubnet;
                NewNetwork.SubnetMask = IPAddress.None;
                NewHost.Networks.Add(NewNetwork);

                SetHostPropertiesFromXml(NewHost, HostNodes.Current);

                // Process the child nodes of the host item.
                XPathNodeIterator CurrentHostIterator = HostNodes.Current.SelectChildren(XPathNodeType.Element);
                while (CurrentHostIterator.MoveNext())
                {
                    SetHostPropertiesFromXml(NewHost, CurrentHostIterator.Current);
                }

                _hosts.Add(NewHost);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a deep copy of this object.
        /// </summary>
        /// <returns>The deep copy of this WolHost object.</returns>
        public WolHost Clone()
        {
            WolHost CloneObject = MemberwiseClone() as WolHost;

            CloneObject.MachineAddress   = (this.MachineAddress != null ? this.MachineAddress.Clone() : null);
            CloneObject.SecureOnPassword = (this.SecureOnPassword != null ? this.SecureOnPassword.Clone() : null);

            return(CloneObject);
        }
Esempio n. 3
0
        /// <summary>
        /// Writes the configuration data for a WolHost into XML format for storage in a file.
        /// </summary>
        /// <param name="writer">An open XML Writer to which the XML will be written.</param>
        /// <param name="host">The WolHost to be persisted.</param>
        private void PersistHost(XmlWriter writer, WolHost host)
        {
            writer.WriteStartElement("host");
            writer.WriteAttributeString("id", host.Id.ToString());

            if (host.RequireSecureOn)
            {
                writer.WriteAttributeString("secureOn", "true");
            }

            if (host.DefaultNetwork != Guid.Empty)
            {
                writer.WriteAttributeString("defaultNetwork", host.DefaultNetwork.ToString());
            }

            writer.WriteElementString("name", host.Name);
            writer.WriteElementString("owner", host.Owner);
            writer.WriteElementString("physicalAddress", host.MachineAddress.ToString("C", null));
            writer.WriteElementString("description", host.Description);
            writer.WriteElementString("secureOnPassword", (host.RequireSecureOn ? host.SecureOnPassword.ToString("C", null) : null));

            writer.WriteStartElement("networks");

            foreach (WolHostNetwork CurrentNetwork in host.Networks)
            {
                writer.WriteStartElement("network");
                writer.WriteAttributeString("id", CurrentNetwork.NetworkId.ToString());
                writer.WriteElementString("name", CurrentNetwork.Name);
                writer.WriteElementString("locality", CurrentNetwork.Locality.ToString());
                writer.WriteElementString("address", CurrentNetwork.Address);
                writer.WriteElementString("subnetMask", (CurrentNetwork.SubnetMask == IPAddress.None ? null : CurrentNetwork.SubnetMask.ToString()));
                writer.WriteElementString("port", CurrentNetwork.Port.ToString());
                writer.WriteEndElement();
            }

            writer.WriteEndElement();

            writer.WriteEndElement();
        }
Esempio n. 4
0
        /// <summary>
        /// Updates a WolHost instance with settings from persisted XML configuration data.
        /// </summary>
        /// <param name="host"></param>
        /// <param name="hostNodeNavigator"></param>
        private void SetHostPropertiesFromXml(WolHost host, XPathNavigator hostNodeNavigator)
        {
            PhysicalAddress ParsedAddress;

            switch (hostNodeNavigator.Name)
            {
            case "host":
                if (hostNodeNavigator.HasAttributes)
                {
                    string SecureOnAttribute = hostNodeNavigator.GetAttribute("secureOn", String.Empty);
                    host.RequireSecureOn = (String.IsNullOrEmpty(SecureOnAttribute) ? false : SecureOnAttribute.Equals("true", StringComparison.InvariantCultureIgnoreCase));

                    string HostId = hostNodeNavigator.GetAttribute("id", String.Empty);
                    host.Id = String.IsNullOrEmpty(HostId) ? Guid.NewGuid() : new Guid(HostId);

                    string DefaultNetworkId = hostNodeNavigator.GetAttribute("defaultNetwork", String.Empty);
                    host.DefaultNetwork = String.IsNullOrEmpty(DefaultNetworkId) ? Guid.Empty : new Guid(DefaultNetworkId);
                }
                else
                {
                    host.RequireSecureOn = false;
                }

                break;

            case "networks":
                // Process the networks.
                XPathNodeIterator NetworksIterator = hostNodeNavigator.Select("network");
                while (NetworksIterator.MoveNext())
                {
                    WolHostNetwork NewNetwork = new WolHostNetwork();
                    SetNetworkPropertiesFromXml(NewNetwork, NetworksIterator.Current);

                    host.Networks.Add(NewNetwork);
                }

                break;

            case "name":
                host.Name = hostNodeNavigator.Value;
                break;

            case "description":
                host.Description = hostNodeNavigator.Value;
                break;

            case "physicalAddress":
                if (PhysicalAddress.TryParse(hostNodeNavigator.Value, out ParsedAddress))
                {
                    host.MachineAddress = ParsedAddress;
                }
                break;

            case "hostAddress":
                host.Networks[0].Address = hostNodeNavigator.Value;
                break;

            case "hostPort":
                int HostPort;
                if (Int32.TryParse(hostNodeNavigator.Value, out HostPort))
                {
                    host.Networks[0].Port = HostPort;
                }
                else
                {
                    host.Networks[0].Port = 0;
                }
                break;

            case "secureOnPassword":
                if (PhysicalAddress.TryParse(hostNodeNavigator.Value, out ParsedAddress))
                {
                    host.SecureOnPassword = ParsedAddress;
                }
                break;

            case "owner":
                host.Owner = hostNodeNavigator.Value;
                break;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Loads a WeK Hosts File defined with version 2.0 format.
        /// </summary>
        /// <param name="hostsNavigator"></param>
        private void LoadVersionTwoXml(XPathNavigator hostsNavigator)
        {
            // Load the hosts.
            XPathNodeIterator HostNodes = hostsNavigator.Select("//wekHosts/hosts/host");

            while (HostNodes.MoveNext())
            {
                WolHost NewHost = new WolHost();

                SetHostPropertiesFromXml(NewHost, HostNodes.Current);

                // Process child nodes of the host item.
                XPathNodeIterator CurrentHostIterator = HostNodes.Current.SelectChildren(XPathNodeType.Element);
                while (CurrentHostIterator.MoveNext())
                {
                    SetHostPropertiesFromXml(NewHost, CurrentHostIterator.Current);
                }

                // Ensure that there is a default network indicated if not set in the WekHosts file.
                if (NewHost.DefaultNetwork == Guid.Empty && NewHost.Networks.Count > 0)
                {
                    NewHost.DefaultNetwork = NewHost.Networks[0].NetworkId;
                }

                this.Items.Add(NewHost);
            }

            // Load the groups and resolve their membership.
            XPathNodeIterator GroupNodes = hostsNavigator.Select("//wekHosts/groups/group");

            while (GroupNodes.MoveNext())
            {
                WolHostGroup NewGroup = new WolHostGroup();

                if (GroupNodes.Current.HasAttributes)
                {
                    NewGroup.Name = GroupNodes.Current.GetAttribute("name", String.Empty);
                }
                else
                {
                    NewGroup.Name = "_default";
                }

                XPathNodeIterator GroupMemberIterator = GroupNodes.Current.SelectChildren(XPathNodeType.Element);
                while (GroupMemberIterator.MoveNext())
                {
                    switch (GroupMemberIterator.Current.Name)
                    {
                    case "memberHost":
                        WolHost Member = _hosts.Find(delegate(WolHost Host)
                        {
                            return(Host.Id.Equals(new Guid(GroupMemberIterator.Current.Value)));
                        });

                        if (Member != null)
                        {
                            // Set the preferred network for the host when part of the group. The presence of
                            // the default network Id does not guarantee that the network exists for the host.
                            string DefaultNetworkId = null;
                            if (GroupMemberIterator.Current.HasAttributes)
                            {
                                DefaultNetworkId = GroupMemberIterator.Current.GetAttribute("defaultNetwork", String.Empty);
                                if (String.IsNullOrEmpty(DefaultNetworkId) == false)
                                {
                                    NewGroup.Add(new WolHostGroupMember(Member, new Guid(DefaultNetworkId)));
                                }
                            }

                            if (String.IsNullOrEmpty(DefaultNetworkId) == false)
                            {
                                NewGroup.Add(new WolHostGroupMember(Member, new Guid(DefaultNetworkId)));
                            }
                            else
                            {
                                NewGroup.Add(new WolHostGroupMember(Member));
                            }
                        }

                        break;
                    }
                }

                this.HostGroups.Add(NewGroup);
            }
        }
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="host"></param>
 /// <param name="defaultNetwork"></param>
 public WolHostGroupMember(WolHost host, Guid defaultNetwork)
 {
     this.DefaultNetwork = defaultNetwork;
     this.Host           = host;
 }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="host"></param>
 public WolHostGroupMember(WolHost host)
     : this(host, Guid.Empty)
 {
 }