コード例 #1
0
 /// <summary>
 /// Reconnects a given client.
 /// </summary>
 /// <param name="client">The client, for which a reconnect should get performed.</param>
 /// <returns></returns>
 private async Task ReconnectClientAsync(ClientConnectionHandler client)
 {
     if (client.IsDisabled())
     {
         // Only disconnect if the client is disabled:
         await client.DisconnectAsync();
     }
     else
     {
         await client.ReconnectAsync();
     }
 }
コード例 #2
0
        //--------------------------------------------------------Events:---------------------------------------------------------------------\\
        #region --Events--
        private async void INSTANCE_AccountChanged(AccountDBManager handler, AccountChangedEventArgs args)
        {
            await CLIENT_SEMA.WaitAsync();

            for (int i = 0; i < CLIENTS.Count; i++)
            {
                if (Equals(CLIENTS[i].GetBareJid(), args.ACCOUNT.getBareJid()))
                {
                    // Disconnect first:
                    CLIENTS[i].DisconnectAsync().Wait();

                    if (args.REMOVED)
                    {
                        CLIENTS[i].ClientConnected -= OnClientConnected;
                        CLIENTS.RemoveAt(i);
                    }
                    else
                    {
                        CLIENTS[i].SetAccount(args.ACCOUNT);
                        if (!CLIENTS[i].IsDisabled())
                        {
                            await CLIENTS[i].ConnectAsync();
                        }
                    }
                    CLIENT_SEMA.Release();
                    return;
                }
            }

            // Account got added:
            if (!args.REMOVED)
            {
                ClientConnectionHandler client = new ClientConnectionHandler(args.ACCOUNT);
                if (!client.IsDisabled())
                {
                    client.ConnectAsync().Wait();
                }
                CLIENTS.Add(client);
            }
            CLIENT_SEMA.Release();
        }