public void Fetch()
        {
            TimeRunner.Run(async(time, th) =>
            {
                var downloader = new FakeElexonDownloader();
                var dir        = new FakeDirectory(th);
                var fetcher    = new FetchB1610(th, downloader, dir, time, null);

                var cts     = new CancellationTokenSource();
                Task unused = th.Run(async() =>
                {
                    await th.Delay(NodaTime.Duration.FromMinutes(5)).ConfigureAwait(th);
                    cts.Cancel();
                });

                await fetcher.Start(cts.Token).ConfigureAwaitHideCancel(th);

                var reader = new B1610.Reader(th, dir);
                Assert.Equal(100 + 103, await reader.CountAsync().ConfigureAwait(th));
                Assert.Equal(new B1610.Data("GRAI-6", Instant.FromUtc(2017, 7, 31, 23, 0), Power.FromKilowatts(226_200)),
                             await(await reader.ReadAsync(0, 1)).First());
                Assert.Equal(new B1610.Data("GRGBW-1", Instant.FromUtc(2017, 7, 31, 23, 30), Power.FromKilowatts(43_390)),
                             await(await reader.ReadAsync(100 + 103 - 1, 100 + 103)).First());
            }, startInstant: NodaTime.Instant.FromUtc(2017, 8, 10, 22, 30));
        }
Beispiel #2
0
        static async Task <int> ShowB1610(ShowB1610Options opts)
        {
            var taskHelper = SystemTaskHelper.Instance;
            var dir        = new SystemDirectory(taskHelper, opts.DataDirectory);
            var reader     = new B1610.Reader(taskHelper, dir);
            var count      = opts.Count;
            var totalCount = (int)await reader.CountAsync();

            Console.WriteLine($"B1610 data count: {totalCount}");
            Console.WriteLine($"Latest {count} data readings:");
            var data = await reader.ReadAsync(totalCount - count, totalCount);

            data.ForEach(r => Console.WriteLine(r));
            return(0);
        }
        private async Task Start0(CancellationToken ct)
        {
            while (true)
            {
                int count = (int)await _reader.CountAsync().ConfigureAwait(_taskHelper);

                var items     = await(await _reader.ReadAsync(count - 500, ct: ct).ConfigureAwait(_taskHelper)).ToList().ConfigureAwait(_taskHelper);
                var lastTime  = items.Any() ? items.Max(x => x.SettlementPeriodStart) : _time.GetCurrentInstant() - Duration.FromDays(10);
                var fetchTime = lastTime + Duration.FromMinutes(30);
                var data      = await _b1610.GetAsync(fetchTime.SettlementDate(), fetchTime.SettlementPeriod(), ct).ConfigureAwait(_taskHelper);

                if (data.Count == 0)
                {
                    await _scheduler.ScheduleOne(Duration.FromMinutes(30), Duration.FromMinutes(2.5), ct).ConfigureAwait(_taskHelper);
                }
                else
                {
                    await _writer.AppendAsync(data, ct).ConfigureAwait(_taskHelper);

                    await _scheduler.ScheduleOne(Duration.FromMinutes(5), Duration.FromMinutes(2.5), ct).ConfigureAwait(_taskHelper);
                }
            }
        }