private async Task GetPoolInfoAsync(HttpContext context, Match m) { var pool = GetPool(context, m); // load stats var stats = await cf.Run(con => statsRepo.GetLastPoolStatsAsync(con, pool.Id)); // get pool pools.TryGetValue(pool.Id, out var poolInstance); var response = new GetPoolResponse { Pool = pool.ToPoolInfo(mapper, stats, poolInstance) }; // enrich response.Pool.TotalPaid = await cf.Run(con => statsRepo.GetTotalPoolPaymentsAsync(con, pool.Id)); #if DEBUG var from = new DateTime(2018, 1, 7, 16, 0, 0); #else var from = clock.Now.AddDays(-1); #endif response.Pool.TopMiners = (await cf.Run(con => statsRepo.PagePoolMinersByHashrateAsync( con, pool.Id, from, 0, 15))) .Select(mapper.Map <MinerPerformanceStats>) .ToArray(); await SendJsonAsync(context, response); }
private async Task GetPoolInfoAsync(HttpContext context, Match m) { var pool = GetPool(context, m); if (pool == null) { return; } var stats = cf.Run(con => statsRepo.GetLastPoolStats(con, pool.Id)); var response = new GetPoolResponse { Pool = pool.ToPoolInfo(mapper, stats) }; response.Pool.TotalPaid = cf.Run(con => statsRepo.GetTotalPoolPayments(con, pool.Id)); #if DEBUG var from = new DateTime(2018, 1, 7, 16, 0, 0); #else var from = clock.Now.AddDays(-1); #endif response.Pool.TopMiners = cf.Run(con => statsRepo.PagePoolMinersByHashrate( con, pool.Id, from, 0, 15)) .Select(mapper.Map <MinerPerformanceStats>) .ToArray(); await SendJsonAsync(context, response); }
public async Task <GetPoolResponse> GetPoolInfoAsync(string poolId) { var pool = GetPool(poolId); // load stats var stats = await cf.Run(con => statsRepo.GetLastPoolStatsAsync(con, pool.Id)); // get pool pools.TryGetValue(pool.Id, out var poolInstance); var response = new GetPoolResponse { Pool = pool.ToPoolInfo(mapper, stats, poolInstance) }; // enrich response.Pool.TotalPaid = await cf.Run(con => statsRepo.GetTotalPoolPaymentsAsync(con, pool.Id)); var from = clock.Now.AddDays(-1); response.Pool.TopMiners = (await cf.Run(con => statsRepo.PagePoolMinersByHashrateAsync( con, pool.Id, from, 0, 15))) .Select(mapper.Map <MinerPerformanceStats>) .ToArray(); return(response); }
/// <summary> /// Builds a GetPoolResponse object /// </summary> public static GetPoolResponse CreateGetPoolResponse(string poolName) { GetPoolResponse response = new GetPoolResponse(); SetProperty(response, "StatusCode", HttpStatusCode.OK); Pool pool = new Pool(); SetProperty(pool, "Name", poolName); SetProperty(response, "Pool", pool); return(response); }
private async Task HandleGetPoolAsync(HttpContext context, Match m) { GetPoolResponse response; var pool = GetPool(context, m); if (pool == null) { return; } response = new GetPoolResponse() { Pool = pool.ToPoolInfo(mapper) }; await SendJson(context, response); }
public void GetBatchPoolTest() { // Setup cmdlet to get a Pool by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Name = "testPool"; cmdlet.Filter = null; // Build a Pool instead of querying the service on a GetPool call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is GetPoolRequest) { GetPoolResponse response = BatchTestHelpers.CreateGetPoolResponse(cmdlet.Name); Task <object> task = Task <object> .Factory.StartNew(() => { return(response); }); return(task); } return(null); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudPool> pipeline = new List <PSCloudPool>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())).Callback <object>(p => pipeline.Add((PSCloudPool)p)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the Pool returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Name, pipeline[0].Name); }
/// <summary> /// Builds a GetPoolResponse object /// </summary> public static GetPoolResponse CreateGetPoolResponse(string poolName) { GetPoolResponse response = new GetPoolResponse(); SetProperty(response, "StatusCode", HttpStatusCode.OK); Pool pool = new Pool(); SetProperty(pool, "Name", poolName); SetProperty(response, "Pool", pool); return response; }