示例#1
0
        private async void Restore()
        {
            StartProgress = true;
            BlackBox      = Visibility.Visible;
            var t = Task.Run(() =>
            {
                string downloadfolder = AppDomain.CurrentDomain.BaseDirectory + @"download\";

                try
                {
                    string backupfile = downloadfolder + SelectedItem;

                    if (!System.IO.Directory.Exists(downloadfolder))
                    {
                        System.IO.Directory.CreateDirectory(downloadfolder);
                    }

                    string restorefolder = ConnectionString;

                    if (ConnectionString == @"|DataDirectory|\DataBase\")
                    {
                        restorefolder = AppDomain.CurrentDomain.BaseDirectory + @"DataBase\";
                    }

                    System.IO.File.Copy(BackupPath + @"\" + SelectedItem, backupfile, true);
                    Compress.DecompressDirectory(BackupPath + @"\" + SelectedItem, restorefolder, null);
                }
                catch (Exception ex)
                {
                    Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate {
                        AsyncMessageBox(ex.Message, DialogBoxColor.Red, false);
                    }));
                }
                finally
                {
                    System.IO.Directory.Delete(downloadfolder, true);
                    StartProgress = false;
                    BlackBox      = Visibility.Collapsed;
                }
            });

            await t;

            if (t.IsCompleted)
            {
                AsyncMessageBox("Backup restaurado!", DialogBoxColor.Green, false);
            }
            else
            {
                AsyncMessageBox("Backup NÃO restaurado!", DialogBoxColor.Red, false);
            }
        }