Ejemplo n.º 1
0
        public async void Execute(object parameter)
        {
            BucketEntryViewModel bucketEntryVM = parameter as BucketEntryViewModel;

            ContentDialog cancelObjectUploadDialog = new ContentDialog
            {
                Title             = "Cancel '" + bucketEntryVM.UploadOperation.ObjectName + "'",
                Content           = "Do you really want to cancel the upload of '" + bucketEntryVM.UploadOperation.ObjectName + "' ?",
                CloseButtonText   = "No",
                PrimaryButtonText = "Yes"
            };

            ContentDialogResult result = await cancelObjectUploadDialog.ShowAsync();

            if (result != ContentDialogResult.Primary)
            {
                return;
            }
            bucketEntryVM.UploadOperation.Cancel();
            try
            {
                BucketContentViewModel.ActiveUploadOperations[bucketEntryVM._bucketContentViewModel.BucketName].Remove(bucketEntryVM.UploadOperation);
            }
            catch
            {
                //Ignore any error
            }

            await bucketEntryVM._bucketContentViewModel.RefreshAsync();
        }
Ejemplo n.º 2
0
        public async void Execute(object parameter)
        {
            BucketEntryViewModel bucketEntryVM = parameter as BucketEntryViewModel;

            ContentDialog deleteObjectDialog = new ContentDialog
            {
                Title             = "Delete '" + bucketEntryVM.ObjectInfo.Key + "'",
                Content           = "Do you really want to delete the object '" + bucketEntryVM.ObjectInfo.Key + "' ?",
                CloseButtonText   = "No",
                PrimaryButtonText = "Yes"
            };

            ContentDialogResult result = await deleteObjectDialog.ShowAsync();

            if (result != ContentDialogResult.Primary)
            {
                return;
            }
            try
            {
                var bucket = await _bucketService.GetBucketAsync(bucketEntryVM._bucketContentViewModel.BucketName);

                await _objectService.DeleteObjectAsync(bucket, bucketEntryVM.ObjectInfo.Key);
            }
            catch (Exception ex)
            {
                Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Could not delete object - " + ex.Message);
                await dialog.ShowAsync();

                return;
            }

            await bucketEntryVM._bucketContentViewModel.RefreshAsync();
        }
Ejemplo n.º 3
0
        public async void Execute(object parameter)
        {
            BucketEntryViewModel bucketEntryVM = parameter as BucketEntryViewModel;

            if (bucketEntryVM.IsDownloadOperation)
            {
                Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(bucketEntryVM.DownloadOperation.ErrorMessage);
                await dialog.ShowAsync();
            }
            else if (bucketEntryVM.IsUploadOperation)
            {
                Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(bucketEntryVM.UploadOperation.ErrorMessage);
                await dialog.ShowAsync();
            }
        }
Ejemplo n.º 4
0
        public async void Execute(object parameter)
        {
            BucketEntryViewModel bucketEntryVM = parameter as BucketEntryViewModel;

#if !__ANDROID__
            FileSavePicker picker = new FileSavePicker();
            if (bucketEntryVM.ObjectInfo.Key.Contains("mp4"))
            {
                picker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
                picker.FileTypeChoices.Add("Video", new List <string>()
                {
                    ".mp4"
                });
            }
            else
            {
                picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                picker.FileTypeChoices.Add("Image", new List <string>()
                {
                    ".jpg"
                });
            }

            picker.SuggestedFileName = bucketEntryVM.ObjectInfo.Key;


            var file = await picker.PickSaveFileAsync();

            if (file == null)
            {
                return;
            }

            Windows.Storage.CachedFileManager.DeferUpdates(file);

            try
            {
                var bucket = await _bucketService.GetBucketAsync(bucketEntryVM._bucketContentViewModel.BucketName);

                var downloadOperation = await _objectService.DownloadObjectAsync(bucket, bucketEntryVM.ObjectInfo.Key, new DownloadOptions()
                {
                }, false);

                downloadOperation.DownloadOperationEnded += async(operation) =>
                {
                    if (!operation.Failed && !operation.Cancelled)
                    {
                        await Windows.Storage.FileIO.WriteBytesAsync(file, operation.DownloadedBytes);

                        var status = await CachedFileManager.CompleteUpdatesAsync(file);
                    }
                };
                downloadOperation.StartDownloadAsync();
                if (BucketContentViewModel.ActiveDownloadOperations.ContainsKey(_bucketName))
                {
                    BucketContentViewModel.ActiveDownloadOperations[_bucketName].Add(downloadOperation);
                }
                else
                {
                    var list = new List <DownloadOperation>();
                    list.Add(downloadOperation);
                    BucketContentViewModel.ActiveDownloadOperations.Add(_bucketName, list);
                }
                _senderView.AddDownloadOperation(downloadOperation);
            }
            catch (Exception ex)
            {
                Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Could not download object - " + ex.Message);
                await dialog.ShowAsync();

                return;
            }
#else
            var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

            try
            {
                var bucket = await _bucketService.GetBucketAsync(bucketEntryVM._bucketContentViewModel.BucketName);

                var downloadOperation = await _objectService.DownloadObjectAsync(bucket, bucketEntryVM.ObjectInfo.Key, new DownloadOptions(), true);

                downloadOperation.DownloadOperationEnded += async(operation) =>
                {
                    if (!operation.Failed && !operation.Cancelled)
                    {
                        string filePath = Path.Combine(path, "Download");
                        if (!Directory.Exists(filePath))
                        {
                            Directory.CreateDirectory(filePath);
                        }

                        filePath = Path.Combine(filePath, "Storj");
                        if (!Directory.Exists(filePath))
                        {
                            Directory.CreateDirectory(filePath);
                        }
                        filePath = Path.Combine(filePath, bucketEntryVM.ObjectInfo.Key);
                        using (FileStream fs = new FileStream(filePath, FileMode.Create))
                        {
                            await fs.WriteAsync(operation.DownloadedBytes, 0, (int)operation.TotalBytes);
                        }
                    }
                };
                if (BucketContentViewModel.ActiveDownloadOperations.ContainsKey(_bucketName))
                {
                    BucketContentViewModel.ActiveDownloadOperations[_bucketName].Add(downloadOperation);
                }
                else
                {
                    var list = new List <DownloadOperation>();
                    list.Add(downloadOperation);
                    BucketContentViewModel.ActiveDownloadOperations.Add(_bucketName, list);
                }
                _senderView.AddDownloadOperation(downloadOperation);
            }
            catch (Exception ex)
            {
                Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Could not download object - " + ex.Message);
                await dialog.ShowAsync();

                return;
            }
#endif
        }