Exemplo n.º 1
0
        public static async Task ConnectPersonToChatHub()
        {
            if (Persona != null)
            {
                ChatsServices chatService = new ChatsServices();

                for (int i = 0; i < 3; i++)
                {
                    if (CrossConnectivity.Current.IsConnected && await CrossConnectivity.Current.IsRemoteReachable(URL.Host, msTimeout: 1000))
                    {
                        try
                        {
                            await chatService.ConectarChatHub(Persona.Consecutivo);

                            if (!string.IsNullOrWhiteSpace(ConnectionIDChatHub))
                            {
                                DisposeChatEvents();
                                ChatsServices.ErrorConexion   += ChatsServices_ErrorConexion;
                                ChatsServices.ConexionPerdida += ChatsServices_ConexionPerdida;
                                break;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static async Task ReconectarChatHub()
        {
            if (string.IsNullOrWhiteSpace(ConnectionIDChatHub) && Persona != null && _appInicializada && !_reconectando)
            {
                try
                {
                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
                    using (await _lockeable.LockAsync(cancellationTokenSource.Token))
                    {
                        await Task.Run(async() =>
                        {
                            _reconectando = true;

                            ChatsServices chatService = new ChatsServices();
                            while (string.IsNullOrWhiteSpace(ConnectionIDChatHub))
                            {
                                if (await CrossConnectivity.Current.IsRemoteReachable(URL.Host, msTimeout: 1000))
                                {
                                    try
                                    {
                                        await chatService.ConectarChatHub(Persona.Consecutivo);

                                        if (!string.IsNullOrWhiteSpace(ConnectionIDChatHub))
                                        {
                                            _reconectando = false;
                                            break;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }

                                await Task.Delay(3000);
                            }
                        });
                    }
                }
                catch (Exception)
                {
                }
            }
        }