public void ConnectMessageListener() { if (IsMessageListenerStarted || Disconnecting) { return; } try { lock (lockObject) { messageCacheControl = new CacheControlClass { UserID = userId, Password = password }; messageCacheControl.CacheEvent += MessageCacheEventHandler; object errorCode = null; var submittedAt = DateTime.Now; // assume everything will be fine - the submit does not return until we have // processed all the events, so it is easier to assume success IsMessageListenerStarted = true; var submitResult = messageCacheControl.Submit("Message", "true", ref errorCode); OnStatusChanged(EventArgs.Empty); log.Info( "Submitted Message Listener at " + submittedAt + ", submitResult=" + submitResult + ", errorCode=" + errorCode); } } catch (Exception e) { IsMessageListenerStarted = false; log.Error("Failed to connect message listener to Redi", e); } }
/// <summary> /// Connect to the postion table. /// /// Check at logical step to see if we have been requested to shutdown. /// </summary> public void ConnectPositionListener() { if (IsPositionListenerStarted || Disconnecting) { return; } try { lock (lockObject) { Connecting = true; positionCacheControl = new CacheControlClass { UserID = userId, Password = password }; positionCacheControl.CacheEvent += PositionCacheEventHandler; object submitErrorCode = null; var accountList = GetRediAccounts(); var submittedAt = DateTime.Now; var submitResult = positionCacheControl.Submit("Position", "true", ref submitErrorCode); foreach (var account in accountList) { object watchErrorCode = null; var watchResult = positionCacheControl.AddWatch(2, "", account, ref watchErrorCode); watchedAccounts.Add(account); log.Info("Watching account: " + account + ", result=" + watchResult + ", errorCode=" + watchErrorCode); if (Disconnecting) { break; } } IsPositionListenerStarted = true; Connecting = false; Connected = true; OnStatusChanged(EventArgs.Empty); log.Info( "Submitted Position Listener at " + submittedAt + ", submitResult=" + submitResult + ", errorCode=" + submitErrorCode); } } catch (Exception e) { IsPositionListenerStarted = false; log.Error("Failed to connect position listener to Redi", e); } }