예제 #1
0
        private async Task getFileFromBackupFolderAsync()
        {
            try
            {
                LiveConnectClient liveClient = new LiveConnectClient(oneDriveAuthClient.Session);
                var queryFiles = oneDriveFolderId + "/files";
                var operation  = await liveClient.GetAsync(queryFiles);

                var items = operation.Result["data"] as List <object>;
                BackupfileCollection = new ObservableCollection <Backupfile>();

                foreach (object item in items)
                {
                    IDictionary <string, object> file = item as IDictionary <string, object>;
                    if (file["name"].ToString().EndsWith(".sdf"))
                    {
                        Backupfile bFile = new Backupfile();
                        bFile.FileID   = file["id"].ToString();
                        bFile.Filename = file["name"].ToString();
                        bFile.FileType = file["type"].ToString();
                        BackupfileCollection.Add(bFile);
                    }
                }
            }
            catch (LiveConnectException ex)
            {
                App.AppViewModel.SendExceptionReport(ex);
            }
        }
예제 #2
0
        public async Task RestoreBackupfile(Backupfile file)
        {
            RestoreLock = true;
            string tmpPathDatabase = "downloadedDatabase.sdf";
            //release all resources from DB

            LiveConnectClient liveClient = new LiveConnectClient(oneDriveAuthClient.Session);

            try
            {
                LiveDownloadOperationResult downloadResult = await liveClient.DownloadAsync(file.FileID + "/content");

                using (Stream downloadStream = downloadResult.Stream)
                {
                    if (downloadStream != null)
                    {
                        using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            using (IsolatedStorageFileStream output = storage.CreateFile(tmpPathDatabase))
                            {
                                // Initialize the buffer.
                                byte[] readBuffer = new byte[4096];
                                int    bytesRead  = -1;

                                // Copy the file from the installation folder to the local folder.
                                while ((bytesRead = downloadStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                                {
                                    output.Write(readBuffer, 0, bytesRead);
                                }
                            }
                        }
                    }
                }
                MessageBox.Show("Download successful. Restore started.");

                IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

                App.AppViewModel.RestoreDatabase(tmpPathDatabase);

                if (iso.FileExists(tmpPathDatabase))
                {
                    iso.DeleteFile(tmpPathDatabase);
                }

                MessageBox.Show("Restore succesfull.");
                RestoreLock = false;
            }
            catch (LiveConnectException ex)
            {
                App.AppViewModel.SendExceptionReport(ex);
                RestoreLock = false;
            }
        }
예제 #3
0
        private async void fileRestoreButton_Click(object sender, RoutedEventArgs e)
        {
            this.LoadingPanel.Visibility = Visibility.Visible;
            var button = sender as Button;

            if (button != null)
            {
                Backupfile file = button.DataContext as Backupfile;

                MessageBoxButton buttons = MessageBoxButton.OKCancel;
                MessageBoxResult result  = MessageBox.Show("Are you sure to restore the database with the backupfile " + file.Filename
                                                           + " ? All data in the recent database will be lossed. Best backup them before restore.", "", buttons);

                if (result == MessageBoxResult.OK)
                {
                    MessageBox.Show("Don't close the app nor navigate back or to the home screen. This can cause data loss.");
                    await backupViewModel.RestoreBackupfile(file);

                    // Put the focus back to the main page.
                    this.Focus();
                }
            }
            this.LoadingPanel.Visibility = Visibility.Collapsed;
        }