Exemple #1
0
        protected async void OpenDatabase(NSObject sender)
        {
            var url = await UIDialog.OpenFileDialog("Open Database", ShowOpenAsSheet?Window : null);

            if (url.HasValue)
            {
                try
                {
                    HandleOpenDatabase(url.Value);
                }
                catch (Exception e)
                {
                    UIDialog.ShowAlert("Database Error", $"Failed to open database: {e.Message}", NSAlertStyle.Critical);
                }
            }
        }
Exemple #2
0
        protected async void NewDatabase(NSObject sender)
        {
            var url = await UIDialog.SaveFileDialog("Save Database", ShowSaveAsSheet?Window : null);

            if (url.HasValue)
            {
                try
                {
                    HandleCreateDatabase(url.Value);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    UIDialog.ShowAlert("Database Error", $"Failed to create database: {e.Message}", NSAlertStyle.Critical);
                }
            }
        }
Exemple #3
0
        public bool HandleOpenDatabase(NSUrl url)
        {
            var path = url.Path;

            if (SessionData.Current.IsDatabaseOpen(path))
            {
                return(false);
            }

            if (!File.Exists(path))
            {
                UIDialog.ShowAlert(
                    "File not found",
                    "Cannot open database, file not found.",
                    NSAlertStyle.Critical);
                return(false);
            }

            try
            {
                string password = null;
                if (DatabaseReference.IsDbPasswordProtected(path))
                {
                    if (UIDialog.ShowInputAlert(Window, "Database is password protected, enter password:"******"Database password.", "", out password) != true)
                    {
                        return(false);
                    }
                }

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

                // Add document to the Open Recent menu
                NSDocumentController.SharedDocumentController.NoteNewRecentDocumentURL(url);

                return(true);
            }
            catch (Exception e)
            {
                UIDialog.ShowAlert(
                    "Database Error",
                    "Failed to open database:" + Environment.NewLine + e.Message,
                    NSAlertStyle.Critical);
            }

            return(false);
        }