示例#1
0
        /// <inheritdoc />
        public override async Task <bool> OnExecute()
        {
            if (this.configuration.NotifyBatchCount == 0)
            {
                this.Abort = true;
                return(true);
            }

            AddressNotifications item;

            if (this.TryDequeue(out item))
            {
                var stoper = Stopwatch.Start();

                var queue     = new Queue <string>(item.Addresses);
                var total     = queue.Count();
                var sendCount = 0;
                do
                {
                    var addresses = Extensions.TakeAndRemove(queue, this.configuration.NotifyBatchCount).ToList();

                    var coin = new CoinAddressInfo
                    {
                        CoinTag = this.configuration.CoinTag,
                        Address = addresses.ToList()
                    };

                    try
                    {
                        await this.client.Value.PostAsJsonAsync(this.configuration.NotifyUrl, coin);

                        sendCount++;
                    }
                    catch (Exception ex)
                    {
                        this.log.LogError(ex, "Notifier");
                        this.Abort = true;
                        return(false);
                    }
                }while (queue.Any());

                stoper.Stop();

                this.log.LogDebug($"Seconds = {stoper.Elapsed.TotalSeconds} - Total = {total} - Requests = {sendCount}");

                return(true);
            }

            return(false);
        }
示例#2
0
        /// <inheritdoc />
        public override async Task <bool> OnExecute()
        {
            if (this.configuration.NotifyBatchCount == 0)
            {
                this.Abort = true;
                return(true);
            }

            AddressNotifications item;

            if (this.TryDequeue(out item))
            {
                var stoper = Stopwatch.Start();

                var queue     = new Queue <string>(item.Addresses);
                var total     = queue.Count();
                var sendCount = 0;
                do
                {
                    var addresses = Extensions.TakeAndRemove(queue, this.configuration.NotifyBatchCount).ToList();

                    var coin = new CoinAddressInfo
                    {
                        CoinTag = this.configuration.CoinTag,
                        Address = addresses.ToList()
                    };

                    try
                    {
                        await this.client.Value.PostAsJsonAsync(this.configuration.NotifyUrl, coin);

                        sendCount++;
                    }
                    catch (Exception ex)
                    {
                        this.tracer.Trace("Notifier", string.Format("error = {0}", ex), ConsoleColor.Red);
                        this.Abort = true;
                        return(false);
                    }
                }while (queue.Any());

                stoper.Stop();

                this.tracer.Trace("Notifier", string.Format("Seconds = {0} - Total = {1} - Requests = {2}", stoper.Elapsed.TotalSeconds, total, sendCount), ConsoleColor.Cyan);

                return(true);
            }

            return(false);
        }
示例#3
0
        /// <inheritdoc />
        public override async Task <bool> OnExecute()
        {
            if (configuration.NotifyBatchCount == 0)
            {
                Abort = true;
                return(true);
            }

            if (TryDequeue(out AddressNotifications item))
            {
                watch.Restart();

                var queue     = new Queue <string>(item.Addresses);
                int total     = queue.Count();
                int sendCount = 0;
                do
                {
                    var addresses = Extensions.Extensions.TakeAndRemove(queue, configuration.NotifyBatchCount).ToList();

                    var coin = new CoinAddressInfo
                    {
                        Symbol  = chainConfiguration.Symbol,
                        Address = addresses.ToList()
                    };

                    try
                    {
                        //await this.client.Value.PostAsync(.PostAsJsonAsync(this.configuration.NotifyUrl, coin);
                        await client.Value.PostAsync(configuration.NotifyUrl, coin, new JsonMediaTypeFormatter());

                        sendCount++;
                    }
                    catch (Exception ex)
                    {
                        log.LogError(ex, "Notifier");
                        Abort = true;
                        return(false);
                    }
                }while (queue.Any());

                watch.Stop();

                log.LogDebug($"Seconds = {watch.Elapsed.TotalSeconds} - Total = {total} - Requests = {sendCount}");

                return(true);
            }

            return(false);
        }