예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AmendNetworkButton_Click(object sender, EventArgs e)
        {
            if (this.NetworksListView.SelectedItems.Count == 1)
            {
                ListViewItem SelectedItem = this.NetworksListView.SelectedItems[0];

                WolHostNetwork SelectedNetwork = SelectedItem.Tag as WolHostNetwork;
                WolHostNetwork ClonedNetwork   = SelectedNetwork.Clone();

                if (SelectedNetwork != null)
                {
                    using (AmendNetwork AmendNetworkForm = new AmendNetwork(ActionMode.Amend, ClonedNetwork))
                    {
                        if (AmendNetworkForm.ShowDialog() == DialogResult.OK)
                        {
                            SelectedItem.SubItems[0].Text = ClonedNetwork.Name;
                            SelectedItem.SubItems[1].Text = ClonedNetwork.Address;

                            SelectedItem.Tag = ClonedNetwork;

                            this.NetworksListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Creates and initialises a new instance of the AmendNetwork form.
        /// </summary>
        /// <param name="action">The <see cref="ActionMode">amendment mode</see> in which the form will be operating.</param>
        /// <param name="network">The data object representing the network to be amended.</param>
        public AmendNetwork(ActionMode action, WolHostNetwork network)
        {
            InitializeComponent();

            _action  = action;
            _network = network;

            InitialiseUI();
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNetworkButton_Click(object sender, EventArgs e)
        {
            WolHostNetwork NewNetwork = new WolHostNetwork();

            using (AmendNetwork AddNetworkForm = new AmendNetwork(ActionMode.Add, NewNetwork))
            {
                if (AddNetworkForm.ShowDialog() == DialogResult.OK)
                {
                    ListViewItem NewListItem = new ListViewItem(new string[] {
                        NewNetwork.Name,
                        NewNetwork.Address
                    });

                    NewListItem.Tag = NewNetwork;

                    this.NetworksListView.Items.Add(NewListItem);
                    this.NetworksListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                }
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetDefaultButton_Click(object sender, EventArgs e)
        {
            if (this.NetworksListView.SelectedItems.Count == 1)
            {
                for (int i = 0; i < this.NetworksListView.Items.Count; i++)
                {
                    if (i == this.NetworksListView.SelectedItems[0].Index)
                    {
                        WolHostNetwork SelectedNetwork = this.NetworksListView.SelectedItems[0].Tag as WolHostNetwork;
                        _host.DefaultNetwork = SelectedNetwork.NetworkId;

                        this.NetworksListView.Items[i].Font = new Font(this.NetworksListView.Font, FontStyle.Bold);
                    }
                    else
                    {
                        this.NetworksListView.Items[i].Font = this.NetworksListView.Font;
                    }
                }

                this.NetworksListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
        }
예제 #5
0
        /// <summary>
        /// Wakes a host, handling any required SecureOn password prompting.
        /// </summary>
        /// <param name="hostToWake">The WolHost object describing the host to wake.</param>
        /// <param name="networkToWake"></param>
        private void WakeHost(WolHost hostToWake, Guid networkId)
        {
            if (hostToWake != null)
            {
                // Retrieve the network details for waking the host.
                WolHostNetwork Network = hostToWake.Networks[networkId];
                if (Network == null)
                {
                    throw new InvalidOperationException("Host cannot be woken as no suitable network has been defined.");
                }

                IPEndPoint HostEndpoint = null;

                if (Network.Locality == WolHostNetwork.NetworkLocality.Remote)
                {
                    try
                    {
                        IPAddress[] ResolvedAddresses = Dns.GetHostAddresses(Network.Address);
                        if (ResolvedAddresses != null && ResolvedAddresses.Length > 0)
                        {
                            HostEndpoint = new IPEndPoint(ResolvedAddresses[0], Network.Port);
                        }
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        HostEndpoint = null;
                    }

                    // Check that a valid endpoint has been prepared. A remote host is not valid for awakening
                    // if the endpoint is not valid by this point - falling back to local would not be any use.
                    if (HostEndpoint == null)
                    {
                        // TODO: Tidy this scenario
                        throw new InvalidOperationException("Invalid host address for remote host.");
                    }
                }

                if (hostToWake.RequireSecureOn == false)
                {
                    if (Network.Locality == WolHostNetwork.NetworkLocality.Remote)
                    {
                        WakeOnLan.WakeMachine(hostToWake.MachineAddress,
                                              HostEndpoint,
                                              Network.SubnetMask);
                    }
                    else
                    {
                        WakeOnLan.WakeMachine(hostToWake.MachineAddress);
                    }
                }
                else
                {
                    // Check to see whether the SecureOn Password needs to be prompted.
                    if (hostToWake.SecureOnPassword == null || hostToWake.SecureOnPassword == PhysicalAddress.None)
                    {
                        using (SecureOnPromptForm SecureOnPrompt = new SecureOnPromptForm(hostToWake))
                        {
                            if (SecureOnPrompt.ShowDialog() == DialogResult.OK)
                            {
                                // Use the supplied SecureOn Password.
                                if (Network.Locality == WolHostNetwork.NetworkLocality.Remote)
                                {
                                    WakeOnLan.WakeMachine(hostToWake.MachineAddress,
                                                          SecureOnPrompt.SecureOnPassword,
                                                          HostEndpoint,
                                                          Network.SubnetMask);
                                }
                                else
                                {
                                    WakeOnLan.WakeMachine(hostToWake.MachineAddress, SecureOnPrompt.SecureOnPassword);
                                }
                            }
                        }
                    }
                    else
                    {
                        // Use the stored SecureOn Password.
                        if (Network.Locality == WolHostNetwork.NetworkLocality.Remote)
                        {
                            WakeOnLan.WakeMachine(hostToWake.MachineAddress,
                                                  hostToWake.SecureOnPassword,
                                                  HostEndpoint,
                                                  Network.SubnetMask);
                        }
                        else
                        {
                            WakeOnLan.WakeMachine(hostToWake.MachineAddress, hostToWake.SecureOnPassword);
                        }
                    }
                }
            }
        }