Пример #1
0
 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
 {
     if (_networkListManager.IsConnectedToInternet)
     {
         // do something based on internet connection
     }
 }
 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
 {
     this.Connectivity = DateTime.Now.ToLongTimeString();
     if ((newConnectivity & NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) != NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
     {
     }
 }
Пример #3
0
 private void OnNetworkConnectivityChanged(Guid guid, NLM_CONNECTIVITY connectivity)
 {
     NetworkConnectivityChangedEventArgs e = new NetworkConnectivityChangedEventArgs()
     {
         IsAvailable = _networkListManager.IsConnectedToInternet,
         ConnectionStatus = GetInternetStatus()
     };
     NetworkConnectivityChanged?.Invoke(new object(), e);
 }
Пример #4
0
        private string GetConnectivity(NLM_CONNECTIVITY newConnectivity)
        {
            //Console.WriteLine("");
            //Console.WriteLine("-------------------------------------------" +
            //                  "--------------------------------");
            //Log("NetworkList just informed the connectivity change." +
            //                  " The new connectivity is:");

            string connectivity = "";

            if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
            {
                connectivity = "disconnected";
            }
            if (((int)newConnectivity &
                 (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) != 0)
            {
                connectivity = "connected to internet with IPv4 capability";
            }
            if (((int)newConnectivity &
                 (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV6_INTERNET) != 0)
            {
                connectivity = "connected to internet with IPv6 capability";
            }
            if (((int)newConnectivity &
                 (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_LOCALNETWORK) != 0)
            {
                if (!string.IsNullOrEmpty(connectivity))
                {
                    connectivity = connectivity + " and connected to local network";
                }
                else
                {
                    connectivity = "connected to local network";
                }
            }
            //if ((((int)newConnectivity &
            //      (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) == 0) &&
            //      (((int)newConnectivity &
            //      (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV6_INTERNET) == 0))
            //{
            //    Log("The machine is not connected to internet yet ");
            //}
            return(connectivity);
        }
 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
 {
     if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
     {
         SetText("Đã ngắt kết nối internet!", Color.White, Color.Red);
     }
     if (((int)newConnectivity & (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) != 0)
     {
         SetText("Đang kết nối thành công Internet với IPv4!", Color.White, Color.Green);
     }
     if (((int)newConnectivity & (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV6_INTERNET) != 0)
     {
         SetText("Đang kết nối thành công Internet với IPv6!", Color.White, Color.Green);
     }
     if ((((int)newConnectivity & (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) == 0) &&
         (((int)newConnectivity & (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV6_INTERNET) == 0))
     {
         SetText("Mất kết nối Internet!", Color.White, Color.Red);
     }
 }
Пример #6
0
        public void NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
        {
            // Event is only important in this case when the Network has changed and it is connected.
            if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED) { return; }
            if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_NOTRAFFIC) { return; }

            if (((int)newConnectivity & (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) == 0) { return; }

            try
            {
                var newNetworkName = _networkListManager.GetNetwork(networkId).GetName();
                if (_networkChangedCall != null && !string.IsNullOrEmpty(newNetworkName))
                {
                    _networkChangedCall(newNetworkName);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
Пример #7
0
 public void NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
 {
     var handler = ConnectivityChanged;
     handler?.Invoke(this, new NetworkEventConnectivityArgs(networkId, newConnectivity));
 }
Пример #8
0
 public void NetworkConnectionConnectivityChanged(Guid connectionId, NLM_CONNECTIVITY newConnectivity)
 {
     // Don't care.
 }
Пример #9
0
 public void NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
 {
     ConnectionStateChanged?.Invoke();
 }
Пример #10
0
 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
 {
     ConnectionStateChanged?.Invoke();
 }
Пример #11
0
        //private static bool _isNetworkChangeInProgress = false;
        private async void NetworkListManager_NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
        {
            //if (_isNetworkChangeInProgress) return;
            //_isNetworkChangeInProgress = true;

            _log.Log("**Network Connectivity Changed**");

            if (!DisableDisconnect &&
                newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
            {
                if (_disconnectTask != null) return;

                _log.Log("**Disconnect Triggered**");
                //Task.Factory.

                _disconnectTask = Task.Run(() =>
                {
                    DisableDisconnect = true;
                    //NetworkListManager.NetworkConnectivityChanged -= NetworkListManager_NetworkConnectivityChanged;
                    var adapters = GetActiveNetworkInterfaces();
                    EnableAllNeworkInterfaces(false);

                    ClosePrograms();
                    EnableAllNeworkInterfaces();
                    ResetNetworkInterfaces();
                    //FileIO.ResetTransfers();
                    SystemUtils.AllowSleep();
                    if (this.IsOpenVPNConnected())
                    {
                        DisableDisconnect = true;
                    }
                    if (!DisableRetryConnect)
                    {
                        VPNGate.TryReconnect();
                    }
                }).ContinueWith((t) =>
                {
                    _disconnectTask = null;
                });

            }
            //else if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET)
            //{

            //    if (this.IsOpenVPNConnected())
            //    {
            //        OpenPrograms();
            //    }
            //}
            if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
            {
                //ResetNetworkInterfaces();
            }
            await Task.Delay(20000).ContinueWith((t) =>
            {
                ScanNetworkInterfaces();
                LogNetworkInfo();
                if (IsLocalNetworkConnected())
                {
                    _timerMediaShare.Enabled = true;
                    //FileIO.ProcessFileTransferQueue();
                }
                else
                {
                    //FileIO.ResetTransfers();
                }
               // _isNetworkChangeInProgress = false;
            });

        }
Пример #12
0
        private string GetConnectivity(NLM_CONNECTIVITY newConnectivity)
        {
            //Console.WriteLine("");
            //Console.WriteLine("-------------------------------------------" +
            //                  "--------------------------------");
            //Log("NetworkList just informed the connectivity change." +
            //                  " The new connectivity is:");

            string connectivity = "";

            if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
            {
                connectivity = "disconnected";
            }
            if (((int)newConnectivity &
                 (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) != 0)
            {
                connectivity = "connected to internet with IPv4 capability";
            }
            if (((int)newConnectivity &
                 (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV6_INTERNET) != 0)
            {
                connectivity = "connected to internet with IPv6 capability";
            }
            if (((int)newConnectivity &
              (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_LOCALNETWORK) != 0)
            {
                if (!string.IsNullOrEmpty(connectivity))
                {
                    connectivity = connectivity + " and connected to local network";
                }
                else
                {
                    connectivity = "connected to local network";
                }
            }
            //if ((((int)newConnectivity &
            //      (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) == 0) &&
            //      (((int)newConnectivity &
            //      (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV6_INTERNET) == 0))
            //{
            //    Log("The machine is not connected to internet yet ");
            //}
            return connectivity;
        }
Пример #13
0
 public NetworkEventConnectivityArgs(Guid networkID, NLM_CONNECTIVITY connectivity) : base(networkID)
 {
     Connectivity = connectivity;
 }
Пример #14
0
 void OnNetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
 {
     // Just flag that something has changed. Changes will be enumerated
     // when timer1 ticks.
     netchanged = true;
 }
 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
 {
     //Fire our event
     OnConnectivityChanged(this, newConnectivity);
 }
Пример #16
0
 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
 {
     var i = (int) newConnectivity;
     if (!WsWrapper.WebsiteLive)
     {
         if (newConnectivity != NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
         {
             if ((i & (int) NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) != 0 ||
                 ((int) newConnectivity & (int) NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV6_INTERNET) != 0)
             {
                 if (!WsWrapper.WebsiteLive)
                 {
                     WsWrapper.LastLiveCheck = Helper.Now.AddMinutes(-5);
                 }
             }
         }
     }
 }
Пример #17
0
        //private static bool _isNetworkChangeInProgress = false;
        private async void NetworkListManager_NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
        {
            //if (_isNetworkChangeInProgress) return;
            //_isNetworkChangeInProgress = true;

            _log.Log("**Network Connectivity Changed**");

            if (!DisableDisconnect &&
                newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
            {
                if (_disconnectTask != null)
                {
                    return;
                }

                _log.Log("**Disconnect Triggered**");
                //Task.Factory.

                _disconnectTask = Task.Run(() =>
                {
                    DisableDisconnect = true;
                    //NetworkListManager.NetworkConnectivityChanged -= NetworkListManager_NetworkConnectivityChanged;
                    var adapters = GetActiveNetworkInterfaces();
                    EnableAllNeworkInterfaces(false);

                    ClosePrograms();
                    EnableAllNeworkInterfaces();
                    ResetNetworkInterfaces();
                    //FileIO.ResetTransfers();
                    SystemUtils.AllowSleep();
                    if (this.IsOpenVPNConnected())
                    {
                        DisableDisconnect = true;
                    }
                    if (!DisableRetryConnect)
                    {
                        VPNGate.TryReconnect();
                    }
                }).ContinueWith((t) =>
                {
                    _disconnectTask = null;
                });
            }
            //else if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET)
            //{

            //    if (this.IsOpenVPNConnected())
            //    {
            //        OpenPrograms();
            //    }
            //}
            if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED)
            {
                //ResetNetworkInterfaces();
            }
            await Task.Delay(20000).ContinueWith((t) =>
            {
                ScanNetworkInterfaces();
                LogNetworkInfo();
                if (IsLocalNetworkConnected())
                {
                    _timerMediaShare.Enabled = true;
                    //FileIO.ProcessFileTransferQueue();
                }
                else
                {
                    //FileIO.ResetTransfers();
                }
                // _isNetworkChangeInProgress = false;
            });
        }
Пример #18
0
 public NetworkEventConnectivityArgs(Guid networkID, NLM_CONNECTIVITY connectivity)
     : base(networkID)
 {
     Connectivity = connectivity;
 }
Пример #19
0
        public void NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
        {
            var handler = ConnectivityChanged;

            handler?.Invoke(this, new NetworkEventConnectivityArgs(networkId, newConnectivity));
        }
Пример #20
0
 private void NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
 {
     this.NetworksChanged?.Invoke(this, EventArgs.Empty);
 }
Пример #21
0
 //this method must be implemented
 public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity)
 {
     //Your code goes here
 }
Пример #22
0
 private void _nlm_NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
 {
     ConnectivityChanged?.Invoke(this, IsNetworkAvailable());
 }
Пример #23
0
 private void NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
 {
     this.NetworksChanged?.Invoke(this, EventArgs.Empty);
 }