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>
        /// 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. 3
0
        /// <summary>
        /// Updates a WolHostNetwork instance with settings from persisted XML configuration data.
        /// </summary>
        /// <param name="network"></param>
        /// <param name="networkNodeNavigator"></param>
        private void SetNetworkPropertiesFromXml(WolHostNetwork network, XPathNavigator networkNodeNavigator)
        {
            if (networkNodeNavigator.HasAttributes)
            {
                string NetworkId = networkNodeNavigator.GetAttribute("id", String.Empty);
                if (String.IsNullOrEmpty(NetworkId) == false)
                {
                    network.NetworkId = new Guid(NetworkId);
                }
                else
                {
                    throw new InvalidDataException("Host network cannot be defined without a Network Id.");
                }
            }

            XPathNodeIterator NetworkNodeIterator = networkNodeNavigator.SelectDescendants(XPathNodeType.Element, false);

            while (NetworkNodeIterator.MoveNext())
            {
                switch (NetworkNodeIterator.Current.Name)
                {
                case "address":
                    network.Address = NetworkNodeIterator.Current.Value;
                    break;

                case "locality":
                    if (String.IsNullOrEmpty(NetworkNodeIterator.Current.Value) == false)
                    {
                        network.Locality = (WolHostNetwork.NetworkLocality)Enum.Parse(typeof(WolHostNetwork.NetworkLocality),
                                                                                      NetworkNodeIterator.Current.Value);
                    }
                    else
                    {
                        network.Locality = WolHostNetwork.NetworkLocality.LocalSubnet;
                    }
                    break;

                case "name":
                    network.Name = NetworkNodeIterator.Current.Value;
                    break;

                case "port":
                    int HostPort;
                    if (Int32.TryParse(NetworkNodeIterator.Current.Value, out HostPort))
                    {
                        network.Port = HostPort;
                    }
                    else
                    {
                        network.Port = 0;
                    }
                    break;

                case "subnetMask":
                    IPAddress PersistedMask;
                    if (IPAddress.TryParse(NetworkNodeIterator.Current.Value, out PersistedMask))
                    {
                        network.SubnetMask = PersistedMask;
                    }
                    else
                    {
                        network.SubnetMask = IPAddress.None;
                    }
                    break;
                }
            }
        }