/// <summary>
        /// Command for deleting a file.
        /// </summary>
        async void ExecuteDeleteCommandAsync()
        {
            bool deleteFile = await MessageDialogHelper.ShowYesNoDialogAsync(
                String.Format("Are you sure you want to delete '{0}'?", _selectedFileObject.Name), "Confirm deletion");

            if (deleteFile == true)
            {
                bool?isSuccess = await _fileOperations.DeleteFileOrFolderAsync(_selectedFileObject);



                if (isSuccess == true)
                {
                    await LoadFilesAndFoldersAsync();

                    LoggingViewModel.Instance.Information = "You successfully deleted the file or folder!";
                }
                else if (isSuccess == false)
                {
                    LoggingViewModel.Instance.Information = "The file or folder wasn't deleted.";
                }
                else
                {
                    LoggingViewModel.Instance.Information = "Please get the file and folder list, select an item, and try again.";
                }
            }

            else
            {
                LoggingViewModel.Instance.Information = "The file or folder wasn't deleted.";
            }
        }
        /// <summary>
        /// Command for deleting a file.
        /// </summary>
        async void ExecuteDeleteCommandAsync()
        {
            bool deleteFile = await MessageDialogHelper.ShowYesNoDialogAsync("Do you really want to delete this file or folder?", "Delete");

            if (deleteFile == true)
            {
                bool?isSuccess = await _fileOperations.DeleteFileOrFolderAsync(_selectedFileObject);

                ExecuteGetFileAndFolderListCommandAsync();


                if (isSuccess == true)
                {
                    LoggingViewModel.Instance.Information = "You successfully deleted the file or folder!";
                }
                else if (isSuccess == false)
                {
                    LoggingViewModel.Instance.Information = "The file or folder wasn't deleted.";
                }
                else
                {
                    LoggingViewModel.Instance.Information = "Please get the file and folder list, select an item, and try again.";
                }
            }

            else
            {
                LoggingViewModel.Instance.Information = "The file or folder wasn't deleted.";
            }
        }
        /// <summary>
        /// Sends event remove request to Exchange service
        /// </summary>
        async void ExecuteDeleteCommandAsync()
        {
            if (await MessageDialogHelper.ShowYesNoDialogAsync(String.Format("Are you sure you want to delete the event '{0}'?", this._selectedEvent.DisplayString), "Confirm Deletion"))
            {
                if (!String.IsNullOrEmpty(this._selectedEvent.Id))
                {
                    var success = await _calendarOperations.DeleteCalendarEventAsync(this._selectedEvent.Id);

                    if (success)
                    {
                        //Removes event from bound observable collection
                        Events.Remove((EventViewModel)_selectedEvent);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Sends event remove request to Exchange service
        /// </summary>
        async void ExecuteDeleteCommandAsync()
        {
            try
            {
                if (await MessageDialogHelper.ShowYesNoDialogAsync(String.Format("Are you sure you want to delete the event '{0}'?", this._selectedEvent.DisplayString), "Confirm Deletion"))
                {
                    if (!String.IsNullOrEmpty(this._selectedEvent.Id))
                    {
                        await _calendarOperations.DeleteCalendarEventAsync(this._selectedEvent.Id);
                    }

                    //Removes event from bound observable collection
                    TodaysEvents.Remove((EventViewModel)_selectedEvent);
                }
            }
            catch (Exception)
            {
                LoggingViewModel.Instance.Information = "We could not delete your calendar event";
            }
        }
 /// <summary>
 /// Sends mail item remove request to the Exchange service.
 /// </summary>
 async void ExecuteDeleteMailCommandAsync()
 {
     try
     {
         if (await MessageDialogHelper.ShowYesNoDialogAsync(String.Format("Are you sure you want to delete the mail item '{0}'?", this._selectedMail.Subject), "Confirm Deletion"))
         {
             if (!String.IsNullOrEmpty(this._selectedMail.ID))
             {
                 if (await _mailOperations.DeleteMailItemAsync(this._selectedMail.ID))
                 {
                     //Removes email from bound observable collection
                     MailItems.Remove((MailItemViewModel)_selectedMail);
                 }
             }
         }
     }
     catch (Exception)
     {
         LoggingViewModel.Instance.Information = "We could not delete your mail item.";
     }
 }
 /// <summary>
 /// Sends contact remove request to the Exchange service.
 /// </summary>
 async void ExecuteDeleteCommandAsync()
 {
     try
     {
         if (await MessageDialogHelper.ShowYesNoDialogAsync(String.Format("Are you sure you want to delete the contact '{0}'?", this._selectedContact.DisplayString), "Confirm Deletion"))
         {
             if (!String.IsNullOrEmpty(this._selectedContact.Id))
             {
                 if (await _contactsOperations.DeleteContactItemAsync(this._selectedContact.Id))
                 {
                     //Removes contact from bound observable collection
                     Contacts.Remove((ContactItemViewModel)_selectedContact);
                 }
             }
         }
     }
     catch (Exception)
     {
         LoggingViewModel.Instance.Information = "We could not delete your contact.";
     }
 }
        /// <summary>
        /// Command for downloading and viewing a file.
        /// </summary>
        async void ExecuteDownloadFileCommandAsync()
        {
            StorageFile downloadedFile = null;

            if (_selectedFileObject.FileSystemItem is Folder)
            {
                LoggingViewModel.Instance.Information = "We can't download a folder";
                return;
            }

            var stream = await _fileOperations.DownloadFileAsync(_selectedFileObject);

            // Save the file.
            FileSavePicker fsp = new FileSavePicker();

            fsp.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

            fsp.FileTypeChoices.Add("Text", new List <string>()
            {
                ".txt"
            });
            fsp.FileTypeChoices.Add("Word document", new List <string>()
            {
                ".docx"
            });
            fsp.FileTypeChoices.Add("Excel workbook", new List <string>()
            {
                ".xslx"
            });
            fsp.FileTypeChoices.Add("Powerpoint", new List <string>()
            {
                ".pptx"
            });
            fsp.FileTypeChoices.Add("XML", new List <string>()
            {
                ".xml"
            });
            fsp.FileTypeChoices.Add("JPEG", new List <string>()
            {
                ".jpg"
            });
            fsp.FileTypeChoices.Add("PNG", new List <string>()
            {
                ".png"
            });
            fsp.FileTypeChoices.Add("PDF", new List <string>()
            {
                ".pdf"
            });
            fsp.SuggestedFileName = _selectedFileObject.Name;

            StorageFile sFile = await fsp.PickSaveFileAsync();

            if (sFile != null && stream != null)
            {
                CachedFileManager.DeferUpdates(sFile);

                using (Stream s = await sFile.OpenStreamForWriteAsync())
                {
                    int count = 0;
                    do
                    {
                        var buffer = new byte[2048];
                        count = stream.Read(buffer, 0, 2048);
                        await s.WriteAsync(buffer, 0, count);
                    }while (stream.CanRead && count > 0);

                    await s.FlushAsync();
                }

                stream.Dispose();

                downloadedFile = sFile;
            }

            if (downloadedFile != null)
            {
                if (await MessageDialogHelper.ShowYesNoDialogAsync(String.Format("Your file was downloaded to {0}\nWould you like to open the file?", downloadedFile.Path), "Download Succeeded"))
                {
                    // Try to launch the default app for the file, so the user can see it
                    try
                    {
                        // Set the option to show the picker
                        var options = new Windows.System.LauncherOptions();
                        options.DisplayApplicationPicker = true;

                        await Windows.System.Launcher.LaunchFileAsync(downloadedFile, options);
                    }
                    catch (Exception)
                    {
                        // Fail silently
                    }
                }
            }
            else
            {
                LoggingViewModel.Instance.Information = "The file wasn't downloaded.";
            }
        }
        /// <summary>
        /// Command for downloading and viewing a file.
        /// </summary>
        async void ExecuteDownloadFileCommandAsync()
        {
            StorageFile destinationFile = null;

            if (_selectedFileObject.FileSystemItem is Folder)
            {
                LoggingViewModel.Instance.Information = String.Format("The item '{0}' is a folder and therefore can't be downloaded.", _selectedFileObject.Name);
                return;
            }

            using (var downloadStream = await _fileOperations.DownloadFileAsync(_selectedFileObject))
            {
                // Create the picker object and set options
                FileSavePicker picker = new FileSavePicker();
                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

                // Dropdown of file types the user can save the file as
                picker.FileTypeChoices.Add("Text", new List <string>()
                {
                    ".txt"
                });
                picker.FileTypeChoices.Add("Word document", new List <string>()
                {
                    ".docx"
                });
                picker.FileTypeChoices.Add("Excel workbook", new List <string>()
                {
                    ".xlsx"
                });
                picker.FileTypeChoices.Add("Powerpoint", new List <string>()
                {
                    ".pptx"
                });
                picker.FileTypeChoices.Add("XML", new List <string>()
                {
                    ".xml"
                });
                picker.FileTypeChoices.Add("JPEG", new List <string>()
                {
                    ".jpg"
                });
                picker.FileTypeChoices.Add("PNG", new List <string>()
                {
                    ".png"
                });
                picker.FileTypeChoices.Add("PDF", new List <string>()
                {
                    ".pdf"
                });

                // Default file name if the user does not type one in or select a file to replace
                picker.SuggestedFileName = _selectedFileObject.Name;

                destinationFile = await picker.PickSaveFileAsync();

                if (destinationFile != null && downloadStream != null)
                {
                    CachedFileManager.DeferUpdates(destinationFile);

                    using (Stream destinationStream = await destinationFile.OpenStreamForWriteAsync())
                    {
                        int count = 0;
                        do
                        {
                            var buffer = new byte[2048];
                            count = downloadStream.Read(buffer, 0, 2048);
                            await destinationStream.WriteAsync(buffer, 0, count);
                        }while (downloadStream.CanRead && count > 0);

                        await destinationStream.FlushAsync();
                    }
                }
            }

            if (destinationFile != null)
            {
                var viewFile = await MessageDialogHelper.ShowYesNoDialogAsync(
                    String.Format("Your file was downloaded to {0}\nWould you like to open the file?", destinationFile.Path), "Download Succeeded");

                if (viewFile)
                {
                    // Launch the selected app so the user can see the file contents.

                    // Let the user choose which app to use.
                    var options = new Windows.System.LauncherOptions();
                    options.DisplayApplicationPicker = true;

                    var success = await Windows.System.Launcher.LaunchFileAsync(destinationFile, options);

                    if (!success)
                    {
                        LoggingViewModel.Instance.Information = "We couldn't launch an app to view the file.";
                    }
                }
            }
            else
            {
                LoggingViewModel.Instance.Information = "The file wasn't downloaded.";
            }
        }