Пример #1
0
        private static async Task <bool> ImportCsv(IWin32Window owner, string filePath, NotebookManager manager,
                                                   DatabaseSchema schema)
        {
            string importSql;

            using (var f = new ImportCsvForm(filePath, schema, manager)) {
                if (f.ShowDialog(owner) != DialogResult.OK)
                {
                    return(false);
                }
                importSql = f.GeneratedImportSql;
            }

            return(await RunImportScript(importSql, owner, filePath, manager));
        }
Пример #2
0
        public static async Task <bool> Start(IWin32Window owner, string filePath, NotebookManager manager)
        {
            DatabaseSchema schema = null;

            manager.PushStatus("Reading notebook...");
            try {
                schema = await Task.Run(() => DatabaseSchema.FromNotebook(manager.Notebook));
            } catch (Exception ex) {
                MessageForm.ShowError(owner,
                                      "Import Error",
                                      "Failed to read the list of tables in the notebook.",
                                      ex.Message);
                return(false);
            }
            manager.PopStatus();

            string importSql;

            using (var f = new ImportCsvForm(filePath, schema, manager)) {
                if (f.ShowDialog(owner) != DialogResult.OK)
                {
                    return(false);
                }
                importSql = f.GeneratedImportSql;
            }

            manager.PushStatus($"Importing \"{Path.GetFileName(filePath)}\"...");
            try {
                await Task.Run(() => {
                    manager.ExecuteScript(importSql, withTransaction: true);
                });

                manager.Rescan();
            } catch (Exception ex) {
                manager.PopStatus();
                MessageForm.ShowError(owner, "Import Error", "The import failed.", ex.GetErrorMessage());
                return(false);
            }

            manager.SetDirty();
            manager.PopStatus();
            return(true);
        }