/// <summary> /// Ctor using ProSqlExpressDb from datasource as parameter /// </summary> /// <param name="ProSqlExpressDb">ProSqlExpressDb from datasource</param> /// <param name="tableInfo">ProSqlExpressTableInfo of table/feature class that has been opened</param> public ProSqlPluginTableTemplate(ProSqlExpressDb.ProSqlExpressDb ProSqlExpressDb, ProSqlExpressTableInfo tableInfo) { _sqlDb = ProSqlExpressDb; _tableName = tableInfo.TableName; if (!string.IsNullOrEmpty(tableInfo.SpatialRefString)) { _spatialReference = SpatialReferenceBuilder.CreateSpatialReference(tableInfo.SpatialRefString); } _tableInfo = tableInfo; }
private void InitAccessDB(string path) { if (_sqlDb == null) { try { _sqlDb = new ProSqlExpressDb.ProSqlExpressDb(path); } catch (Exception ex) { _sqlError = ex.Message; _sqlDb = null; } } }
//TODO: Fetch is required if <b>IsContainer</b> = <b>true</b> public override void Fetch() { // Retrieve your child items // child items must also derive from CustomItemBase // the sqlexpress file contains one or more lines of SQLExpress connection strings // each connection string represents a database // don't refresh if this list is already primed before if (this.HasChildren) { return; } var children = new List <ProDataSubItem>(); var sqlConnections = System.IO.File.ReadAllLines(this.Path); foreach (var sqlConnection in sqlConnections) { if (string.IsNullOrEmpty(sqlConnection)) { continue; } ProSqlExpressDb.ProSqlExpressDb sqlDb = null; var dbChildren = new List <ProDataSubItem>(); var nodeName = string.Empty; try { sqlDb = new ProSqlExpressDb.ProSqlExpressDb(sqlConnection); nodeName = sqlDb.DatabaseName; _ProSqlExpressDbs.Add(sqlDb); // child items must also derive from CustomItemBase var lstTbl = sqlDb.GetSpatialTables(); ProDataSubItem featDataset = null; foreach (var tableInfo in lstTbl) { // the path has to be 'unique' for each entry otherwise the UI // will not treat the enumeration as a real enumeration var uniqueDbPath = $@"{this.Path}|{sqlConnection}|{tableInfo.TableName}"; var str = featDataset == null ? "-" : featDataset.Name; if (str != tableInfo.FeatureDataset) { featDataset = !string.IsNullOrEmpty(tableInfo.FeatureDataset) ? new ProDataSubItem(tableInfo.FeatureDataset, $@"{this.Path}|{sqlConnection}|{tableInfo.FeatureDataset}", this.TypeID, tableInfo, ProDataSubItem.EnumSubItemType.DataSet) : null; if (featDataset != null) { dbChildren.Add(featDataset); } } var dbChild = new ProDataSubItem(tableInfo.TableName, uniqueDbPath, this.TypeID, tableInfo, ProDataSubItem.EnumSubItemType.SqlType); if (featDataset != null) { featDataset.AddChild(dbChild); } else { dbChildren.Add(dbChild); } } } catch (Exception ex) { sqlDb = null; throw new Exception($@"Problem while initializing database connection. Error: {ex.Message}"); } if (dbChildren.Count() == 0) { break; } var uniquePath = $@"{this.Path}|{sqlConnection}|"; var child = new ProDataSubItem(nodeName, uniquePath, this.TypeID, null, ProDataSubItem.EnumSubItemType.SqlType, dbChildren); children.Add(child); } this.AddRangeToChildren(children); }