async public Task <IExplorerFileObject> CreateInstance(IExplorerObject parent, string filename) { string f = filename.ToLower(); if (!f.ToLower().EndsWith(".fdb")) { return(null); } try { if (!(new FileInfo(f).Exists)) { return(null); } using (SQLiteFDB fdb = new SQLiteFDB()) { if (!await fdb.Open(f) || !await fdb.IsValidAccessFDB()) { return(null); } } } catch { return(null); } return(new SQLiteFDBExplorerObject(parent, filename)); }
async private Task BuildList() { lstDatasets.Items.Clear(); AccessFDB fdb = null; switch (_providerId) { case "mssql": fdb = new SqlFDB(); break; case "postgres": fdb = new pgFDB(); break; case "sqlite": fdb = new SQLiteFDB(); break; } if (fdb == null) { return; } if (!await fdb.Open(this.ConnectionString)) { MessageBox.Show(fdb.LastErrorMessage, "Error"); return; } string[] dsnames = await fdb.DatasetNames(); if (dsnames != null) { foreach (string dsname in dsnames) { var isImageDatasetResult = await fdb.IsImageDataset(dsname); ListViewItem item = new ListViewItem( dsname, isImageDatasetResult.isImageDataset ? 1 : 0); lstDatasets.Items.Add(item); if (item.Text == _dsname) { lstDatasets.SelectedIndices.Add(lstDatasets.Items.Count - 1); } } } }
async public Task <IExplorerObject> CreateExplorerObject(IExplorerObject parentExObject) { if (!CanCreate(parentExObject)) { return(null); } FormNewDataset dlg = new FormNewDataset(); dlg.IndexTypeIsEditable = false; if (dlg.ShowDialog() != DialogResult.OK) { return(null); } SQLiteFDB fdb = new SQLiteFDB(); await fdb.Open(parentExObject.FullName); int dsID = -1; string datasetName = dlg.DatasetName; switch (dlg.DatasetType) { case FormNewDataset.datasetType.FeatureDataset: dsID = await fdb.CreateDataset(datasetName, dlg.SpatialReferene); break; case FormNewDataset.datasetType.ImageDataset: dsID = await fdb.CreateImageDataset(datasetName, dlg.SpatialReferene, null, dlg.ImageSpace, dlg.AdditionalFields); datasetName = "#" + datasetName; break; } if (dsID == -1) { MessageBox.Show(fdb.LastErrorMessage, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } return(new SQLiteFDBDatasetExplorerObject(parentExObject, parentExObject.FullName, datasetName)); }
async private Task <string[]> DatasetNames() { try { SQLiteFDB fdb = new SQLiteFDB(); if (!await fdb.Open(_filename)) { _errMsg = fdb.LastErrorMessage; return(null); } string[] ds = await fdb.DatasetNames(); string[] dsMod = new string[ds.Length]; int i = 0; foreach (string dsname in ds) { var isImageDatasetResult = await fdb.IsImageDataset(dsname); string imageSpace = isImageDatasetResult.imageSpace; if (isImageDatasetResult.isImageDataset) { dsMod[i++] = "#" + dsname; } else { dsMod[i++] = dsname; } } if (ds == null) { _errMsg = fdb.LastErrorMessage; } fdb.Dispose(); return(dsMod); } catch (Exception ex) { _errMsg = ex.Message; return(null); } }
async private void btnChangeConnectionString_Click(object sender, EventArgs e) { AccessFDB fdb = null; switch (_providerId) { case "mssql": fdb = new SqlFDB(); break; case "postgres": fdb = new pgFDB(); break; case "sqlite": fdb = new SQLiteFDB(); break; } if (fdb == null) { return; } await fdb.Open(_connectionString); DbConnectionString dbConnStr = new DbConnectionString(); dbConnStr.UseProviderInConnectionString = false; FormConnectionString dlg = (dbConnStr.TryFromConnectionString("mssql", fdb.ConnectionString) ? new FormConnectionString(dbConnStr) : new FormConnectionString()); dlg.ProviderID = _providerId; dlg.UseProviderInConnectionString = false; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { dbConnStr = dlg.DbConnectionString; _connectionString = dbConnStr.ConnectionString; await BuildList(); } }
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 SQLiteFDB(); } _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..."); }