public void Fetch() { TimeRunner.Run(async(time, th) => { var downloader = new FakeElexonDownloader(); var dir = new FakeDirectory(th); var fetcher = new FetchPhyBmData(th, downloader, dir, time); var cts = new CancellationTokenSource(); Task unused = th.Run(async() => { await th.Delay(NodaTime.Duration.FromMinutes(60)).ConfigureAwait(th); cts.Cancel(); }); await fetcher.Start(false, cts.Token).ConfigureAwaitHideCancel(th); var reader = new PhyBmData.FpnReader(th, dir); Assert.Equal(1031 + 1023, await reader.CountAsync().ConfigureAwait(th)); var cldcwIdHash = EicIds.Hash("CLDCW-1"); var cldcwTask = (await reader.ReadAsync().ConfigureAwait(th)).Where(x => x.ResourceNameHash == cldcwIdHash); var cldcw = await cldcwTask.ToList().ConfigureAwait(th); Assert.Equal(4, cldcw.Count); Assert.Equal(new [] { 13.0, 11.0, 11.0, 9.0 }, cldcw.Select(x => x.LevelTo.Megawatts)); }, startInstant: NodaTime.Instant.FromUtc(2017, 8, 5, 22, 29)); }
static async Task <int> ShowPhyBmData(ShowPhyBmDataOptions opts) { var taskHelper = SystemTaskHelper.Instance; var dir = new SystemDirectory(taskHelper, opts.DataDirectory); var reader = new PhyBmData.FpnReader(taskHelper, dir); var count = opts.Count; var totalCount = (int)await reader.CountAsync(); Console.WriteLine($"Physical BM 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); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddResponseCompression(options => { options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { MediaTypeNames.Application.Octet, WasmMediaTypeNames.Application.Wasm, }); }); services.AddSingleton <ITime>(SystemTime.Instance); services.AddSingleton <ITaskHelper>(SystemTaskHelper.Instance); services.AddSingleton <Db <FuelInstHhCur.Data> >(svcs => { var taskHelper = svcs.GetRequiredService <ITaskHelper>(); var options = svcs.GetRequiredService <CmdLineOptions>(); var dir = new SystemDirectory(taskHelper, options.FuelInstHhCurDataDirectory); var reader = new FuelInstHhCur.Reader(taskHelper, dir); return(new Db <FuelInstHhCur.Data>(taskHelper, reader)); }); services.AddSingleton <Db <Freq.Data> >(svcs => { var taskHelper = svcs.GetRequiredService <ITaskHelper>(); var options = svcs.GetRequiredService <CmdLineOptions>(); var dir = new SystemDirectory(taskHelper, options.FreqDataDirectory); var reader = new Freq.Reader(taskHelper, dir); return(new Db <Freq.Data>(taskHelper, reader)); }); services.AddSingleton <InstantaneousFlow.Reader>(svcs => { var taskHelper = svcs.GetRequiredService <ITaskHelper>(); var options = svcs.GetRequiredService <CmdLineOptions>(); var dir = new SystemDirectory(taskHelper, options.GasFlowDataDirectory); return(new InstantaneousFlow.Reader(taskHelper, dir)); }); services.AddSingleton <Db <InstantaneousFlow.Data> >(svcs => { var taskHelper = svcs.GetRequiredService <ITaskHelper>(); var reader = svcs.GetRequiredService <InstantaneousFlow.Reader>(); return(new Db <InstantaneousFlow.Data>(taskHelper, reader)); }); services.AddSingleton <Db <B1610.Data> >(svcs => { var taskHelper = svcs.GetRequiredService <ITaskHelper>(); var options = svcs.GetRequiredService <CmdLineOptions>(); var dir = new SystemDirectory(taskHelper, options.B1610DataDirectory); var reader = new B1610.Reader(taskHelper, dir); return(new Db <B1610.Data>(taskHelper, reader)); }); services.AddSingleton <Db <PhyBmData.FpnData> >(svcs => { var taskHelper = svcs.GetRequiredService <ITaskHelper>(); var options = svcs.GetRequiredService <CmdLineOptions>(); var dir = new SystemDirectory(taskHelper, options.FpnDataDirectory); var reader = new PhyBmData.FpnReader(taskHelper, dir); return(new Db <PhyBmData.FpnData>(taskHelper, reader, pollInterval: Duration.FromMinutes(5))); }); services.AddSingleton <PostBag>(); }