Ejemplo n.º 1
0
        public async Task <Notified> SendAsync(IEnumerable <Gem> gems)
        {
            var result = new Notified();

            try
            {
                if (gems.AnyAndNotNull())
                {
                    foreach (var gem in gems)
                    {
                        Task <SingleServiceResponse <TokenInfo> >     tokenInfoTask = null;
                        Task <SingleServiceResponse <SmartContract> > contractTask  = null;
                        Task <SingleServiceResponse <TopHolderList> > holdersTask   = null;

                        await TaskExt.Sequence(
                            () => { return(tokenInfoTask = _ethPlorerService.FetchTokenInfoAsync(gem.Id)); },
                            () => { return(contractTask = _etherScanService.IsSmartContractVerifiedAsync(gem.Id)); },
                            () => { return(Task.Delay(1000)); },
                            () => { return(holdersTask = _ethPlorerService.FetchTopHoldersAsync(gem.Id, 5)); }
                            );

                        var msgPr = KyberMsg.ForPremiumTelegram(
                            gem,
                            tokenInfoTask.Result,
                            contractTask.Result,
                            holdersTask.Result);

                        var sentPr = await _telegramService.SendPremiumMessageAsync(msgPr.Item2, msgPr.Item1);

                        if (!sentPr.Success)
                        {
                            result.Message += $"Telegram Premium Error: {sentPr.Message}";
                        }
                    }
                }
                else
                {
                    result.Message = "Nothing to send";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.GetFullMessage();
            }
            return(result);
        }