Exemple #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));
        }
Exemple #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);
        }
Exemple #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);

                IEnumerable <LocationJerkModel> locationJerks = await _locationJerkLogic.LoadLatestLocationJerkInfoAsync();


                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));
        }
Exemple #4
0
        //[WebApiRequirePermission(Permission.ViewTelemetry)]
        //public async Task<HttpResponseMessage> GetDashboardDevicePaneDataAsync(string deviceId)
        public async Task <HttpResponseMessage> GetDashboardDevicePaneDataAsync()
        {
            // TESTING
            var deviceId = "SampleDevice001_375";

            ValidateArgumentNotNullOrWhitespace("deviceId", deviceId);

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

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

                IList <DeviceTelemetryFieldModel> telemetryFields;

                try
                {
                    telemetryFields = _deviceLogic.ExtractTelemetry(device);
                    result.DeviceTelemetryFields = telemetryFields?.ToArray();
                }
                catch
                {
                    HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
                    message.Content = new StringContent($"Device {deviceId} has an invalid Telemetry specification on its DeviceInfo");
                    throw new HttpResponseException(message);
                }

                // Get Telemetry Summary
                DeviceTelemetrySummaryModel summaryModel;

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

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

                // Get Telemetry History
                DateTime minTime         = DateTime.Now.AddMinutes(-MaxDeviceSummaryAgeMinutes);
                var      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(getTelemetry, false));
        }
        public async Task <HttpResponseMessage> GetDashboardDevicePaneDataAsync([FromBody] string[] deviceIds)
        {
            HttpResponseMessage r = new HttpResponseMessage();

            Func <Task <List <DashboardDevicePaneDataModel> > > getTelemetry =
                async() =>
            {
                List <DashboardDevicePaneDataModel> results = new List <DashboardDevicePaneDataModel>();

                foreach (var deviceId in deviceIds)
                {
                    DashboardDevicePaneDataModel result = new DashboardDevicePaneDataModel()
                    {
                        DeviceId = deviceId
                    };

                    dynamic device = await _deviceLogic.GetDeviceAsync(deviceId);

                    result.MessengerUser = Convert.ToString(device.DeviceProperties.MessengerUser);

                    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 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();
                    }

                    results.Add(result);
                }

                return(results);
            };

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