コード例 #1
0
 /// <summary>
 /// Creates a new network address event arguments instance.
 /// </summary>
 /// <param name="information">The address information.</param>
 public UnicastNetworkAddressEventArgs(UnicastNetworkAddressInformation information)
 {
     this.Information = information;
 }
コード例 #2
0
        /// <summary>
        /// Updates the network information.
        /// </summary>
        private static void OnUpdate()
        {
            lock (NetworkConfiguration.sync)
            {
                // Set the information for all addresses to stale.
                NetworkConfiguration.unicastInformation.ForEach(info => info.Stale = true);

                // For all network interfaces.
                foreach (NetworkInterface iface in NetworkInterface.GetAllNetworkInterfaces())
                {
                    // Get the IP properties.
                    IPInterfaceProperties ipProperties = iface.GetIPProperties();

                    // For all unicast IP addresses.
                    foreach (UnicastIPAddressInformation info in ipProperties.UnicastAddresses)
                    {
                        // Find the corresponding address information.
                        UnicastNetworkAddressInformation information = NetworkConfiguration.unicastInformation.FirstOrDefault(inf => inf.Information.Address == info.Address);

                        // If there exists an address information.
                        if (null != information)
                        {
                            // If the information has changed.
                            if (information.Interface != iface || information.UnicastInformation != info)
                            {
                                // Update the information.
                                information.Interface = iface;
                                information.UnicastInformation = info;
                            }

                            // Set the information as not stale.
                            information.Stale = false;
                        }
                        else
                        {
                            // Create a new address information.
                            information = new UnicastNetworkAddressInformation(iface, info);

                            // Add the address information to the list.
                            NetworkConfiguration.unicastInformation.Add(information);
                        }
                    }
                }

                // Remove the stale address information records.
                NetworkConfiguration.unicastInformation.RemoveAll(info => info.Stale);

                // Order the address information records.
                NetworkConfiguration.unicastInformation.OrderBy(info => info.Information.Address);
            }
        }