Exemple #1
0
        /// <summary>
        /// Save selected button handler
        /// </summary>
        private async void SaveSelectedDrivers()
        {
            //Update Drivers for backup count property
            MaximumProgress = DriversForBackpCount;
            MessageDialog   = null;
            //check for empty selection
            if (!Drivers.Any(x => x.IsSelected))
            {
                MessageDialog =
                    new MessageDialogViewModel(new ObservableCollection <ActionButton>(new List <ActionButton>()
                {
                    new ActionButton(StringResources.OK,
                                     () => { MessageDialog = null; }, ActionButton.ButtonType.Deafult)
                }), StringResources.NothingToSave, StringResources.NoDriversSelected);
                return;
            }

            var folder = new FolderBrowserDialog();

            if (folder.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string path = folder.SelectedPath;

            Progress             = 0;
            ShowInProgressDialog = true;
            InProgressTest       = StringResources.SavingDriversDots;
            cts = new CancellationTokenSource();

            await SaveDriversAsync(Drivers.Where(x => x.IsSelected), path, cts.Token);
        }
Exemple #2
0
        private void OpenOutputFolder(string path)
        {
            //Handle: Folder might have been compressed to zip - check and handle
            if (Directory.Exists(path))
            {
                Process.Start(path);
            }

            //older is a zip
            else if (File.Exists(path + ".zip"))
            {
                MessageDialog =
                    new MessageDialogViewModel(
                        new ObservableCollection <ActionButton>()
                {
                    new ActionButton(StringResources.OK, () => MessageDialog = null,
                                     ActionButton.ButtonType.Accept)
                },
                        StringResources.FolderCannotBeOpened, StringResources.FolderCannotBeOpenedLong);
            }

            //not found
            else
            {
                MessageDialog =
                    new MessageDialogViewModel(
                        new ObservableCollection <ActionButton>()
                {
                    new ActionButton(StringResources.OK, () => MessageDialog = null,
                                     ActionButton.ButtonType.Accept)
                },
                        StringResources.FolderCannotBeOpened, StringResources.FolderNotFound);
            }
        }
Exemple #3
0
        private async Task SaveDriversAsync(IEnumerable <DriverInformation> drivers, string path, CancellationToken ct)
        {
            await Task.Run(async() =>
            {
                try
                {
                    var controller = new DriverBackup();
                    foreach (var t in drivers)
                    {
                        //Backup drivers one by one on background thread and show progress to the user
                        await controller.BackupDriverAsync(t, path);
                        await
                        Application.Current.Dispatcher.BeginInvoke(
                            DispatcherPriority.Background,
                            new Action(() => Progress++));
                        ct.ThrowIfCancellationRequested();
                    }

                    //Cancellation token for zipping
                    cts = new CancellationTokenSource();

                    //Zip folder if user wants it automatically
                    if (AppSettings.ZipRootFolder)
                    {
                        await CompressFolderAsZip(path);
                    }

                    //Alert user when the job is done
                    MessageDialog =
                        new MessageDialogViewModel(
                            new ObservableCollection <ActionButton>(new List <ActionButton>
                    {
                        new ActionButton(StringResources.OK,
                                         () => MessageDialog = null,
                                         ActionButton.ButtonType.Accept),
                        new ActionButton(StringResources.OpenFolder,
                                         () => OpenOutputFolder(path),
                                         ActionButton.ButtonType.Deafult),
                    }),
                            StringResources.DriversSaved, StringResources.DriversSavedLong);

                    //Add compress folder as zip button if it is not automatic
                    if (!AppSettings.ZipRootFolder)
                    {
                        MessageDialog.ActionButtons.Add(
                            new ActionButton(StringResources.ZipFolder,
                                             async() =>
                        {
                            MessageDialog = null;
                            await CompressFolderAsZip(path);
                        }, ActionButton.ButtonType.Deafult));
                    }
                }
                catch (OperationCanceledException)
                {
                    //Canceled by user
                    MessageDialog =
                        new MessageDialogViewModel(
                            new ObservableCollection <ActionButton>(new List <ActionButton>
                    {
                        new ActionButton(StringResources.OK, () => MessageDialog = null,
                                         ActionButton.ButtonType.Accept)
                    }),
                            StringResources.SavingCanceled);
                }

                catch (Exception e)
                {
                    //Let user know about the error
                    MessageDialog =
                        new MessageDialogViewModel(
                            new ObservableCollection <ActionButton>(new List <ActionButton>
                    {
                        new ActionButton(StringResources.OK, () => MessageDialog = null,
                                         ActionButton.ButtonType.Accept)
                    }),
                            StringResources.Error, e.Message);
                }
                finally
                {
                    ShowInProgressDialog = false;
                }
            }, ct);
        }