Пример #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            DispatcherUnhandledException += App_DispatcherUnhandledException;

            Program program = null;

            if (e.Args.Length >= 1)
            {
                try
                {
                    program = Program.Load(e.Args[0]);
                }
                catch (Exception ex)
                {
                    CommonExceptionHandlers.HandleException(null, ex);
                }
            }
            if (program == null)
            {
                program = new Program();
            }

            AppState.Program = program;

            MainWindow mainWindow = new MainWindow();

            mainWindow.Show();
        }
Пример #2
0
        void OnApplicationStartup(object sender, StartupEventArgs e)
        {
            DispatcherUnhandledException += App_DispatcherUnhandledException;

            Program program = null;

            if (e.Args.Length >= 1)
            {
                try
                {
                    program = Program.Load(e.Args[0]);
                }
                catch (Exception ex)
                {
                    CommonExceptionHandlers.HandleException(null, ex);
                }
            }
            if (program == null)
            {
                program = new Program();
            }

            AppState.Program = program;

            var bootstrapper = new Bootstrapper();

            bootstrapper.Run();
        }
Пример #3
0
        private bool SaveAs(bool forceSave)
        {
            Debug.Assert(AppState.Program != null);
            if (AppState.Program == null)
            {
                return(true);
            }

            if (!forceSave &&
                !AppState.Program.IsModified)
            {
                return(true);
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.DefaultExt = Properties.Resources.FileDefaultExt;
            dialog.Filter     = Properties.Resources.FileFilter;
            if (dialog.ShowDialog(this) == false)
            {
                return(false);
            }

            try
            {
                AppState.Program.SaveAs(dialog.FileName);
            }
            catch (FileNotFoundException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }
            catch (DirectoryNotFoundException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }
            catch (IOException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }

            return(true);
        }
Пример #4
0
        private bool Save(bool forceSave)
        {
            Debug.Assert(AppState.Program != null);
            if (AppState.Program == null)
            {
                return(true);
            }

            if (!forceSave &&
                !AppState.Program.IsModified)
            {
                return(true);
            }

            if (string.IsNullOrEmpty(AppState.Program.FileName))
            {
                return(SaveAs(forceSave));
            }

            try
            {
                AppState.Program.Save();
            }
            catch (FileNotFoundException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }
            catch (DirectoryNotFoundException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }
            catch (IOException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }

            return(true);
        }
Пример #5
0
        private bool Open()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt = Properties.Resources.FileDefaultExt;
            dialog.Filter     = Properties.Resources.FileFilter;
            if (dialog.ShowDialog(this) == false)
            {
                return(false);
            }

            Program program;

            try
            {
                program = Program.Load(dialog.FileName);
            }
            catch (FileNotFoundException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }
            catch (DirectoryNotFoundException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }
            catch (IOException ex)
            {
                CommonExceptionHandlers.HandleException(this, ex);
                return(false);
            }

            AppState.Program = program;

            return(true);
        }
Пример #6
0
        void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            CommonExceptionHandlers.HandleException(null, e.Exception);

            e.Handled = true;
        }