private void btnOK_Click(object sender, EventArgs e) { try { Cursor = Cursors.WaitCursor; pgFDB fdb = new pgFDB(); UserData parameters = _advancedSettings.ToUserData(); if (btnOnlyRepository.Checked) { parameters.SetUserData("CreateDatabase", false); } fdb.Open(ConnectionString); if (!fdb.Create(txtDatabase.Text, parameters)) { MessageBox.Show(fdb.lastErrorMsg, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //if (chkCreateReplicationDatamodel.Checked == true) { string errMsg; if (!gView.Framework.Offline.Replication.CreateRelicationModel(fdb, out errMsg)) { MessageBox.Show("RepliCreateRelicationModel failed:\n" + errMsg, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (chkCreateConnection.Checked) { string connStr = FullConnectionString; ConfigTextStream stream = new ConfigTextStream("postgrefdb_connections", true, true); string id = txtObject.Text; stream.Write(FullConnectionString, ref id); stream.Close(); _resultExObject = new ExplorerObject(null, id, FullConnectionString); } this.Close(); } catch (Exception ex) { MessageBox.Show("FATAL ERROR: " + ex.Message); } finally { Cursor = Cursors.Default; } }
async public Task <bool> SetConnectionString(string value) { _connStr = value; if (value == null) { return(false); } while (_connStr.IndexOf(";;") != -1) { _connStr = _connStr.Replace(";;", ";"); } _dsname = ConfigTextStream.ExtractValue(value, "dsname"); _addedLayers.Clear(); foreach (string layername in ConfigTextStream.ExtractValue(value, "layers").Split('@')) { if (layername == "") { continue; } if (_addedLayers.IndexOf(layername) != -1) { continue; } _addedLayers.Add(layername); } if (_fdb == null) { _fdb = new pgFDB(); } _fdb.DatasetRenamed += new gView.DataSources.Fdb.MSAccess.AccessFDB.DatasetRenamedEventHandler(SqlFDB_DatasetRenamed); _fdb.FeatureClassRenamed += new gView.DataSources.Fdb.MSAccess.AccessFDB.FeatureClassRenamedEventHandler(SqlFDB_FeatureClassRenamed); _fdb.TableAltered += new gView.DataSources.Fdb.MSAccess.AccessFDB.AlterTableEventHandler(SqlFDB_TableAltered); await _fdb.Open(_connStr); return(true); }
static void Main(string[] args) { #region Parse Parameters for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "-add": if (job != jobs.unknown) { Console.WriteLine("Can't do more than one job. Run programm twice..."); return; } job = jobs.add; break; case "-clean": if (job != jobs.unknown) { Console.WriteLine("Can't do more than one job. Run programm twice..."); return; } job = jobs.removeUnexisting; break; case "-truncate": if (job != jobs.unknown) { Usage(); Console.WriteLine("Can't do more than one job. Run programm twice..."); return; } job = jobs.truncate; break; case "-s": connectinString = args[++i]; break; case "-db": dbType = args[++i].ToLower(); break; case "-provider": provider = args[++i].ToLower(); break; case "-fn": if (rootPath != String.Empty) { Usage(); Console.WriteLine("Filename OR Rootdirectory..."); return; } fileName = args[++i]; break; case "-rd": if (fileName != String.Empty) { Usage(); Console.WriteLine("Filename OR Rootdirectory..."); return; } rootPath = args[++i]; break; case "-f": Filters = args[++i]; break; } } #endregion #region Check Parameters if (connectinString == String.Empty) { Usage(); Console.WriteLine("No connection string..."); return; } switch (job) { case jobs.removeUnexisting: case jobs.truncate: break; case jobs.add: if (fileName == String.Empty && (rootPath == String.Empty || Filters == String.Empty)) { Usage(); Console.WriteLine("No file or rootdirectory and filter defined..."); return; } break; case jobs.unknown: Usage(); Console.WriteLine("No job defined..."); return; } #endregion DateTime dt = DateTime.Now; string mdb = ConfigTextStream.ExtractValue(connectinString, "mdb"); string dsname = ConfigTextStream.ExtractValue(connectinString, "dsname"); string connStr = ConfigTextStream.RemoveValue(connectinString, "dsname"); IFeatureDataset ds = null; if (mdb != String.Empty) { AccessFDB fdb = new AccessFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } else if (dbType == "sql") { SqlFDB fdb = new SqlFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } else if (dbType == "postgres") { pgFDB fdb = new pgFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } else if (dbType == "sqlite") { SQLiteFDB fdb = new SQLiteFDB(); fdb.Open(connStr); IFeatureDataset dataset = fdb[dsname]; if (dataset == null) { Console.WriteLine("Error opening dataset: " + fdb.lastErrorMsg); return; } //dataset.ConnectionString = connectinString; if (!dataset.Open()) { Console.WriteLine("Error opening dataset: " + dataset.lastErrorMsg); return; } ds = dataset; } IRasterFileDataset rds = null; if (provider == "gdal") { rds = PlugInManager.Create(new Guid("43DFABF1-3D19-438c-84DA-F8BA0B266592")) as IRasterFileDataset; } else if (provider == "raster") { rds = PlugInManager.Create(new Guid("D4812641-3F53-48eb-A66C-FC0203980C79")) as IRasterFileDataset; } Dictionary <string, Guid> providers = new Dictionary <string, Guid>(); if (rds != null) { foreach (string format in rds.SupportedFileFilter.Split('|')) { string extension = format; int pos = format.LastIndexOf("."); if (pos > 0) { extension = format.Substring(pos, format.Length - pos); } providers.Add(extension, PlugInManager.PlugInID(rds)); Console.WriteLine("Provider " + extension + ": " + rds.ToString() + " {" + PlugInManager.PlugInID(rds).ToString() + "}"); } } if (providers.Count == 0) { providers = null; } switch (job) { case jobs.truncate: Truncate(ds, dsname + "_IMAGE_POLYGONS"); break; case jobs.removeUnexisting: RemoveUnexisting(ds); CalculateExtent(ds); break; case jobs.add: if (fileName != String.Empty) { if (!ImportFiles(ds, fileName.Split(';'), providers)) { if (!continueOnError) { return; } } } else if (rootPath != String.Empty && Filters != String.Empty) { if (!ImportDirectory(ds, new DirectoryInfo(rootPath), Filters.Split(';'), providers)) { if (!continueOnError) { return; } } } CalculateExtent(ds); break; } Console.WriteLine("\n" + ((TimeSpan)(DateTime.Now - dt)).TotalSeconds + "s"); Console.WriteLine("done..."); }