Пример #1
0
            public void Execute(object parameter)
            {
                ContinuousProgressWindow progressWindow =
                    new ContinuousProgressWindow("Removing record info from Google Drive");
                BackgroundWorker backgroundWorker = new BackgroundWorker();
                backgroundWorker.DoWork += new DoWorkEventHandler(
                    (Object sender, DoWorkEventArgs eventArgs) =>
                    {
                        Task<String> recordRemovalTask =
                            CloudFileTrackingAggregatorSingleton.
                            Instance.
                            TryRemoveRecordFromGoogleDrive(_viewModel._selectedRecordEntity);
                        recordRemovalTask.Wait();
                    });
                backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                    (Object sender, RunWorkerCompletedEventArgs eventArgs) =>
                    {
                        _viewModel._fileRecordEntities.Remove(_viewModel._selectedRecordEntity);
                        _viewModel._parentWindow.IsEnabled = true;
                        progressWindow.Close();

                    });
                _viewModel._parentWindow.IsEnabled = false;
                progressWindow.Show();
                backgroundWorker.RunWorkerAsync();
            }
Пример #2
0
 public void Execute(object parameter)
 {
     DiffStampDescriptionWindow diffStampDescriptionWindow =
         new DiffStampDescriptionWindow();
     String diffStampDescription = diffStampDescriptionWindow.ShowDialog();
     if (diffStampDescription == default(String))
     {
         //Cancelled by user
     }
     else
     {
         ContinuousProgressWindow progressWindow =
             new ContinuousProgressWindow("Making snapshot and uploading");
         Window currentWindow = _viewModel._parentWindow;
         BackgroundWorker backgroundWorker = new BackgroundWorker();
         backgroundWorker.DoWork += new DoWorkEventHandler(
             (Object sender, DoWorkEventArgs eventArgs) =>
             {
                 FileEntityAggregator seletedRecord = _viewModel.SelectedRecordEntity;
                 Task<FileEntityAggregator> diffStampTask =
                     CloudFileTrackingAggregatorSingleton.
                     Instance.
                     TryMakeAndUploadDiffStamp(seletedRecord, diffStampDescription);
                 diffStampTask.Wait();
                 seletedRecord.RefreshRecord();
             });
         backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
             (Object sender, RunWorkerCompletedEventArgs eventArgs) =>
             {
                 currentWindow.IsEnabled = true;
                 progressWindow.Close();
             });
         currentWindow.IsEnabled = false;
         progressWindow.Show();
         backgroundWorker.RunWorkerAsync();
     }
 }
Пример #3
0
 public void Execute(object parameter)
 {
     Window parentWindow = _viewModel._parentWindow;
     CommonOpenFileDialog commonOpenFileDialog =
         new CommonOpenFileDialog("Select file(s) for tracking");
     commonOpenFileDialog.Multiselect = true;
     WindowInteropHelper currentWindowHelper =
         new WindowInteropHelper(parentWindow);
     CommonFileDialogResult dialogResult =
         commonOpenFileDialog.ShowDialog(currentWindowHelper.Handle);
     if (dialogResult == CommonFileDialogResult.Ok)
     {
         foreach (String localFilePath in commonOpenFileDialog.FileNames)
         {
             Boolean isAlreadyAdded =
                 CloudFileTrackingAggregatorSingleton.
                 IsLocalFileAddedForTracking(
                     _viewModel._fileRecordEntities,
                     localFilePath);
             if (!isAlreadyAdded)
             {
                 ContinuousProgressWindow progressWindow =
                     new ContinuousProgressWindow(
                         String.Format("Uploading {0}", Path.GetFileName(localFilePath)));
                 BackgroundWorker backgroundWorker = new BackgroundWorker();
                 backgroundWorker.DoWork += new DoWorkEventHandler(
                     (Object sender, DoWorkEventArgs eventArgs) =>
                     {
                         Task<FileEntityAggregator> fileUploadTask =
                             CloudFileTrackingAggregatorSingleton.
                             Instance.
                             TryAddLocalFileForTracking(localFilePath);
                         fileUploadTask.Wait();
                         eventArgs.Result = fileUploadTask.Result;
                     });
                 backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                     (Object sender, RunWorkerCompletedEventArgs eventArgs) =>
                     {
                         _viewModel._fileRecordEntities.Add(eventArgs.Result as FileEntityAggregator);
                         parentWindow.IsEnabled = true;
                         progressWindow.Close();
                     });
                 parentWindow.IsEnabled = false;
                 progressWindow.Show();
                 backgroundWorker.RunWorkerAsync();
             }
         }
     }
 }
Пример #4
0
 public void Execute(object parameter)
 {
     FileDialog saveFileDialog = new SaveFileDialog();
     saveFileDialog.FileName = _viewModel._fileEntityAggregator.FileName;
     saveFileDialog.Title = "Save specific version";
     Boolean? saveFileDialogResult = saveFileDialog.ShowDialog(_viewModel._parentWindow);
     if (saveFileDialogResult == true)
     {
         ContinuousProgressWindow progressWindow =
             new ContinuousProgressWindow("Downloading and applying patches");
         BackgroundWorker backgroundWorker = new BackgroundWorker();
         backgroundWorker.DoWork += new DoWorkEventHandler(
             (Object sender, DoWorkEventArgs eventArgs) =>
             {
                 Task<Byte[]> latestFileVersionTask = default(Task<Byte[]>);
                 try
                 {
                     latestFileVersionTask =
                         CloudFileTrackingAggregatorSingleton.
                         Instance.
                         TryGetFilePatchedUntilDateTime(
                             _viewModel._fileEntityAggregator,
                             _viewModel._selectedDiffStamp.DateTimeCreated);
                     latestFileVersionTask.Wait();
                     IO.FileStream fileStream = default(IO.FileStream);
                     try
                     {
                         fileStream = new IO.FileStream(saveFileDialog.FileName, IO.FileMode.Create);
                         Byte[] fileData = latestFileVersionTask.Result;
                         fileStream.Write(fileData, 0, fileData.Length);
                     }
                     catch (Exception)
                     {
                         MessageBox.Show(
                         "Failed to save file",
                         "Error while saving a file");
                     }
                     finally
                     {
                         fileStream.Dispose();
                     }
                 }
                 catch(Exception)
                 {
                     MessageBox.Show(
                         "Failed to download or patch file",
                         "Error while downloading and patching");
                 }
             });
         backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
             (Object sender, RunWorkerCompletedEventArgs eventArgs) =>
             {
                 _viewModel._parentWindow.IsEnabled = true;
                 progressWindow.Close();
             });
         _viewModel._parentWindow.IsEnabled = false;
         progressWindow.Show();
         backgroundWorker.RunWorkerAsync();
     }
     else
     {
         //Cancelled by user
     }
 }
Пример #5
0
 private void ResolveApplicationInitialization()
 {
     //Background operations must coordinate the UI thread to invoke
     CloudFileTrackingAggregatorSingleton.Instance.CurentUIThreadInvoker = _parentWindow;
     ContinuousProgressWindow progressWindow = new ContinuousProgressWindow("Loading file records");
     BackgroundWorker backgroundWorker = new BackgroundWorker();
     backgroundWorker.DoWork += new DoWorkEventHandler(
         (Object sender, DoWorkEventArgs eventArgs) =>
         {
             Task <List<FileEntityAggregator>> entitiesListTask =
                 CloudFileTrackingAggregatorSingleton.
                 Instance.
                 TryInitializeGoogleDriveFileRecords();
             entitiesListTask.Wait();
             IList<FileEntityAggregator> fileEntitiesList = entitiesListTask.Result;
             foreach (FileEntityAggregator fileEntity in fileEntitiesList)
             {
                 _fileEntities.Add(fileEntity);
             }
         });
     backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
         (Object sender, RunWorkerCompletedEventArgs eventArgs) =>
         {
             _trayAdapter.ShowInfoMessage(
                 "Files Time Machine For Google Drive",
                 "The application has loaded");
             _parentWindow.IsEnabled = true;
             progressWindow.Close();
         });
     _parentWindow.IsEnabled = false;
     progressWindow.Show();
     backgroundWorker.RunWorkerAsync();
 }
Пример #6
0
 public void Drop(Object sender, DragEventArgs eventArguments)
 {
     IDataObject draggedObject = eventArguments.Data;
     Object draggedItems = draggedObject.GetData(DataFormats.FileDrop, false);
     String[] pathsToItems = draggedItems as String[];
     DragEnterNotifierVisibility = Visibility.Collapsed;
     foreach (String localFilePath in pathsToItems)
     {
         Boolean isAlreadyAdded =
                     CloudFileTrackingAggregatorSingleton.
                     IsLocalFileAddedForTracking(
                         _fileEntities,
                         localFilePath);
         if (!isAlreadyAdded)
         {
             ContinuousProgressWindow progressWindow =
                 new ContinuousProgressWindow(
                     String.Format("Uploading {0}", IO.Path.GetFileName(localFilePath)));
             BackgroundWorker backgroundWorker = new BackgroundWorker();
             backgroundWorker.DoWork += new DoWorkEventHandler(
                 (Object bwsender, DoWorkEventArgs eventArgs) =>
                 {
                     Task<FileEntityAggregator> fileUploadTask =
                         CloudFileTrackingAggregatorSingleton.
                         Instance.
                         TryAddLocalFileForTracking(localFilePath);
                     fileUploadTask.Wait();
                     eventArgs.Result = fileUploadTask.Result;
                 });
             backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                 (Object bwsender, RunWorkerCompletedEventArgs eventArgs) =>
                 {
                     _fileEntities.Add(eventArgs.Result as FileEntityAggregator);
                     _parentWindow.IsEnabled = true;
                     progressWindow.Close();
                 });
             _parentWindow.IsEnabled = false;
             progressWindow.Show();
             backgroundWorker.RunWorkerAsync();
         }
     }
 }