private bool ConnectAndStartMonitoring() { DEBUGLogger.WriteThreadInfo("ConnectAndStartMonitoring"); // TODO: PARSE/CHECK these values: string ipAddress = tbIpAddress.Text.Trim(); string password = tbPassword.Text.Trim(); int connectionTimeoutMs = int.Parse(tbConnTimeout.Text.Trim()); _rawDevLinkQueue = new ConcurrentQueue <DevLinkWrapper.DevLinkMessage>(); int iPOID = 21; try { AddLog("Connecting to " + ipAddress + "..."); _devLinkWrapper = new DevLinkWrapper(_rawDevLinkQueue, ipAddress, password, iPOID, connectionTimeoutMs); AddLog("Connection successful!"); /* * // Here we're blocking till the method returns. Should not take much longer than the connectionTimeoutMs. * // TODO: maybe Start monitoring automatically? Or pass the queue there? * /// _isConnected = _devLinkWrapper.StartMonitoring(); * * if (_isConnected) * { * SubscribeToDevLinksEvent(true); * * StartStopButtonPressed(); * * Thread dlThread = new Thread(ReceiveDevLinks); * dlThread.Start(); * * return true; * } * return false;*/ } catch { return(false); } }
/// <summary> /// Handling the DevLinkReceived event. NOTE: This will be executed in Avaya DevLink's Thread! /// It MUST be very light-weight and NOT throw exceptions! /// TODO:LATER: if this doesn't work well, try using ConcurrentQueue /// </summary> /// <param name="devLinkWrapper"></param> /// <param name="e"></param> private void devLinkWrapper_DevLinkRecieved(object sender, DevLinkEventArgs e) { // It is sliiightly possible for us to have un-subscribed juust before the event fires. // In this case (because of the way the event is fired to make it thread-safe) this would still get called, so make sure we don't execute it: if (_subscribedToDevLinksEvent == false) { AddLog("devLinkWrapper_DevLinkRecieved - we've already unsubscribed! Ignoring..."); return; } DEBUGLogger.WriteThreadInfo("devLinkWrapper_DevLinkRecieved EH"); DevLinkWrapper dlWrapper = (DevLinkWrapper)sender; // TODO: THINK ABOUT: // - backing up the data if connection is lost -- in the Collection?? AddLog(e.SiteId + " ||| " + e.RawDevLink + " ### " + dlWrapper.IpAddress + " ### " + DateTime.Now); }