public async Task SaveSightFileAsync(SightFile sightFile) { try { await InitializeAsync(); await sightFileTable.InsertAsync(sightFile); // A 'SightFile' is actually the SightFile object that saves details about an attached file in a database table // and then there is the physical file itself if (sightFile.Uri?.StartsWith("ms-appdata") ?? false) { // Optimisation for this lab - many images are shipped as content in the app package // and therefore have ms-appx:/// Uris - don't sync these to the cloud, as it will put a big network surge // when everyone starts the app for the first time // So we only care about files with ms-appdata uri which have been created by the user - these we sync to the cloud sightFile.File = await sightFileTable.AddFileAsync(sightFile, sightFile.FileName); } await SyncAsync(); // offline sync } catch (Exception ex) { var errorString = "Insert SightFile failed: " + ex.Message + "\n\nIf you are still in an offline scenario, " + "you can try your Pull again when connected with your Mobile Service."; await ShowError(errorString); throw; } }
public async Task UpdateSightFileAsync(SightFile sightFile) { try { await InitializeAsync(); // Get unaltered one var sightFileOriginal = await sightFileTable.LookupAsync(sightFile.Id.ToString()); await sightFileTable.UpdateAsync(sightFile); if (sightFileOriginal?.Uri != sightFile.Uri) { // Image file has changed - upload the new file if (sightFile.Uri?.StartsWith("ms-appdata") ?? false) { // So we only care about files with ms-appdata uri which have been created by the user - these we sync to the cloud sightFile.File = await sightFileTable.AddFileAsync(sightFile, sightFile.FileName); } } await SyncAsync(); // offline sync } catch (Exception ex) { var errorString = "Update SightFile failed: " + ex.Message + "\n\nIf you are still in an offline scenario, " + "you can try your Pull again when connected with your Mobile Service."; await ShowError(errorString); throw; } }
public async Task ReplaceSelectedSightFileAsync(SightFile replacement) { // Delete in the database await _dataModelService.DeleteSightFileAsync(SelectedSightFile); // And save the replacement await _dataModelService.SaveSightFileAsync(replacement); // Replace the current version with the updated one int position = CurrentSightFiles.IndexOf(SelectedSightFile); CurrentSightFiles.Insert(position, replacement); CurrentSightFiles.RemoveAt(position + 1); SightImage = replacement.ImageUri; }
public async Task DeleteSightFileAsync(SightFile sightFile) { try { await InitializeAsync(); await sightFileTable.DeleteAsync(sightFile); await SyncAsync(); // offline sync } catch (Exception ex) { var errorString = "Delete failed: " + ex.Message + "\n\nIf you are still in an offline scenario, " + "you can try your Pull again when connected with your Mobile Service."; await ShowError(errorString); throw; } }
public async Task <SightFile> CreateSightFileAndAssociatedStorageFileAsync() { // Id of the new SightFile Guid sightFileId = Guid.NewGuid(); StorageFolder sightFolder = await GetStorageFolderForSightFile(sightFileId); // Create the physical file var attachedFile = await sightFolder.CreateFileAsync($"{Guid.NewGuid().ToString("D")}.png", CreationCollisionOption.GenerateUniqueName); var sightFile = new SightFile { Id = sightFileId, FileType = SightFileType.General, Sight = CurrentSight, SightId = CurrentSight.Id, FileName = attachedFile.Name, Uri = attachedFile.GetUri().ToString() }; return(sightFile); }
public async Task UpdateSightFileAsync(SightFile sightFile) { var connection = SQLiteService.CreateAsyncConnection(); await connection.UpdateAsync(sightFile); }
public async Task SaveSightFileAsync(SightFile sightFile) { CurrentSight.SightFiles.Add(sightFile); CurrentSightFiles.Add(sightFile); await _dataModelService.SaveSightFileAsync(sightFile); }