示例#1
0
 public override long GetPreviousTransactionId(Transaction transaction)
 {
     PreviousAccountTransaction.GetPreviousTransactionId(transaction, out var previousTransactionId);
     return(previousTransactionId);
 }
示例#2
0
        // active polling is meh, should be replace by a simple notification server, but it's ok for now
        async Task PollLoop()
        {
            var profileInfo = (await ProfileManager.Current.GetProfileData(AccountId, ProfileDownloadType.ForceDownload, false)).ProfileInfo;

            if (profileInfo != null)
            {
                ProfileInfo = profileInfo;
            }

            await DownloadInboxRecords(AccountId);
            await QueryMissingProfiles();

            while (true)
            {
                try
                {
                    await DownloadFriends(false);

                    var save = false;
                    var lastAccountTransaction  = (await PreviousAccountTransaction.DownloadLastTransactionInfo(_client, ChainType.Data, ChainId, MessageServiceInfo.MessageDataChainIndex, AccountId))?.Item;
                    var lastReceiverTransaction = (await Receiver.DownloadLastTransactionInfo(_client, ChainType.Data, ChainId, MessageServiceInfo.MessageDataChainIndex, AccountId))?.Item;

                    if (_lastAccountTransaction == null)
                    {
                        _lastAccountTransaction = lastAccountTransaction;
                        save = true;
                    }
                    if (_lastReceivedTransaction == null)
                    {
                        _lastReceivedTransaction = lastReceiverTransaction;
                        save = true;
                    }

                    var result = new PollResult();
                    if (lastAccountTransaction != null)
                    {
                        if (lastAccountTransaction.TransactionId > _lastAccountTransaction.TransactionId)
                        {
                            var download = new AccountTransactionDownload(AccountId, ServiceNode.GetTransactionDownloadManager(MessageServiceInfo.MessageDataChainIndex))
                            {
                                MinimalTransactionId = Math.Max(1, _lastAccountTransaction.TransactionId)
                            };

                            if (await Poll(download, result))
                            {
                                _lastAccountTransaction = lastAccountTransaction;
                                save = true;
                            }
                        }
                    }

                    if (lastReceiverTransaction != null)
                    {
                        if (lastReceiverTransaction.TransactionId > _lastReceivedTransaction.TransactionId)
                        {
                            var download = new ReceiverTransactionDownload(AccountId, ServiceNode.GetTransactionDownloadManager(MessageServiceInfo.MessageDataChainIndex))
                            {
                                MinimalTransactionId = Math.Max(1, _lastReceivedTransaction.TransactionId)
                            };

                            if (await Poll(download, result))
                            {
                                _lastReceivedTransaction = lastReceiverTransaction;
                                save = true;
                            }
                        }
                    }

                    if (result.UpdateFriends)
                    {
                        await DownloadFriends(false);
                    }

                    foreach (var index in result.Indices)
                    {
                        var chat = GetChat(index, true);
                        if (!IsNodeChat(chat))
                        {
                            _chats[chat.Index] = chat;

                            GenerateSubmitAccount(index);
                            await GenerateDefaultExchangeKeys();
                        }

                        await chat.DownloadMessages(false);
                    }

                    if (result.Indices.Count > 0)
                    {
                        await UIApp.PubSub.PublishAsync(new MessageNodeRefreshEvent(this));
                    }

                    if (save)
                    {
                        await SaveAsync();
                    }


                    await Task.Delay(5000);
                }
                catch (Exception ex)
                {
                    Log.HandleException(ex);
                }
            }
        }
 public override async Task <Result> GetLastTransactionId()
 {
     return(await PreviousAccountTransaction.DownloadLastTransactionInfo(_client, ChainType, ChainId, ChainIndex, AccountId));
 }