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;
            }
        }
Beispiel #2
0
        internal async Task <Models.Image> AddImageAsync(string userId, Models.Album album, string sourceFile)
        {
            var image = new Models.Image {
                UserId       = userId,
                AlbumId      = album.AlbumId,
                UploadFormat = "Mobile Image"
            };

            await imageTableSync.InsertAsync(image); // create a new image record

            // add image to the record
            string copiedFilePath = await FileHelper.CopyFileAsync(image.Id, sourceFile, DataFilesPath);

            string copiedFileName = Path.GetFileName(copiedFilePath);

            // add an object representing a resize request for the blob
            // it will be synced after all images have been uploaded
            await resizeRequestSync.InsertAsync(new ResizeRequest { BlobName = copiedFileName });

            var file = await imageTableSync.AddFileAsync(image, copiedFileName);

            image.File = file;

            return(image);
        }
        public async Task AddImage(ImageReference imageReference)
        {
            string fileName = Path.GetFileName(imageReference.FileName);

            await _imageReferenceTable.InsertAsync(imageReference);

            await _imageReferenceTable.AddFileAsync(imageReference, fileName);
        }
Beispiel #4
0
        public async Task <MobileServiceFile> AddItemImageAsync(TodoItem item, string image)
        {
            var path = await fileProvider.CopyItemFileAsync(item.Id, image);

            var fileName = Path.GetFileName(path);
            var msFile   = await itemTable.AddFileAsync(item, fileName);

            return(msFile);
        }
Beispiel #5
0
        public async Task AddItemAsync(SaleItem item, string imagePath)
        {
            await saleItemsTable.InsertAsync(item);

            string targetPath = await FileHelper.CopySaleItemFileAsync(item.Id, imagePath);

            await saleItemsTable.AddFileAsync(item, Path.GetFileName(targetPath));

            await SyncSaleItems();
        }
Beispiel #6
0
        internal async Task <Models.Image> AddImageAsync(Models.Album album, string sourceFile)
        {
            var image = new Models.Image {
                UserId       = Settings.Current.CurrentUserId,
                AlbumId      = album.AlbumId,
                UploadFormat = "Mobile Image",
                UpdatedAt    = DateTime.Now
            };

            await imageTableSync.InsertAsync(image); // create a new image record

            // add image to the record
            string copiedFilePath = await FileHelper.CopyFileAsync(image.Id, sourceFile, DataFilesPath);

            string copiedFileName = Path.GetFileName(copiedFilePath);

            var file = await imageTableSync.AddFileAsync(image, copiedFileName);

            image.File = file;

            return(image);
        }
Beispiel #7
0
        public async Task InsertCoupon(Coupon coupon, string filename)
        {
            await couponTable.InsertAsync(coupon);

            var file = await couponTable.AddFileAsync(coupon, filename);
        }