protected async Task UpdateSafetyProfilesAsync() { // First check if we have a internet connection. If we do go and get the latest safety checks from Blue Sphere. if (_reachability.IsConnected()) { IEnumerable <SafetyProfile> safetyProfiles = null; try { safetyProfiles = await _gatewayService.GetSafetyProfilesAsync(); } catch (TaskCanceledException) { // Although we have used reachability to determine that there is an available network connection, // it is still possible for the data fetch to fail which triggers a TaskCanceledException. } if (safetyProfiles != null) { await _safetyProfileRepository.DeleteAllAsync(); try { await _safetyProfileRepository.InsertAsync(safetyProfiles); } catch (Exception ex) { MvxTrace.Error("\"{0}\" in {1}.{2}\n{3}", ex.Message, "SafetyProfileRepository", "InsertAsync", ex.StackTrace); throw; } } } var safetyProfileData = await _safetyProfileRepository.GetAllAsync(); if (safetyProfileData.ToList().Count == 0) { await Mvx.Resolve <ICustomUserInteraction>().AlertAsync("No Profiles Found."); } }
// returns false if the customer code is not known // throws exceptions if the web services or db inserts fail private async Task <bool> SetupDeviceAsync() { if (!await _gatewayService.CreateDeviceAsync()) { _errorMessage = _unexpectedErrorMessage; return(false); } var device = await _gatewayService.GetDeviceAsync(CustomerCode); if (device == null) { _errorMessage = "The customer passcode you submitted doesn't exist, check the passcode and try again."; return(false); } var config = await _gatewayService.GetConfigAsync(); var applicationProfile = await _gatewayService.GetApplicationProfileAsync(); var drivers = await _gatewayService.GetDriversAsync(); var vehicleViews = await _gatewayService.GetVehicleViewsAsync(); var safetyProfiles = await _gatewayService.GetSafetyProfilesAsync(); var vehicleViewVehicles = new Dictionary <string, IEnumerable <Models.BaseVehicle> >(vehicleViews.Count()); foreach (var vehicleView in vehicleViews) { vehicleViewVehicles.Add(vehicleView.Title, await _gatewayService.GetVehiclesAsync(vehicleView.Title)); } var vehiclesAndTrailers = vehicleViewVehicles.SelectMany(vvv => vvv.Value).DistinctBy(v => v.ID); var vehicles = vehiclesAndTrailers.Where(bv => !bv.IsTrailer).Select(bv => new Models.Vehicle(bv)); var trailers = vehiclesAndTrailers.Where(bv => bv.IsTrailer).Select(bv => new Models.Trailer(bv)); //TODO: I'm not sure whether verb profiles will be used anywhere within this app, or whether this is a hangover from the Tough Touch implementation? If not used on completion of the project then remove from here and local db. // TODO: Get verb profile titles from config or somewhere? var verbProfileTitles = new[] { "Palletforce", "Cancel", "Complete", "Suspend" }; var verbProfiles = new List <Models.VerbProfile>(verbProfileTitles.Count()); foreach (var verbProfileTitle in verbProfileTitles) { var verbProfile = await _gatewayService.GetVerbProfileAsync(verbProfileTitle); if (verbProfile != null) { verbProfiles.Add(verbProfile); } } await _dataService.RunInTransactionAsync(c => { //TODO: Store the customer title? Need to get the customer title from somewhere. _customerRepository.Insert(new Customer() { ID = Guid.NewGuid(), CustomerCode = CustomerCode }, c); _deviceRepository.Insert(device, c); _verbProfileRepository.Insert(verbProfiles, c); _applicationProfileRepository.Insert(applicationProfile, c); _driverRepository.Insert(drivers, c); //TODO: relate Vehicles to VehicleViews? Are VehicleViews actually used for anything within the app? _vehicleRepository.Insert(vehicles, c); _trailerRepository.Insert(trailers, c); _safetyProfileRepository.Insert(safetyProfiles, c); _configRepository.Insert(config, c); }); //TODO: call fwRegisterDevice - what does this actually do? return(true); }