protected async Task SendPendingMessages()
        {
            ChadderMessage msg = null;

            try
            {
                var backoff = new ExponentialBackoff(1000, 5000);
                while (PendingMessages.Count > 0)
                {
                    if (PendingMessages.TryPeek(out msg) && msg.Status != ChadderMessage.MESSAGE_STATUS.SENT)
                    {
                        var conversation = db.GetConversation(msg.ConversationId);
                        if (await SendMessageToServer(msg, conversation) == ChadderError.OK)
                        {
                            while (PendingMessages.TryDequeue(out msg))
                            {
                                ;
                            }
                            backoff.Reset();
                        }
                        else
                        {
                            await backoff.Failed();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Insight.Track("SendPendingMessages safe try-catch");
                Insight.Report(ex);
            }
            SendPendingMessagesTask = null;
        }
Exemplo n.º 2
0
        protected async Task FinishLoading()
        {
            try
            {
                var timer   = Insight.StartTimer("FinishLoading");
                var backoff = new ExponentialBackoff(1000, 5000);
                while (await CreateToken() != ChadderError.OK)
                {
                    await backoff.Failed();
                }
                backoff.Reset();
                await Connection.Connect();

                while (await GetPackages() != ChadderError.OK)
                {
                    await backoff.Failed();
                }
                backoff.Reset();

                while (await GetMyDevices() != ChadderError.OK)
                {
                    await backoff.Failed();
                }
                backoff.Reset();

                while (await UpdateContacts() != ChadderError.OK)
                {
                    await backoff.Failed();
                }
                Insight.StopTimer(timer);
                backoff.Reset();
                while (await GetMyInfo() != ChadderError.OK)
                {
                    await backoff.Failed();
                }

                StartSendPendingMessages();
            }
            catch (Exception ex)
            {
                Insight.Report(ex);
            }
        }