コード例 #1
0
        private IMobileServiceSyncTable<TodoItem> todoTable = App.MobileService.GetSyncTable<TodoItem>(); // offline sync


        public async Task DeleteTodoItem(TodoItem todoItem)
        {
            // This code deletes a TodoItem from the database. 
            await todoTable.DeleteAsync(todoItem);

            await SyncWithImagesAsync(); // offline sync        
        }
コード例 #2
0
 public async Task DeleteTodoItem(TodoItem todoitem)
 {
     var item = (from t in _cache
                 where t.Id == todoitem.Id
                 select t).FirstOrDefault();
     _cache.Remove(item);
     await _fileService.WriteAsync<Models.TodoItem>(cachekey, _cache);
 }
コード例 #3
0
            public async Task InsertTodoItem(TodoItem todoItem)
            {
                try
                {

                    // This code inserts a new TodoItem into the database. 
                    await todoTable.InsertAsync(todoItem);

                }
                catch (Exception)
                {
                    throw;
                }
                //await SyncAsync(); // offline sync
            }
コード例 #4
0
        public async Task InsertTodoItem(TodoItem todoItem)
        {
            try
            {
                if (todoItem.ImageUploadPending)
                {
                    // Set blob properties of TodoItem.
                    todoItem.ContainerName = "todoitemimages";

                    // Use a unigue GUID to avoid collisions.
                    todoItem.ResourceName = Guid.NewGuid().ToString();
                }

                // This code inserts a new TodoItem into the database. 
                await todoTable.InsertAsync(todoItem);

            }
            catch (Exception)
            {
                throw;
            }

            await SyncWithImagesAsync(); // offline sync
        }
コード例 #5
0
 public async Task InsertTodoItem(TodoItem item)
 {
     _cache.Add(item);
     await _fileService.WriteAsync<Models.TodoItem>(cachekey, _cache);
 }
コード例 #6
0
        private async Task UploadImage(TodoItem todoItem)
        {
            // If we have a returned SAS, then upload the blob.
            if (!string.IsNullOrEmpty(todoItem.SasQueryString))
            {
                // Get the URI generated that contains the SAS 
                // and extract the storage credentials.
                StorageCredentials cred = new StorageCredentials(todoItem.SasQueryString);

                // Instantiate a Blob store container based on the info in the returned item.
                CloudBlobContainer container = new CloudBlobContainer(
                    new Uri(string.Format("https://{0}/{1}",
                        todoItem.ImageUri.Host, todoItem.ContainerName)), cred);

                // Get the new local image as a stream.
                StorageFile media = await StorageFile.GetFileFromApplicationUriAsync(new Uri(todoItem.LocalImageUri));
                using (var inputStream = await media.OpenReadAsync())
                {
                    // Upload the new image as a BLOB from the stream.
                    CloudBlockBlob blobFromSASCredential =
                        container.GetBlockBlobReference(todoItem.ResourceName);
                    await blobFromSASCredential.UploadFromStreamAsync(inputStream);
                }

                // Clear the flag on the item and related fields
                todoItem.ImageUploadPending = false;
                todoItem.LocalImageUri = string.Empty;
                todoItem.SasQueryString = string.Empty;
                todoItem.ResourceName = string.Empty;

                // This code updates a TodoItem in the local database. 
                await todoTable.UpdateAsync(todoItem);

                await SyncAsync();
            }
        }
コード例 #7
0
        public async Task UpdateTodoItem(TodoItem todoItem)
        {
            if (todoItem.ImageUploadPending)
            {
                // Set blob properties of TodoItem.
                todoItem.ContainerName = "todoitemimages";

                // Use a unigue GUID to avoid collisions.
                todoItem.ResourceName = Guid.NewGuid().ToString();
            }

            // This code updates a TodoItem in the local database. 
            await todoTable.UpdateAsync(todoItem);

            await SyncWithImagesAsync(); // offline sync
        }
コード例 #8
0
            public async Task UpdateTodoItem(TodoItem todoItem)
            {
                // This code updates a TodoItem in the database. 
                await todoTable.UpdateAsync(todoItem);

                //await SyncAsync(); // offline sync
            }