コード例 #1
0
        private void UpdateLocationJerkList(LocationJerkModel newLocationJerk, ref List <LocationJerkModel> newLocationJerkList)
        {
            if (newLocationJerk != null)
            {
                LocationJerkModel found = newLocationJerkList.FirstOrDefault(l => l.Latitude == newLocationJerk.Latitude && l.Longitude == newLocationJerk.Longitude);

                if (found == null)
                {
                    newLocationJerkList.Add(newLocationJerk);
                }
                else
                {
                    foreach (DeviceJerkModel deviceJerk in newLocationJerk.DeviceList)
                    {
                        DeviceJerkModel existingDeviceJerk = found.DeviceList.FirstOrDefault(d => d.DeviceId == deviceJerk.DeviceId);

                        if (existingDeviceJerk == null)
                        {
                            found.DeviceList.Add(deviceJerk);
                        }
                        else
                        {
                            existingDeviceJerk.CapturedJerks.AddRange(deviceJerk.CapturedJerks);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public async Task <HttpResponseMessage> GetJerkGraphData(string deviceId, string latitude, string longitude)
        {
            return(await GetServiceResponseAsync <LocationReportGraphPaneDataModel>(async() =>
            {
                double lat;
                double lng;
                LocationReportGraphPaneDataModel dataModel = null;
                if (Double.TryParse(latitude, out lat) && Double.TryParse(longitude, out lng) && !String.IsNullOrEmpty(deviceId))
                {
                    LocationJerkModelExtended locationJerkModel = await _locationJerkLogic.GetLocationDetails(lat as double?, lng as double?);
                    if (locationJerkModel.DeviceList != null)
                    {
                        DeviceJerkModel jerkModel = locationJerkModel.DeviceList.Where(d => d.DeviceId == deviceId).FirstOrDefault();

                        dataModel = new LocationReportGraphPaneDataModel()
                        {
                            DeviceId = jerkModel.DeviceId,
                            Speed = jerkModel.Speed,
                            Heading = jerkModel.Heading
                        };

                        IList <LocationJerkGraphFieldModel> graphFields = ExtractLocationJerkGraphFields();
                        dataModel.LocationJerkGraphFields = graphFields != null ? graphFields.ToArray() : null;

                        IEnumerable <LocationJerkGraphModel> graphModels = GetLocationJerkGraphModels(jerkModel.CapturedJerks);

                        if (graphModels == null)
                        {
                            dataModel.LocationJerkGraphModels = new LocationJerkGraphModel[0];
                        }
                        else
                        {
                            dataModel.LocationJerkGraphModels = graphModels.OrderBy(t => t.Timestamp).ToArray();
                        }
                    }
                }
                return dataModel;
            }, false));
        }
コード例 #3
0
        public async Task SaveLocationJerkInfoAsync(List <LocationJerkModel> newLocationJerks)
        {
            LocationJerkBlobResults existingBlobResults = await GetAllLocationJerkInfo();

            List <LocationJerkModel> existingLocationJerks = existingBlobResults.LocationJerkInfo;

            foreach (LocationJerkModel newJerkModel in newLocationJerks)
            {
                if (newJerkModel.Latitude == null)
                {
                    throw new Exception("No Latitude Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                }

                if (newJerkModel.Longitude == null)
                {
                    throw new Exception("No Longitude Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                }

                if (newJerkModel.DeviceList == null)
                {
                    throw new Exception("No DeviceList Found in LocationJerkModel-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                }

                if (newJerkModel.Latitude != null && newJerkModel.Longitude != null)
                {
                    LocationJerkModel found = (existingLocationJerks as IEnumerable <LocationJerkModel>).FirstOrDefault(j => j.Latitude == newJerkModel.Latitude && j.Longitude == newJerkModel.Longitude);

                    if (found == null)
                    {
                        if (newJerkModel.DeviceList != null)
                        {
                            foreach (DeviceJerkModel jerkDevice in newJerkModel.DeviceList)
                            {
                                if (jerkDevice.DeviceId == String.Empty || String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                                {
                                    throw new Exception("No DeviceID Found in Jerked Device-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                                }

                                if (jerkDevice.CapturedJerks == null || jerkDevice.DeviceId == String.Empty || String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                                {
                                    newJerkModel.DeviceList.Remove(jerkDevice);
                                }
                            }

                            if (newJerkModel.DeviceList != null && newJerkModel.DeviceList.Count() > 0)
                            {
                                existingLocationJerks.Add(newJerkModel);
                            }
                        }
                    }
                    else
                    {
                        List <DeviceJerkModel> newDevices = newJerkModel.DeviceList;
                        foreach (DeviceJerkModel jerkDevice in newDevices)
                        {
                            if (jerkDevice.DeviceId == String.Empty || String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                            {
                                throw new Exception("No DeviceID Found in Jerked Device-- from LocationJerkRepository.SaveLocationJerkInfoAsync");
                            }

                            if (jerkDevice.DeviceId != String.Empty || !String.IsNullOrWhiteSpace(jerkDevice.DeviceId))
                            {
                                DeviceJerkModel deviceFound = (found.DeviceList as IEnumerable <DeviceJerkModel>).FirstOrDefault(d => d.DeviceId == jerkDevice.DeviceId);

                                if (jerkDevice.CapturedJerks != null)
                                {
                                    if (deviceFound == null)
                                    {
                                        found.DeviceList.Add(jerkDevice);
                                    }
                                    else
                                    {
                                        deviceFound.CapturedJerks.AddRange(jerkDevice.CapturedJerks);
                                    }
                                }
                            }
                        }
                    }

                    //add code here for setting status of Location
                }
            }

            string newJsonData = JsonConvert.SerializeObject(existingLocationJerks);

            byte[] newBytes = Encoding.UTF8.GetBytes(newJsonData);

            await _blobStorageManager.UploadFromByteArrayAsync(
                _blobName,
                newBytes,
                0,
                newBytes.Length,
                AccessCondition.GenerateIfMatchCondition(existingBlobResults.ETag),
                null,
                null);
        }