コード例 #1
0
        public async Task DeleteLocationsInBatchAsync(IEnumerable <LocationModel> locations)
        {
            if (locations != null)
            {
                LocationJerkBlobResults existingBlobResults = await GetAllLocationJerkInfo();

                List <LocationJerkModel> existingLocationJerks = existingBlobResults.LocationJerkInfo;
                LocationJerkModel        found = null;

                foreach (var location in locations)
                {
                    found = (existingLocationJerks as IEnumerable <LocationJerkModel>).FirstOrDefault(j => j.Latitude == location.Latitude && j.Longitude == location.Longitude);

                    if (found != null)
                    {
                        existingLocationJerks.Remove(found);
                    }

                    found = null;
                }

                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);
            }
        }
コード例 #2
0
        public async Task DeleteLocationJerkAsync(double?latitude, double?longitude)
        {
            LocationJerkBlobResults existingBlobResults = await GetAllLocationJerkInfo();

            List <LocationJerkModel> existingLocationJerks = existingBlobResults.LocationJerkInfo;


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

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

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

                if (found != null)
                {
                    existingLocationJerks.Remove(found);
                }
            }

            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);
        }
コード例 #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);
        }