void BrowseForDbLib()
        {
            var dblib = AltiumFile.BrowseForDbLib();

            if (dblib.Success)
            {
                PathToDbLib = dblib.Path;
                Properties.Settings.Default.AltiumDbPath = dblib.Path;
                Properties.Settings.Default.Save();

                PathToUdl = dblib.ConnectionStringPath;
            }
        }
        public SettingsViewModel()
        {
            IntroBoxVisible = Properties.Settings.Default.ShowIntroBox;

            HideIntroBoxCommand   = new DelegateCommand(() => { IntroBoxVisible = false; Properties.Settings.Default.ShowIntroBox = false; Properties.Settings.Default.Save(); });
            BrowseForDbLibCommand = new DelegateCommand(BrowseForDbLib);
            UpdateUdlFileCommand  = new DelegateCommand(UpdateUdlFile, () => !String.IsNullOrEmpty(PathToDbLib) && File.Exists(PathToDbLib));

            PathToDbLib = Properties.Settings.Default.AltiumDbPath;
            if (!String.IsNullOrEmpty(PathToDbLib))
            {
                PathToUdl = AltiumFile.ReadUdlLocation(PathToDbLib);
            }
        }
        void UpdateUdlFile()
        {
            ShowUdlSuccessMessage = false;
            ShowUdlErrorMessage   = false;
            UdlMessage            = "";

            if (String.IsNullOrEmpty(MainViewModel.LoginRegisterViewModel.Password))
            {
                MainViewModel.LoginRegisterViewModel.UserIsLoggedIn = false;
                return;
            }

            string newUdlPath = Path.ChangeExtension(PathToDbLib, "udl");
            var    cred       = new UdlCredentials
            {
                Username = MainViewModel.LoginRegisterViewModel.Username,
                Password = MainViewModel.LoginRegisterViewModel.Password,
                Server   = "csql.database.windows.net"
            };

            if (AltiumFile.CreateMsSqlUdlFile(newUdlPath, cred))
            {
                if (AltiumFile.SetUdlLocationInDbLib(PathToDbLib, newUdlPath))
                {
                    PathToUdl             = AltiumFile.ReadUdlLocation(PathToDbLib);
                    ShowUdlSuccessMessage = true;
                    UdlMessage            = "Successfully created/updated the UDL file with your Azure credentials, and set the file path in the Altium DbLib.";
                }
                else
                {
                    ShowUdlErrorMessage = true;
                    UdlMessage          = "Could not update Altium DbLib file with new UDL file location - check Altium is not open, and you have permission to edit the file!";
                }
            }
            else
            {
                ShowUdlErrorMessage = true;
                UdlMessage          = "Could not create the UDL file on disk - check you have permission to create a file here!";
            }
        }
        void BrowseForAltiumDirectory()
        {
            var dbLib = AltiumFile.BrowseForDbLib();

            if (!dbLib.Success)
            {
                ShowAltiumPathError = true;
                AltiumPathError     = "DbLib could not be found/opened. Please login with username and password.";
                return;
            }

            if (String.IsNullOrEmpty(dbLib.ConnectionStringPath))
            {
                ShowAltiumPathError = true;
                AltiumPathError     = "DbLib has not been configured correctly. Please login with username and password.";
                return;
            }

            var conn = AltiumFile.ReadUdlFile(dbLib.ConnectionStringPath);

            if (!String.IsNullOrEmpty(conn.Error))
            {
                ShowAltiumPathError = true;
                AltiumPathError     = String.Format("{0} Please login with username and password.", conn.Error);
                return;
            }

            if (conn.Server != "csql.database.windows.net")
            {
                ShowAltiumPathError = true;
                AltiumPathError     = "DbLib configured for a local server. Please login with username and password.";
                return;
            }

            Username = conn.Username;
            Password = conn.Password;

            AltiumPath = dbLib.Path;
        }