Exemplo n.º 1
0
 public DetailsWindow(SyncPair initialPair)
 {
     InitializeComponent();
     cbMonitoring.DataContext = SyncMonitoring.Strategies;
     cbBackup.DataContext     = SyncBackup.BackupModes;
     this.EditedPair          = initialPair;
 }
Exemplo n.º 2
0
        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command.Equals(ApplicationCommands.Open))
            {
                SyncPair      edited  = e.Parameter as SyncPair;
                DetailsWindow details = new DetailsWindow(edited);
                details.Owner = this;
                if (details.ShowDialog() == true)
                {
                    pairList.Remove(edited);
                    pairList.Add(details.EditedPair);
                }
            }
            else if (e.Command.Equals(ApplicationCommands.Delete))
            {
                SyncPair pair = e.Parameter as SyncPair;

                if (MessageBox.Show(String.Format(Properties.Resources.DeletePairFormat, pair.LocalPath, pair.RemotePath),
                                    Properties.Resources.DeletePairTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
                {
                    pair.IsEnabled = false;
                    pair.ClearMetadata();
                    pairList.Remove(pair);
                    StatusText = Properties.Resources.StatusDeleted;
                }
            }
            else if (e.Command.Equals(ApplicationCommands.New))
            {
                DetailsWindow details = new DetailsWindow(null);
                details.Owner = this;
                if (details.ShowDialog() == true)
                {
                    pairList.Add(details.EditedPair);
                    StatusText = Properties.Resources.StatusAdded;
                }
            }
            else if (e.Command.Equals(ApplicationCommands.Close))
            {
                this.Close();
            }
            else if (e.Command.Equals(ApplicationCommands.Stop))
            {
                cbPauseActivities_Checked(null, null);
            }
            else if (e.Command.Equals(ApplicationCommands.Help))
            {
                AboutWindow about = new AboutWindow();
                about.Owner = this;
                about.ShowDialog();
            }
            else if (e.Command.Equals(ApplicationCommands.Redo))
            {
                SyncPair pair = e.Parameter as SyncPair;
                if ((pair != null) && (!pair.IsEnabled))
                {
                    pair.IsEnabled = true;
                    StatusText     = Properties.Resources.StatusStarted;
                }
            }
        }
Exemplo n.º 3
0
        public static ObservableCollection <SyncPair> LoadPairs()
        {
            object listLock = new object();

            try
            {
                RegistryKey pairsBranch = Registry.CurrentUser.OpenSubKey(sPairsBranch, true);

                ObservableCollection <SyncPair> pairs = new ObservableCollection <SyncPair>();

                if (pairsBranch != null)
                {
                    Parallel.ForEach(pairsBranch.GetValueNames(), key =>
                    {
                        try
                        {
                            SyncPair pair = new SyncPair(pairsBranch.GetValue(key, String.Empty).ToString());
                            lock (listLock) { pairs.Add(pair); }
                        }
                        catch (Exception ex)
                        {
                            Log.Write(ex);
                        }
                    });
                }

                return(pairs);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return(null);
            }
        }
Exemplo n.º 4
0
 private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
 {
     if ((e.Command.Equals(ApplicationCommands.Delete)) || (e.Command.Equals(ApplicationCommands.Open)))
     {
         SyncPair pair = e.Parameter as SyncPair;
         e.CanExecute = (pair != null);
     }
     else if ((e.Command.Equals(ApplicationCommands.New)) || (e.Command.Equals(ApplicationCommands.Close)) || (e.Command.Equals(ApplicationCommands.Stop)) ||
              (e.Command.Equals(ApplicationCommands.Help)))
     {
         e.CanExecute = true;
     }
     else if (e.Command.Equals(ApplicationCommands.Redo))
     {
         SyncPair pair = e.Parameter as SyncPair;
         e.CanExecute = ((pair != null) && (!pair.IsEnabled));
     }
 }
Exemplo n.º 5
0
        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command.Equals(ApplicationCommands.Save))
            {
                if (!Directory.Exists(tbSourceFolder.Text))
                {
                    if (MessageBox.Show(String.Format(Properties.Resources.SourceFolderDoesNotExistFormat, tbSourceFolder.Text),
                                        Properties.Resources.FolderDoesNotExistTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
                    {
                        return;
                    }
                }

                if (!Directory.Exists(tbDestinationFolder.Text))
                {
                    if (MessageBox.Show(String.Format(Properties.Resources.DestinationFolderDoesNotExistFormat, tbDestinationFolder.Text),
                                        Properties.Resources.FolderDoesNotExistTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
                    {
                        return;
                    }
                }

                if ((!(cbBackup.SelectedItem as SyncBackupMode).ID.Equals(SyncBackup.BACKUP_NOBACKUPS)) &&
                    (!Directory.Exists(tbBackupFolder.Text)))
                {
                    if (MessageBox.Show(String.Format(Properties.Resources.BackupFolderDoesNotExistFormat, tbBackupFolder.Text),
                                        Properties.Resources.FolderDoesNotExistTitle, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
                    {
                        return;
                    }
                }

                SyncMonitoringStrategy strategy   = cbMonitoring.SelectedItem as SyncMonitoringStrategy;
                SyncBackupMode         backupMode = cbBackup.SelectedItem as SyncBackupMode;

                if (this.EditedPair == null)
                {
                    this.DialogResult = true;
                    this.EditedPair   = new SyncPair(tbSourceFolder.Text, tbDestinationFolder.Text, strategy.ID, backupMode.ID, tbBackupFolder.Text);
                }
                else
                {
                    if ((!tbSourceFolder.Text.Equals(this.EditedPair.LocalPath)) || (!tbDestinationFolder.Text.Equals(this.EditedPair.RemotePath)) ||
                        (!strategy.Equals(this.EditedPair.Strategy)) || (!backupMode.Equals(this.EditedPair.BackupMode)) ||
                        ((String.IsNullOrEmpty(tbBackupFolder.Text)) && (!String.IsNullOrEmpty(this.EditedPair.BackupPath))) ||
                        (!tbBackupFolder.Text.Equals(this.EditedPair.BackupPath)))
                    {
                        // there are changes in definitions, need to recreate the pair
                        this.EditedPair.IsEnabled = false; // stopping original pair
                        this.EditedPair.ClearMetadata();   // remove old metadata files

                        this.DialogResult = true;
                        this.EditedPair   = new SyncPair(tbSourceFolder.Text, tbDestinationFolder.Text, strategy.ID, backupMode.ID, tbBackupFolder.Text);
                    }
                }
                this.EditedPair.IsEnabled = (cbEnabled.IsChecked.HasValue ? cbEnabled.IsChecked.Value : false);
                this.Close();
            }
            else if (e.Command.Equals(ApplicationCommands.Close))
            {
                this.Close();
            }
            else if (e.Command.Equals(ApplicationCommands.Open))
            {
                TextBox target = e.Parameter as TextBox;
                System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    target.Text = dialog.SelectedPath;
                }
            }
        }