public async Task <bool> ProcessReconnect()
        {
            if (Authenticated)
            {
                var authResult = await socketClient.AuthenticateSocket(this).ConfigureAwait(false);

                if (!authResult.Success)
                {
                    log.Write(LogVerbosity.Info, "Authentication failed on reconnected socket. Disconnecting and reconnecting.");
                    return(false);
                }

                log.Write(LogVerbosity.Debug, "Authentication succeeded on reconnected socket.");
            }

            List <SocketSubscription> handlerList;

            lock (handlersLock)
                handlerList = handlers.Where(h => h.Request != null).ToList();
            foreach (var handler in handlerList)
            {
                var resubResult = await socketClient.SubscribeAndWait(this, handler.Request, handler).ConfigureAwait(false);

                if (!resubResult.Success)
                {
                    log.Write(LogVerbosity.Debug, "Resubscribing all subscriptions failed on reconnected socket. Disconnecting and reconnecting.");
                    return(false);
                }
            }

            log.Write(LogVerbosity.Debug, "All subscription successfully resubscribed on reconnected socket.");
            return(true);
        }
示例#2
0
        private async Task <bool> ProcessReconnect()
        {
            if (Authenticated)
            {
                var authResult = await socketClient.AuthenticateSocket(this).ConfigureAwait(false);

                if (!authResult.Success)
                {
                    log.Write(LogVerbosity.Info, "Authentication failed on reconnected socket. Disconnecting and reconnecting.");
                    return(false);
                }

                log.Write(LogVerbosity.Debug, "Authentication succeeded on reconnected socket.");
            }

            List <SocketSubscription> handlerList;

            lock (handlersLock)
                handlerList = handlers.Where(h => h.Request != null).ToList();

            var success  = true;
            var taskList = new List <Task>();

            foreach (var handler in handlerList)
            {
                var task = socketClient.SubscribeAndWait(this, handler.Request, handler).ContinueWith(t =>
                {
                    if (!t.Result.Success)
                    {
                        success = false;
                    }
                });
                taskList.Add(task);
            }

            Task.WaitAll(taskList.ToArray());
            if (!success)
            {
                log.Write(LogVerbosity.Debug, "Resubscribing all subscriptions failed on reconnected socket. Disconnecting and reconnecting.");
                return(false);
            }

            log.Write(LogVerbosity.Debug, "All subscription successfully resubscribed on reconnected socket.");
            return(true);
        }