Esempio n. 1
0
        private void btnOpenFile_Click(object sender, RoutedEventArgs e)
        {
            if (SaveSettings())
            {
                return;
            }

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = AppHost.AppFileExt;
            dlg.Filter     = "EazyCopy files|*{0}".FormatString(AppHost.AppFileExt);

            var result = dlg.ShowDialog();

            if (result == true)
            {
                using (var x = new ChoWPFWaitCursor())
                {
                    _isNewFileOp     = true;
                    SettingsFilePath = dlg.FileName;
                    UnregisterEvents();
                    _appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
                    RegisterEvents();
                    this.DataContext = null;
                    this.DataContext = _appSettings;
                    IsDirty          = false;
                    _isNewFileOp     = false;
                }
            }
        }
Esempio n. 2
0
        private void MyWindow_Loaded(object sender1, RoutedEventArgs e1)
        {
            _bindObj     = new ChoWPFBindableConfigObject <ChoAppSettings>();
            _appSettings = _bindObj.UnderlyingSource;
            _appSettings.Init();
            if (!SettingsFilePath.IsNullOrWhiteSpace() && File.Exists(SettingsFilePath))
            {
                _appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
            }
            else
            {
                _appSettings.Reset();
            }

            DataContext   = this;
            _mainUIThread = Thread.CurrentThread;

            btnNewFile_Click(null, null);

            _dispatcherTimer          = new System.Windows.Threading.DispatcherTimer();
            _dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
            _dispatcherTimer.Start();

            string x = _appSettings.SourceDirectory;
            ChoShellExtCmdLineArgs cmdLineArgs = new ChoShellExtCmdLineArgs();

            if (!cmdLineArgs.Directory.IsNullOrWhiteSpace())
            {
                _appSettings.SourceDirectory = cmdLineArgs.Directory;
            }

            IsDirty = false;
        }
Esempio n. 3
0
 public ChoRoboCopyManager(string settingsFilePath = null)
 {
     if (settingsFilePath.IsNullOrWhiteSpace())
     {
         if (File.Exists(settingsFilePath))
         {
             string settingsText = File.ReadAllText(settingsFilePath);
             _appSettings.LoadXml(settingsText);
         }
     }
 }
        public void StartFileCopy(string sourceDirectory = null, string destDirectory = null)
        {
            try
            {
                ChoAppSettings appSettings = new ChoAppSettings();
                if (!SettingsFilePath.IsNullOrWhiteSpace())
                {
                    if (!File.Exists(SettingsFilePath))
                    {
                        throw new ArgumentException("Can't find '{0}' settings file.".FormatString(SettingsFilePath));
                    }

                    appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
                }

                ChoConsole.WriteLine();

                ChoRoboCopyManager _roboCopyManager = new ChoRoboCopyManager(SettingsFilePath);
                _roboCopyManager.Status += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };
                _roboCopyManager.AppStatus += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };

                _roboCopyManager.Process(appSettings.RoboCopyFilePath, appSettings.GetCmdLineParams(),
                                         appSettings, true);
            }
            catch (ThreadAbortException)
            {
                Console.WriteLine("RoboCopy operation cancelled by user.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("RoboCopy operation failed." + Environment.NewLine + ChoApplicationException.ToString(ex));
            }
        }
Esempio n. 5
0
        private void MyWindow_Loaded(object sender1, RoutedEventArgs e1)
        {
            _bindObj     = new ChoWPFBindableConfigObject <ChoAppSettings>();
            _appSettings = _bindObj.UnderlyingSource;
            _appSettings.Init();
            if (!SettingsFilePath.IsNullOrWhiteSpace() && File.Exists(SettingsFilePath))
            {
                _appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
            }
            else
            {
                _appSettings.Reset();
            }

            this.DataContext = _appSettings;
            _appSettings.BeforeConfigurationObjectLoaded += ((o, e) =>
            {
                e.Cancel = (bool)this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                                        new Func <bool>(() =>
                {
                    if (IsDirty)
                    {
                        if (MessageBox.Show("Configuration settings has been modified outside of the tool. {0}Do you want to reload it and lose the changes made in the tool?".FormatString(Environment.NewLine),
                                            Title, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                        {
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }

                    return(false);
                }));
            });

            _appSettings.AfterConfigurationObjectMemberSet += ((o, e) =>
            {
                if (_wndLoaded)
                {
                    IsDirty = true;
                }
                this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                            new Action(() =>
                {
                    txtRoboCopyCmd.Text = _appSettings.GetCmdLineText();
                }));
            });

            _appSettings.ConfigurationObjectMemberLoadError += _appSettings_ConfigurationObjectMemberLoadError;
            _appSettings.AfterConfigurationObjectPersisted  += _appSettings_AfterConfigurationObjectPersisted;
            _appSettings.AfterConfigurationObjectLoaded     += ((o, e) =>
            {
                if (_wndLoaded)
                {
                    this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new Action(() =>
                    {
                        this.DataContext = null;
                        this.DataContext = _appSettings;
                        txtRoboCopyCmd.Text = _appSettings.GetCmdLineText();
                        IsDirty = false;
                    }));
                }
                else
                {
                    this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new Action(() =>
                    {
                        txtRoboCopyCmd.Text = _appSettings.GetCmdLineText();
                    }));
                }
            });

            _mainUIThread = Thread.CurrentThread;

            _dispatcherTimer          = new System.Windows.Threading.DispatcherTimer();
            _dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);
            _dispatcherTimer.Start();

            string x = _appSettings.SourceDirectory;
            ChoShellExtCmdLineArgs cmdLineArgs = new ChoShellExtCmdLineArgs();

            if (!cmdLineArgs.Directory.IsNullOrWhiteSpace())
            {
                _appSettings.SourceDirectory = cmdLineArgs.Directory;
            }

            IsDirty = false;
        }