コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public async Task UpdateSightFileAsync(SightFile sightFile)
 {
     var connection = SQLiteService.CreateAsyncConnection();
     await connection.UpdateAsync(sightFile);
 }
コード例 #7
0
 public async Task SaveSightFileAsync(SightFile sightFile)
 {
     CurrentSight.SightFiles.Add(sightFile);
     CurrentSightFiles.Add(sightFile);
     await _dataModelService.SaveSightFileAsync(sightFile);
 }