/// <summary> /// Removes the connections of the given conversation owners. /// </summary> /// <param name="conversationOwnerParties">The conversation owners whose connections to remove.</param> /// <returns>The number of connections removed.</returns> protected virtual IList <MessageRouterResult> RemoveConnections(IList <Party> conversationOwnerParties) { IList <MessageRouterResult> messageRouterResults = new List <MessageRouterResult>(); foreach (Party conversationOwnerParty in conversationOwnerParties) { ConnectedParties.TryGetValue(conversationOwnerParty, out Party conversationClientParty); if (ConnectedParties.Remove(conversationOwnerParty)) { if (conversationOwnerParty is PartyWithTimestamps) { (conversationOwnerParty as PartyWithTimestamps).ResetConnectionEstablishedTime(); } if (conversationClientParty is PartyWithTimestamps) { (conversationClientParty as PartyWithTimestamps).ResetConnectionEstablishedTime(); } messageRouterResults.Add(new MessageRouterResult() { Type = MessageRouterResultType.Disconnected, ConversationOwnerParty = conversationOwnerParty, ConversationClientParty = conversationClientParty }); } } return(messageRouterResults); }
public virtual void DeleteAll() { AggregationParties.Clear(); UserParties.Clear(); BotParties.Clear(); PendingRequests.Clear(); ConnectedParties.Clear(); #if DEBUG LastMessageRouterResults.Clear(); #endif }
public virtual MessageRouterResult ConnectAndClearPendingRequest(Party conversationOwnerParty, Party conversationClientParty) { MessageRouterResult result = new MessageRouterResult() { ConversationOwnerParty = conversationOwnerParty, ConversationClientParty = conversationClientParty }; if (conversationOwnerParty != null && conversationClientParty != null) { try { ConnectedParties.Add(conversationOwnerParty, conversationClientParty); PendingRequests.Remove(conversationClientParty); DateTime connectionStartedTime = DateTime.UtcNow; if (conversationClientParty is PartyWithTimestamps) { (conversationClientParty as PartyWithTimestamps).ResetConnectionRequestTime(); (conversationClientParty as PartyWithTimestamps).ConnectionEstablishedTime = connectionStartedTime; } if (conversationOwnerParty is PartyWithTimestamps) { (conversationOwnerParty as PartyWithTimestamps).ConnectionEstablishedTime = connectionStartedTime; } result.Type = MessageRouterResultType.Connected; } catch (ArgumentException e) { result.Type = MessageRouterResultType.Error; result.ErrorMessage = e.Message; System.Diagnostics.Debug.WriteLine($"Failed to connect parties {conversationOwnerParty} and {conversationClientParty}: {e.Message}"); } } else { result.Type = MessageRouterResultType.Error; result.ErrorMessage = "Either the owner or the client is missing"; } return(result); }
public virtual Party GetConnectedCounterpart(Party partyWhoseCounterpartToFind) { Party counterparty = null; if (IsConnected(partyWhoseCounterpartToFind, ConnectionProfile.Client)) { for (int i = 0; i < ConnectedParties.Count; ++i) { if (ConnectedParties.Values.ElementAt(i).Equals(partyWhoseCounterpartToFind)) { counterparty = ConnectedParties.Keys.ElementAt(i); break; } } } else if (IsConnected(partyWhoseCounterpartToFind, ConnectionProfile.Owner)) { ConnectedParties.TryGetValue(partyWhoseCounterpartToFind, out counterparty); } return(counterparty); }