Пример #1
0
        public MainWindow()
        {
            InitializeComponent();

            UiDispatcher.Initialize();

            RestoreSettings();

            this.SizeChanged     += OnWindowSizeChanged;
            this.LocationChanged += OnWindowLocationChanged;

            Settings.Instance.PropertyChanged += OnSettingsPropertyChanged;
            Settings.Instance.Model.Items.CollectionChanged         += OnModelItemsChanged;
            Settings.Instance.Targets.TargetPaths.CollectionChanged += OnTargetItemsChanged;
            foreach (SourceFolder f in Settings.Instance.Model.Items)
            {
                f.PropertyChanged += OnSourceFolderPropertyChanged;
            }

            string filename = Settings.LogFile;

            if (File.Exists(filename))
            {
                LoadLogFile(filename);
            }

            System.Windows.Forms.Application.SetUnhandledExceptionMode(System.Windows.Forms.UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
            App.Current.DispatcherUnhandledException   += new DispatcherUnhandledExceptionEventHandler(OnDispatcherUnhandledException);
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

            this._log = new FlowDocumentLog(ConsoleTextBox);

            backup.AvailableBackupDrives.CollectionChanged += AvailableBackupDrives_CollectionChanged;
            this.monitorDrivesCanellation = new CancellationTokenSource();
            Task.Run(new Action(() =>
            {
                backup.MonitorBackupDrives(this.monitorDrivesCanellation.Token);
            }));

            if (Settings.Instance.Migrated)
            {
                this.DelayedSaveSettings();
            }
        }
Пример #2
0
        private void LoadLogFile(string filename)
        {
            List <string> lines = new List <string>();

            using (var reader = new StreamReader(filename))
            {
                string line = null;
                while ((line = reader.ReadLine()) != null)
                {
                    lines.Add(line);
                }
            }

            var flow = new FlowDocumentLog(ConsoleTextBox);

            foreach (string line in lines)
            {
                flow.WriteLine(line.Trim());
            }
        }