예제 #1
0
        /// <summary>
        /// Connects (associates) to the specified wireless network, returning either on a success to connect
        /// or a failure.
        /// </summary>
        /// <param name="connectionMode"></param>
        /// <param name="bssType"></param>
        /// <param name="profile"></param>
        /// <param name="connectTimeout"></param>
        /// <returns></returns>
        public bool ConnectSynchronously(WlanConnectionMode connectionMode, Dot11BssType bssType, string profile, int connectTimeout)
        {
            queueEvents = true;             // NOTE: This can cause side effects, other places in the application might not get events properly.
            Stopwatch sw = new Stopwatch();

            try
            {
                Connect(connectionMode, bssType, profile);

                sw.Start();
                while (queueEvents && eventQueueFilled.WaitOne(connectTimeout, true))
                {
                    lock (eventQueue)
                    {
                        while (eventQueue.Count != 0)
                        {
                            if (sw.ElapsedMilliseconds > connectTimeout)
                            {
                                throw new Exception("Timeout");
                            }
                            object e = eventQueue.Dequeue();
                            if (e is WlanConnectionNotificationEventData)
                            {
                                WlanConnectionNotificationEventData wlanConnectionData = (WlanConnectionNotificationEventData)e;
                                // Check if the conditions are good to indicate either success or failure.
                                if (wlanConnectionData.notifyData.notificationSource == WlanNotificationSource.MSM)
                                {
                                    switch ((WlanNotificationCodeMsm)wlanConnectionData.notifyData.notificationCode)
                                    {
                                    case WlanNotificationCodeMsm.Connected:
                                        if (wlanConnectionData.connNotifyData.profileName == profile)
                                        {
                                            return(true);
                                        }
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
            finally
            {
                sw.Stop();
                queueEvents = false;
                eventQueue.Clear();
            }
            return(false);            // timeout expired and no "connection complete"
        }
예제 #2
0
        internal void OnWlanConnection(WlanNotificationData notifyData, WlanConnectionNotificationData connNotifyData)
        {
            WlanConnectionNotification?.Invoke(notifyData, connNotifyData);

            if (queueEvents)
            {
                var queuedEvent = new WlanConnectionNotificationEventData
                {
                    notifyData     = notifyData,
                    connNotifyData = connNotifyData
                };
                EnqueueEvent(queuedEvent);
            }
        }
예제 #3
0
        internal void OnWlanConnection(WlanNotificationData notifyData, WlanConnectionNotificationData connNotifyData)
        {
            WlanConnectionNotification?.Invoke(notifyData, connNotifyData);

            if (!_queueEvents)
            {
                return;
            }
            WlanConnectionNotificationEventData queuedEvent = new WlanConnectionNotificationEventData();

            queuedEvent.NotifyData     = notifyData;
            queuedEvent.ConnNotifyData = connNotifyData;
            EnqueueEvent(queuedEvent);
        }
예제 #4
0
        internal void OnWlanConnection(WlanNotificationData notifyData, WlanConnectionNotificationData connNotifyData)
        {
            if (WlanConnectionNotification != null)
            {
                WlanConnectionNotification(notifyData, connNotifyData);
            }

            if (queueEvents)
            {
                WlanConnectionNotificationEventData queuedEvent = new WlanConnectionNotificationEventData();
                queuedEvent.notifyData     = notifyData;
                queuedEvent.connNotifyData = connNotifyData;
                EnqueueEvent(queuedEvent);
            }
        }
예제 #5
0
 /// <summary>
 /// Connects (associates) to the specified wireless network, returning either on a success to connect
 /// or a failure.
 /// </summary>
 /// <param name="connectionMode"></param>
 /// <param name="bssType"></param>
 /// <param name="profile"></param>
 /// <param name="connectTimeout"></param>
 /// <returns></returns>
 public bool ConnectSynchronously(WlanConnectionMode connectionMode, Dot11BssType bssType, string profile, int connectTimeout)
 {
     _queueEvents = true;             // NOTE: This can cause side effects, other places in the application might not get events properly.
     try
     {
         Connect(connectionMode, bssType, profile);
         while (_queueEvents && _eventQueueFilled.WaitOne(connectTimeout, true))
         {
             lock (_eventQueue)
             {
                 while (_eventQueue.Count != 0)
                 {
                     object e = _eventQueue.Dequeue();
                     if (!(e is WlanConnectionNotificationEventData))
                     {
                         continue;
                     }
                     WlanConnectionNotificationEventData wlanConnectionData = (WlanConnectionNotificationEventData)e;
                     // Check if the conditions are good to indicate either success or failure.
                     if (wlanConnectionData.NotifyData.notificationSource == WlanNotificationSource.MSM)
                     {
                         switch ((WlanNotificationCodeMsm)wlanConnectionData.NotifyData.notificationCode)
                         {
                         case WlanNotificationCodeMsm.Connected:
                             if (wlanConnectionData.ConnNotifyData.profileName == profile)
                             {
                                 return(true);
                             }
                             break;
                         }
                     }
                     break;
                 }
             }
         }
     }
     finally
     {
         _queueEvents = false;
         lock (_eventQueue)
         {
             _eventQueue.Clear();
         }
     }
     return(false);            // timeout expired and no "connection complete"
 }
예제 #6
0
		internal void OnWlanConnection(WlanNotificationData notifyData, WlanConnectionNotificationData connNotifyData)
		{
			if (WlanConnectionNotification != null)
				WlanConnectionNotification(notifyData, connNotifyData);

			if (queueEvents)
			{
				WlanConnectionNotificationEventData queuedEvent = new WlanConnectionNotificationEventData();
				queuedEvent.notifyData = notifyData;
				queuedEvent.connNotifyData = connNotifyData;
				EnqueueEvent(queuedEvent);
			}
		}