public void ConnectToDatabase(bool appStartup)
        {
            DBConnectionWindow    window = new DBConnectionWindow();
            DBConnectionViewModel vm     = new DBConnectionViewModel(window);

            window.DataContext = vm;

            vm.Server   = RegistrySettings.GetValue <string>("DatabaseServer", "localhost");
            vm.Database = RegistrySettings.GetValue <string>("Database", "Lithnet.Acma");

            bool?result = window.ShowDialog();

            if (result.HasValue && result.Value)
            {
                try
                {
                    ActiveConfig.OpenDatabase(vm.Server, vm.Database);
                    this.Database = new AcmaDatabaseViewModel(this);
                    RegistrySettings.SetValue("DatabaseServer", vm.Server);
                    RegistrySettings.SetValue("Database", vm.Database);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not connect to specified database. " + ex.Message);
                    this.ConnectToDatabase(appStartup);
                }
            }
            else
            {
                if (appStartup)
                {
                    Environment.Exit(0);
                }
            }
        }
        public MainWindowViewModel()
            : base()
        {
            UINotifyPropertyChanges.BeginIgnoreAllChanges();
            ViewModelBase.GlobalIconProvider = new Lithnet.Acma.Presentation.IconProvider();
            this.PopulateIgnoreViewModelChanges();
            this.AddDependentPropertyNotification("ViewModelIsDirty", "DisplayName");

            this.IgnorePropertyHasChanged.Add("DisplayName");
            this.IgnorePropertyHasChanged.Add("MRUItems");
            this.IgnorePropertyHasChanged.Add("ChildNodes");
            this.IgnorePropertyHasChanged.Add("Database");
            this.IgnorePropertyHasChanged.Add("XmlConfigFile");
            this.IgnorePropertyHasChanged.Add("ViewModelIsDirty");

            this.ConnectToDatabase(true);

            string[] commandLineArgs = Environment.GetCommandLineArgs();
            string   openFile        = null;

            if (commandLineArgs != null)
            {
                if (commandLineArgs.Length >= 2)
                {
                    openFile = commandLineArgs[1];
                }
            }

            this.XmlConfigFile = new XmlConfigFileViewModel();

            if (openFile != null)
            {
                if (System.IO.File.Exists(openFile))
                {
                    this.XmlConfigFile.Open(openFile);
                }
            }

            this.XmlConfigFile.PropertyChanged += XmlConfigFile_PropertyChanged;

            this.Commands.AddItem("New", x => this.New());
            this.Commands.AddItem("Open", x => this.Open());
            this.Commands.AddItem("Save", x => this.Save(), x => this.CanSave());
            this.Commands.AddItem("SaveAs", x => this.SaveAs(), x => this.CanSave());
            this.Commands.AddItem("ExportAsDocX", x => this.ExportConfigAsDocX(), x => this.CanExportConfigAsDocX());
            this.Commands.AddItem("ExportUnitTestAsDocX", x => this.ExportConfigAsDocX(), x => this.CanExportConfigAsDocX());
            this.Commands.AddItem("Close", x => this.Close());

            this.Database.IsExpanded                = true;
            this.XmlConfigFile.IsExpanded           = true;
            ViewModelBase.ViewModelChanged         += ViewModelBase_ViewModelChanged;
            Application.Current.MainWindow.Closing += new CancelEventHandler(MainWindow_Closing);
            UINotifyPropertyChanges.EndIgnoreAllChanges();

            //Restore TreeWidth from registry value or use default of 325
            int intTreeWidth = Convert.ToInt32(RegistrySettings.GetValue("TreeWidth", "325"));

            TreeWidth = intTreeWidth.ToString();
        }
        private List <string> GetMRUItems()
        {
            List <string> items = new List <string>();

            string[] list = RegistrySettings.GetValue("MRUList", null) as string[];

            if (list != null)
            {
                items.AddRange(list);
            }

            return(items);
        }