Ejemplo n.º 1
0
        private void ComManager_SsidTimerHit(object sender, SsidEventArgs e)
        {
            lock (_lockObject)
            {
                //Color oldColor = Color.DarkBlue;
                //this.BeginInvoke((Action)(() => oldColor = tsCurrentNetwork.BackColor));
                if (e.CurrentSsid != null)
                {
                    if (e.CurrentSsid.Contains("PMC"))
                    {
                        this.BeginInvoke((Action)(() => tsCurrentNetwork.BackColor = Color.Green));
                    }
                    else
                    {
                        this.BeginInvoke((Action)(() => tsCurrentNetwork.BackColor = Color.Red));
                    }
                    tsCurrentNetwork.Text = e.CurrentSsid;
                }
                else
                {
                    tsCurrentNetwork.Text = "NOT CONNECTED";
                    this.BeginInvoke((Action)(() => tsCurrentNetwork.BackColor = Color.Red));
                }

                //Console.WriteLine("Old color: " + oldColor + "   Current color: " + tsCurrentNetwork.BackColor);

                //if (oldColor == Color.Green && tsCurrentNetwork.BackColor == Color.Red)
                //{
                //    MessageBox.Show("Connection to PMC-8 network was lost.  Please reconnect.", "Important");
                //}
            }
        }
        //[System.Runtime.InteropServices.DllImport("wininet.dll")]
        //private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
        //public bool IsConnectedToWirelessNetwork()
        //{
        //    int desc;
        //    bool result = InternetGetConnectedState(out desc, 0);
        //    return result;
        //}

        //private WlanClient _wlan = new WlanClient();
        //public string ConnectedSsid()
        //{
        //    Mutex mut = new Mutex();

        //    //WlanClient wlan = null;
        //    Collection<String> connectedSsids = new Collection<string>();
        //    string last = "Not set";
        //    try
        //    {
        //        mut.WaitOne();
        //        //wlan = new WlanClient();
        //        if (_wlan != null)
        //        {
        //            if (_wlan.Interfaces != null)
        //            {

        //                foreach (WlanClient.WlanInterface wlanInterface in _wlan.Interfaces)
        //                {
        //                    Wlan.Dot11Ssid ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid;
        //                    connectedSsids.Add(new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength)));
        //                    last = new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength));
        //                }
        //            }
        //            else
        //            {
        //                last = "Not set";
        //            }
        //        }
        //        else
        //        {
        //            last = "Not set";
        //        }

        //        //wlan = null;
        //    }
        //    catch (Exception)
        //    {
        //        throw new ApplicationException("GetConnectedSsid Failed");
        //    }
        //    finally
        //    { mut.ReleaseMutex(); }

        //    return last;
        //}

        //private bool IsConnectedToPmcNetwork()
        //{
        //    bool result = false;
        //    if (IsConnectedToWirelessNetwork())
        //    {
        //        if (ConnectedSsid().Contains("PMC"))
        //        {
        //            result = true;
        //        }
        //    }
        //    return result;
        //}
        #endregion

        #region Event Methods
        private void SsidTimers_Elapsed(object sender, ElapsedEventArgs e)
        {
            SsidEventArgs ea = new SsidEventArgs();

            ea.CurrentSsid = ConnectedSsid();
            RaiseSsidTimer(ea);
            //ea.CurrentSsid = GetCurrentSsid();
        }
        protected virtual void OnSsidTimerHit(SsidEventArgs e)
        {
            EventHandler <SsidEventArgs> handler = SsidTimerHit;

            if (handler != null)
            {
                handler(this, e);
            }
        }
 public void RaiseSsidTimer(SsidEventArgs e)
 {
     //e.CurrentSsid = GetCurrentSsid();
     OnSsidTimerHit(e);
 }