Exemplo n.º 1
0
        public NetInterfaceModel(NetworkAdapter netAdptr, NetworkInterface netIface = null, bool createFullObject = true)
        {
            this.originalNetworkAdapter = netAdptr;

            CreateFromNetworkAdapter(netAdptr, netIface);

            statusCheckThread = new Thread(CheckStatusThread);

            if (createFullObject)
            {
                LoadProfiles();
                StartEventWatchers();
            }
        }
Exemplo n.º 2
0
        private void CreateFromNetworkAdapter(NetworkAdapter netAdapter, NetworkInterface netIface = null)
        {
            this.networkAdapter = netAdapter;
            this.networkInterface = null;

            if (netIface != null)
                this.networkInterface = netIface;
            else
            {
                IDictionary<string, NetworkInterface> ifaceDict = NetworkInterface.GetAllNetworkInterfaces().ToDictionary(i => i.Name);

                NetworkInterface value;
                if (ifaceDict.TryGetValue(networkAdapter.NetConnectionID, out value))
                    this.networkInterface = value;

            }

            if (this.networkInterface == null)
                this.type = NetInterfaceType.Unknown;
            else
            {
                switch (this.networkInterface.NetworkInterfaceType)
                {
                    case NetworkInterfaceType.Wireless80211:
                        this.type = NetInterfaceType.Wireless;
                        break;
                    case NetworkInterfaceType.Ethernet:
                        this.type = NetInterfaceType.Wired;
                        break;
                    default:
                        this.type = NetInterfaceType.Other;
                        break;
                }
            }

            this.netshId = (int)networkAdapter.InterfaceIndex;
            ReloadAdapterConfiguration();
        }
Exemplo n.º 3
0
        private void WmiAdapterEventHandler(object sender, EventArrivedEventArgs e)
        {
            ManagementBaseObject targetInstance = (ManagementBaseObject)e.NewEvent["TargetInstance"];
            ManagementBaseObject previousInstance = (ManagementBaseObject)e.NewEvent["PreviousInstance"];

            NetworkAdapter targetAdapter = new NetworkAdapter(targetInstance);
            NetworkAdapter previousAdapter = new NetworkAdapter(previousInstance);

            NetInterfaceModel oldInterface = new NetInterfaceModel(previousAdapter, null, false);
            //CreateFromNetworkAdapter(targetAdapter);
            this.networkAdapter = targetAdapter;

            if (oldInterface.IsConnected != this.IsConnected)
            {
                if (this.IsConnected)
                {
                    if (Connected != null) Connected();
                }
                else
                {
                    if (Disconnected != null) Disconnected();
                }
            }

            if (oldInterface.IsEnabled != this.IsEnabled)
            {
                if (this.IsEnabled)
                {
                    if (InterfaceUp != null) InterfaceUp();
                }
                else
                {
                    if (InterfaceDown != null) InterfaceDown();
                }
            }

            Console.WriteLine("WmiAdapterEventHandler");
        }
Exemplo n.º 4
0
 private void CreateFromNetworkAdapter(NetworkAdapter netAdapter)
 {
     this.networkAdapter = netAdapter;
     this.networkInterface = null;
 }