예제 #1
0
        public async Task GetGraphData()
        {
            var utcNow        = DateTime.UtcNow;
            var startDateTime = utcNow.FirstDayOfLastMonth();
            var device        = await GetWindowsDeviceAsync().ConfigureAwait(false);

            Assert.NotNull(device);

            var dataSource = await PortalClient
                             .GetDataSourceByUniqueNameAsync("WinCPU")
                             .ConfigureAwait(false);

            Assert.NotNull(dataSource);

            var dataSourceGraph = await PortalClient
                                  .GetDataSourceGraphByNameAsync(dataSource.Id, "CPU Usage")
                                  .ConfigureAwait(false);

            Assert.NotNull(dataSourceGraph);

            var deviceDataSource = await PortalClient
                                   .GetDeviceDataSourceByDeviceIdAndDataSourceIdAsync(device.Id, dataSource.Id)
                                   .ConfigureAwait(false);

            Assert.NotNull(deviceDataSource);

            var deviceDataSourceInstances = await PortalClient
                                            .GetAllDeviceDataSourceInstancesAsync(device.Id, deviceDataSource.Id, new Filter <DeviceDataSourceInstance>())
                                            .ConfigureAwait(false);

            Assert.NotNull(deviceDataSourceInstances);
            Assert.NotEmpty(deviceDataSourceInstances);

            var deviceGraphDataRequest = new DeviceDataSourceInstanceGraphDataRequest
            {
                DeviceDataSourceInstanceId = deviceDataSourceInstances.Single().Id,
                DataSourceGraphId          = dataSourceGraph.Id,
                TimePeriod    = TimePeriod.Zoom,
                StartDateTime = startDateTime,
                EndDateTime   = utcNow.LastDayOfLastMonth()
            };

            //  Ensure Caching is enabled
            PortalClient.UseCache = true;

            var graphData = await PortalClient.GetGraphDataAsync(deviceGraphDataRequest).ConfigureAwait(false);

            Assert.NotEmpty(graphData.Lines);
            Assert.Equal(startDateTime, graphData.StartTimeUtc);
            Assert.NotNull(graphData.Lines[0].ColorString);

            // Ensure that subsequent fetches are fast
            var stopwatch = Stopwatch.StartNew();

            graphData = await PortalClient.GetGraphDataAsync(deviceGraphDataRequest).ConfigureAwait(false);

            Assert.NotNull(graphData);
            stopwatch.Stop();
            Assert.True(stopwatch.ElapsedMilliseconds < 50);
        }
예제 #2
0
        public async void GetGraphData_X250()
        {
            PortalClient.UseCache = true;
            var utcNow        = DateTime.UtcNow;
            var startDateTime = utcNow.FirstDayOfLastMonth();
            var device        = await GetWindowsDeviceAsync().ConfigureAwait(false);

            var dataSource = await PortalClient.GetDataSourceByUniqueNameAsync("WinCPU").ConfigureAwait(false);

            var dataSourceGraph = await PortalClient.GetDataSourceGraphByNameAsync(dataSource.Id, "CPU Usage").ConfigureAwait(false);

            Assert.NotNull(dataSourceGraph);
            var deviceDataSource = await PortalClient.GetDeviceDataSourceByDeviceIdAndDataSourceIdAsync(device.Id, dataSource.Id).ConfigureAwait(false);

            var deviceDataSourceInstances = await PortalClient.GetAllDeviceDataSourceInstancesAsync(device.Id, deviceDataSource.Id, new Filter <DeviceDataSourceInstance>()).ConfigureAwait(false);

            var deviceGraphDataRequest = new DeviceDataSourceInstanceGraphDataRequest
            {
                DeviceDataSourceInstanceId = deviceDataSourceInstances.Single().Id,
                DataSourceGraphId          = dataSourceGraph.Id,
                TimePeriod    = TimePeriod.Zoom,
                StartDateTime = startDateTime,
                EndDateTime   = utcNow.LastDayOfLastMonth()
            };
            var sw = Stopwatch.StartNew();

            for (var n = 0; n < 250; n++)
            {
                Logger.LogInformation($"{n:000}: {sw.ElapsedMilliseconds:00000}ms");
                await PortalClient.GetGraphDataAsync(deviceGraphDataRequest).ConfigureAwait(false);
            }
        }