public Workspace OpenWorkspace(String path) { var upgrader = new WorkspaceUpgrader(path); int version; try { using (var connection = upgrader.OpenConnection()) { try { version = upgrader.ReadSchemaVersion(connection); } catch (Exception e) { Console.Out.WriteLine(e); MessageBox.Show( "Unable to read version number from the workspace. This workspace may be too old to be upgraded."); return(null); } } } catch (Exception openException) { Console.Out.WriteLine(openException); MessageBox.Show("Unable to open the database:" + openException.Message); return(null); } if (version > WorkspaceUpgrader.CurrentVersion || version < WorkspaceUpgrader.MinUpgradeableVersion) { MessageBox.Show("This workspace cannot be opened by this version of Topograph", Program.AppName); return(null); } if (version < WorkspaceUpgrader.CurrentVersion) { var result = MessageBox.Show( "This workspace needs to be upgraded to this version of Topograph. Do you want to do that now?", Program.AppName, MessageBoxButtons.OKCancel); if (result == DialogResult.Cancel) { return(null); } using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Upgrading Workspace")) { if (!new LongOperationBroker(upgrader.Run, longWaitDialog).LaunchJob()) { return(null); } } } return(new Workspace(path)); }
private void BtnOkOnClick(object sender, EventArgs e) { if (!CheckRequiredField(tbxServer) || !CheckRequiredField(comboDatabaseName) || !CheckRequiredField(tbxUsername) || !CheckRequiredField(tbxPassword)) { return; } Settings.Default.Reload(); var tpgLinkDef = GetTpgLinkDef(); var workspaceUpgrader = new WorkspaceUpgrader(tpgLinkDef); try { using (var connection = workspaceUpgrader.OpenConnection()) { try { workspaceUpgrader.ReadSchemaVersion(connection); } catch { MessageBox.Show(this, string.Format("The database {0} is not a Topograph workspace", tpgLinkDef.Database)); return; } } } catch (Exception exception) { MessageBox.Show(this, string.Format("There was an error trying to connect to the database: {0}", exception), Program.AppName); return; } using (var fileDialog = new SaveFileDialog { Filter = TopographForm.OnlineWorkspaceFilter, InitialDirectory = Settings.Default.WorkspaceDirectory, FileName = comboDatabaseName.Text + ".tpglnk", }) { while (true) { if (fileDialog.ShowDialog(this) == DialogResult.Cancel) { return; } try { tpgLinkDef.Save(fileDialog.FileName); } catch (Exception exception) { MessageBox.Show(this, string.Format("Error saving .tpglnk file: {0}", exception), Program.AppName); continue; } Filename = fileDialog.FileName; Settings.Default.WorkspaceDirectory = Path.GetDirectoryName(Filename); break; } } Settings.Default.ConnectionSettings = new ConnectionSettings { Server = tbxServer.Text, Port = tbxPort.Text, Username = tbxUsername.Text, }; Settings.Default.Save(); DialogResult = DialogResult.OK; Close(); }
private void BtnOkOnClick(object sender, EventArgs e) { if (!CheckRequiredField(tbxServer) || !CheckRequiredField(tbxDatabase) || !CheckRequiredField(tbxUsername) || !CheckRequiredField(tbxPassword)) { return; } Settings.Default.Reload(); var tpgLnkDef = GetTpgLinkDef(); try { using (tpgLnkDef.OpenConnectionNoDatabase()) { } } catch (Exception exception) { MessageBox.Show(this, string.Format( "The server, port, username, or password is invalid. There was an error connecting to the database: {0}", exception), Program.AppName); return; } bool workspaceExists; try { var workspaceUpgrader = new WorkspaceUpgrader(tpgLnkDef); using (var connection = tpgLnkDef.OpenConnection()) { try { workspaceUpgrader.ReadSchemaVersion(connection); if (MessageBox.Show(this, string.Format( "The database {0} already exists. Instead of creating a new Online Workspace, would you like to save a .tpglnk file which allows you to connect to this existing Online Workspace.", tpgLnkDef.Database), Program.AppName, MessageBoxButtons.YesNo) == DialogResult.No) { return; } workspaceExists = true; } catch (Exception) { MessageBox.Show(this, string.Format("The database {0} already exists but does not appear to be a Topograph workspace.", tpgLnkDef.Database), Program.AppName); return; } } } catch (Exception) { workspaceExists = false; } if (!workspaceExists) { try { using (var sessionFactory = tpgLnkDef.CreateDatabase()) { TopographForm.InitWorkspace(sessionFactory); } } catch (Exception exception) { MessageBox.Show(this, string.Format("There was an error creating the database: {0}", exception), Program.AppName); return; } } while (true) { using (var fileDialog = new SaveFileDialog { Filter = TopographForm.OnlineWorkspaceFilter, InitialDirectory = Settings.Default.WorkspaceDirectory, FileName = tbxDatabase.Text + ".tpglnk", }) { if (fileDialog.ShowDialog(this) == DialogResult.Cancel) { DialogResult = DialogResult.Cancel; } try { tpgLnkDef.Save(fileDialog.FileName); } catch (Exception exception) { MessageBox.Show(this, string.Format("Error saving .tpglnk file: {0}", exception), Program.AppName); continue; } Filename = fileDialog.FileName; Settings.Default.WorkspaceDirectory = Path.GetDirectoryName(Filename); break; } } Settings.Default.ConnectionSettings = new ConnectionSettings { Server = tbxServer.Text, Port = tbxPort.Text, Username = tbxUsername.Text, }; Settings.Default.Save(); DialogResult = DialogResult.OK; Close(); }