Ejemplo n.º 1
0
 /// <summary>
 /// \brief Create a new instance of CallConnection.
 ///
 /// When the instance is created, the database will be updated accordingly.
 /// </summary>
 /// <param name="_client1">An object of the ClientMessageSocket class.</param>
 /// <param name="_client2">An object of the ClientMessageSocket class.</param>
 public CallConnection(ClientMessageSocket _client1, ClientMessageSocket _client2)
 {
     client1           = _client1;
     client2           = _client2;
     client1.isCalling = true;
     client2.isCalling = true;
     SendStartMessages();
     SetThreads();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Remove a ClientMessageSocket from the pendingRandomCallConnections list.
 /// </summary>
 /// <param name="client">The ClientMessageSocket to remove</param>
 public static void RemovePendingRandomCallConnection(ClientMessageSocket client)
 {
     // Ensure that the client is in the pendingRandomCallConnections list.
     if (pendingRandomCallConnections.Contains(client))
     {
         pendingRandomCallConnections.Remove(client);
         mainWindow.SetNumberOfPendingCalls(pendingRandomCallConnections.Count());
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add a ClientMessageSocket instance that has send a random connection request to the pendingRandomCallConnections.
 /// The instance will only be added if it does not exist in the pendingRandomCallConnections list.
 /// </summary>
 /// <param name="client">A ClientMessageSocket instance</param>
 public static void AddPendingRandomCallClient(ClientMessageSocket client)
 {
     // Only add if the pendingRandomCallConnections does not contain the client already.
     if (!pendingRandomCallConnections.Contains(client))
     {
         pendingRandomCallConnections.Add(client);
         // Update the MainWindow.
         mainWindow.SetNumberOfPendingCalls(pendingRandomCallConnections.Count());
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Get a pending ClientMessageSocket instance that has requested a random call connection.
 /// If the pendingRandomCallConnections list is empty, null is returned.
 /// When a ClientMessageSocket instance is found, it is removed from the pendingRandomCallConnections list.
 /// </summary>
 /// <returns>A ClientMessageSocket instance or null</returns>
 public static ClientMessageSocket GetRandomPendingConnection()
 {
     if (pendingRandomCallConnections.Any())
     {
         // Get the first pending ClientMessageSocket instance in the list.
         ClientMessageSocket clientMessageSocket = pendingRandomCallConnections.First();
         // Remove the ClientMessageSocket instance from pendingRandomCallConnections.
         RemovePendingRandomCallConnection(clientMessageSocket);
         // Update the MainWindow.
         mainWindow.SetNumberOfPendingCalls(pendingRandomCallConnections.Count());
         return(clientMessageSocket);
     }
     else
     {
         // If the pendingRandomCallConnections list is empty, return null.
         return(null);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Removes a ClientMessageSocket instance from the connectedSockets list.
 /// If the ClientMessageSocket instance is used in a CallConnection instance, this instance is removed too.
 /// The mainWindow is also updated.
 /// </summary>
 /// <param name="client">The ClientMessageSocket instance to remove.</param>
 public static void RemoveClientFromConnectedSockets(ClientMessageSocket client)
 {
     if (connectedSockets.Contains(client))
     {
         // Close the connection
         client.GetInnerClient().Close();
         // Remove the ClientMessageSocket instance from connectedSockets.
         connectedSockets.Remove(client);
         // Find a CallConnection with the client.
         var callConnection = GetCallConnectionWithCient(client);
         // If a CallConnection is found, remove the CallConnection.
         if (callConnection != null)
         {
             RemoveCallConnection(callConnection);
         }
         // Update MainWindow.
         mainWindow.SetNumberOfConnectedClients(connectedSockets.Count());
         // Remove the client from the pendingRandomCallConnections list.
         RemovePendingRandomCallConnection(client);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Find a CallConnection instance that uses the given client.
 /// If it does not exist, null will be return.
 /// </summary>
 /// <param name="client">The ClientMessageSocket instance to find.</param>
 /// <returns>The CallConnection instance or null.</returns>
 private static CallConnection GetCallConnectionWithCient(ClientMessageSocket client)
 {
     return(callConnections.Where(x => x.GetClient1().Equals(client) || x.GetClient2().Equals(client)).FirstOrDefault());
 }