A model for holding data that the Dashboard Device pane shows.
コード例 #1
0
        public async Task<HttpResponseMessage> GetDashboardDevicePaneDataAsync(string deviceId)
        {
            ValidateArgumentNotNullOrWhitespace("deviceId", deviceId);

            DashboardDevicePaneDataModel result = new DashboardDevicePaneDataModel()
            {
                DeviceId = deviceId
            };

            Func<Task<DashboardDevicePaneDataModel>> getTelemetry =
                async () =>
                {
                    DeviceTelemetrySummaryModel summaryModel;

                    result.DeviceTelemetrySummaryModel = summaryModel =
                        await _deviceTelemetryLogic.LoadLatestDeviceTelemetrySummaryAsync(
                            deviceId, DateTime.Now.AddMinutes(-MAX_DEVICE_SUMMARY_AGE_MINUTES));

                    IEnumerable<DeviceTelemetryModel> telemetryModels;
                    if ((summaryModel != null) && summaryModel.Timestamp.HasValue && summaryModel.TimeFrameMinutes.HasValue)
                    {
                        DateTime minTime = summaryModel.Timestamp.Value.AddMinutes(-summaryModel.TimeFrameMinutes.Value);

                        telemetryModels = await _deviceTelemetryLogic.LoadLatestDeviceTelemetryAsync(deviceId, minTime);

                    }
                    else
                    {
                        telemetryModels = null;

                        result.DeviceTelemetrySummaryModel =
                            new DeviceTelemetrySummaryModel();
                    }

                    if (telemetryModels == null)
                    {
                        result.DeviceTelemetryModels = new DeviceTelemetryModel[0];
                    }
                    else
                    {
                        result.DeviceTelemetryModels =
                            telemetryModels.OrderBy(t => t.Timestamp).ToArray();
                    }

                    return result;
                };

            return await GetServiceResponseAsync<DashboardDevicePaneDataModel>(
                getTelemetry,
                false);
        }
コード例 #2
0
        public async Task<DashboardDevicePaneDataModel> LoadDashboardDevicePaneData(
            string deviceId)
        {
            DateTime minTime;
            DashboardDevicePaneDataModel result;
            DeviceTelemetrySummaryModel summaryModel;
            IEnumerable<DeviceTelemetryModel> telemetryModels;

            if (string.IsNullOrEmpty(deviceId))
            {
                throw new ArgumentException(
                    "deviceId is a null reference or empty string.",
                    "deviceId");
            }

            result = new DashboardDevicePaneDataModel();

            result.DeviceTelemetrySummaryModel =  summaryModel =
                await _deviceTelemetryLogic.LoadLatestDeviceTelemetrySummaryAsync(
                    deviceId,
                    DateTime.Now.AddMinutes(-MaxDeviceSummaryAgeMinutes));

            if ((summaryModel != null) &&
                summaryModel.Timestamp.HasValue &&
                summaryModel.TimeFrameMinutes.HasValue)
            {
                minTime =
                    summaryModel.Timestamp.Value.AddMinutes(
                        -summaryModel.TimeFrameMinutes.Value);

                telemetryModels =
                    await _deviceTelemetryLogic.LoadLatestDeviceTelemetryAsync(
                            deviceId,
                            minTime);
            }
            else
            {
                telemetryModels = null;

                result.DeviceTelemetrySummaryModel = 
                    new DeviceTelemetrySummaryModel();
            }

            if (telemetryModels == null)
            {
                result.DeviceTelemetryModels = new DeviceTelemetryModel[0];
            }
            else
            {
                result.DeviceTelemetryModels =
                    telemetryModels.OrderBy(t => t.Timestamp).ToArray();
            }

            return result;
        }
コード例 #3
0
        public async Task<HttpResponseMessage> GetDashboardDevicePaneDataAsync(string deviceId)
        {
            ValidateArgumentNotNullOrWhitespace("deviceId", deviceId);

            DashboardDevicePaneDataModel result = new DashboardDevicePaneDataModel()
            {
                DeviceId = deviceId
            };

            Func<Task<DashboardDevicePaneDataModel>> getTelemetry =
                async () =>
                {
                    DeviceModel device = await _deviceLogic.GetDeviceAsync(deviceId);

                    IList<DeviceTelemetryFieldModel> telemetryFields = null;

                    try
                    {
                        telemetryFields = _deviceLogic.ExtractTelemetry(device);
                        result.DeviceTelemetryFields = telemetryFields != null ?
                        telemetryFields.ToArray() : null;
                    }
                    catch
                    {
                        HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
                        message.Content = new StringContent(
                        string.Format(Strings.InvalidDeviceTelemetryFormat, deviceId));
                        throw new HttpResponseException(message);
                    }

                    // Get Telemetry Summary
                    DeviceTelemetrySummaryModel summaryModel;

                    result.DeviceTelemetrySummaryModel = summaryModel =
                        await _deviceTelemetryLogic.LoadLatestDeviceTelemetrySummaryAsync(
                            deviceId, DateTime.Now.AddMinutes(-MAX_DEVICE_SUMMARY_AGE_MINUTES));

                    if (summaryModel == null)
                    {
                        result.DeviceTelemetrySummaryModel =
                            new DeviceTelemetrySummaryModel();
                    }

                    // Get Telemetry History
                    IEnumerable<DeviceTelemetryModel> telemetryModels;
                    DateTime minTime = DateTime.Now.AddMinutes(-MAX_DEVICE_SUMMARY_AGE_MINUTES);
                    telemetryModels = await _deviceTelemetryLogic.LoadLatestDeviceTelemetryAsync(deviceId, telemetryFields, minTime);

                    if (telemetryModels == null)
                    {
                        result.DeviceTelemetryModels = new DeviceTelemetryModel[0];
                    }
                    else
                    {
                        result.DeviceTelemetryModels =
                            telemetryModels.OrderBy(t => t.Timestamp).ToArray();
                    }

                    return result;
                };

            return await GetServiceResponseAsync<DashboardDevicePaneDataModel>(
                getTelemetry,
                false);
        }