/// <summary> /// Add new session as an ad-oc (dynamic) operation /// </summary> /// <param name="sessionID">ID of new session<param> /// <param name="dict">config settings for new session</param></param> /// <returns>true if session added successfully, false if session already exists or is not an acceptor</returns> public bool AddSession(SessionID sessionID, Dictionary dict) { lock (GdaxPrototyping.Common.Core.Threading.TThreadingHelpers.MainLockable) if (!settings_.Has(sessionID)) // session won't be in settings if ad-hoc creation after startup { settings_.Set(sessionID, dict); // need to to this here to merge in default config settings } else { return(false); } // session already exists if (CreateSession(sessionID, dict)) { return(true); } lock (GdaxPrototyping.Common.Core.Threading.TThreadingHelpers.MainLockable) // failed to create session, so remove from settings settings_.Remove(sessionID); return(false); }
/// <summary> /// Add new session as an ad-hoc (dynamic) operation /// </summary> /// <param name="sessionID">ID of new session</param> /// <param name="dict">config settings for new session</param> /// <returns>true if session added successfully, false if session already exists or is not an initiator</returns> public bool AddSession(SessionID sessionID, Dictionary dict) { lock (_settings) if (!_settings.Has(sessionID)) // session won't be in settings if ad-hoc creation after startup { _settings.Set(sessionID, dict); // need to to this here to merge in default config settings } else { return(false); } // session already exists if (CreateSession(sessionID, dict)) { return(true); } lock (_settings) // failed to create new session _settings.Remove(sessionID); return(false); }
/// <summary> /// Ad-hoc removal of an existing session /// </summary> /// <param name="sessionID">ID of session to be removed</param> /// <param name="terminateActiveSession">if true, force disconnection and removal of session even if it has an active connection</param> /// <returns>true if session removed or not already present; false if could not be removed due to an active connection</returns> public bool RemoveSession(SessionID sessionID, bool terminateActiveSession) { Session session = null; bool disconnectRequired = false; lock (sync_) { if (sessionIDs_.Contains(sessionID)) { session = sessions_[sessionID]; if (session.IsLoggedOn && !terminateActiveSession) { return(false); } sessions_.Remove(sessionID); _settings.Remove(sessionID); disconnectRequired = IsConnected(sessionID) || IsPending(sessionID); if (disconnectRequired) { SetDisconnected(sessionID); } disconnected_.Remove(sessionID); sessionIDs_.Remove(sessionID); OnRemove(sessionID); } } if (disconnectRequired) { session.Disconnect("Dynamic session removal"); } if (session != null) { session.Dispose(); } return(true); }