Пример #1
0
        public async Task OpenDatabase(string path, string password = "")
        {
            if (Store.Current.IsDatabaseOpen(path))
            {
                return;
            }

            if (!File.Exists(path))
            {
                _applicationInteraction.ShowError("Cannot open database, file not found.", "File not found");
                return;
            }

            if (ArchiveExtensions.GetDriveType(path) == DriveType.Network)
            {
                _applicationInteraction.ShowAlert("Maintaining connection to network files is not guaranteed!", "Network file", UINotificationType.Info);
            }

            try
            {
                if (DatabaseReference.IsDbPasswordProtected(path))
                {
                    var maybePassword = await _applicationInteraction.ShowInputDialog("Database is password protected, enter password:"******"Database password.", password);

                    if (maybePassword.HasNoValue)
                    {
                        return;
                    }

                    password = maybePassword.Value;
                }

                Store.Current.AddDatabase(new DatabaseReference(path, password));

                _recentFilesProvider.InsertRecentFile(path);
            }
            catch (LiteException liteException)
            {
                await OpenDatabaseExceptionHandler(liteException, path, password);
            }
            catch (NotSupportedException notSupportedException)
            {
                _applicationInteraction.ShowError(notSupportedException, "Failed to open database [NotSupportedException]:" + Environment.NewLine + notSupportedException.Message);
            }
            catch (Exception e)
            {
                Logger.Error(e, "Failed to open database: ");
                _applicationInteraction.ShowError(e, "Failed to open database [Exception]:" + Environment.NewLine + e.Message);
            }
        }
Пример #2
0
        public async Task OpenDatabase(string path, string password = "")
        {
            if (Store.Current.IsDatabaseOpen(path))
            {
                return;
            }

            if (!File.Exists(path))
            {
                _applicationInteraction.ShowError("Cannot open database, file not found.", "File not found");
                return;
            }

            if (ArchiveExtensions.GetDriveType(path) == DriveType.Network)
            {
                _applicationInteraction.ShowAlert("Maintaining connection to network files is not guaranteed!", "Network file", UINotificationType.Info);
            }

            try
            {
                var rememberMe = false;
                if (DatabaseReference.IsDbPasswordProtected(path))
                {
                    if (string.IsNullOrWhiteSpace(password) && _recentDatabaseFilesProvider.TryGetPassword(path, out var storedPassword))
                    {
                        password   = storedPassword;
                        rememberMe = true;
                    }

                    var maybePasswordInput = await _applicationInteraction.ShowPasswordInputDialog("Database is password protected, enter password:"******"Database password.", password, rememberMe);

                    if (maybePasswordInput.HasNoValue)
                    {
                        return;
                    }

                    password   = maybePasswordInput.Value.Password;
                    rememberMe = maybePasswordInput.Value.RememberMe;
                }

                var connectionOptions = new DatabaseConnectionOptions(path, password)
                {
                    Mode = Properties.Settings.Default.Database_ConnectionFileMode
                };

                var databaseReference = new DatabaseReference(connectionOptions);

                Store.Current.AddDatabase(databaseReference);

                if (!string.IsNullOrEmpty(password) && rememberMe)
                {
                    _recentDatabaseFilesProvider.InsertRecentFile(databaseReference.DatabaseVersion, path, password);
                }
                else
                {
                    _recentDatabaseFilesProvider.InsertRecentFile(databaseReference.DatabaseVersion, path);
                }
            }
            catch (LiteException liteException)
            {
                await OpenDatabaseExceptionHandler(liteException, path, password);
            }
            catch (NotSupportedException notSupportedException)
            {
                _applicationInteraction.ShowError(notSupportedException, "Failed to open database [NotSupportedException]:" + Environment.NewLine + notSupportedException.Message);
            }
            catch (Exception e)
            {
                Logger.Error(e, "Failed to open database: ");
                _applicationInteraction.ShowError(e, "Failed to open database [Exception]:" + Environment.NewLine + e.Message);
            }
        }