/// <summary> /// Ctor using ProMdbAccessDb from datasource as parameter /// </summary> /// <param name="proMdbAccessDb">ProMdbAccessDb from datasource</param> /// <param name="tableInfo">ProMdbTableInfo of table/feature class that has been opened</param> public ProMdbPluginTableTemplate(ProMdbAccessDb.ProMdbAccessDb proMdbAccessDb, ProMdbTableInfo tableInfo) { _accessDb = proMdbAccessDb; _tableName = tableInfo.TableName; _spatialReference = SpatialReferenceBuilder.CreateSpatialReference(tableInfo.SpatialRefString); _tableInfo = tableInfo; }
/// <summary> /// Called when the datasource is closed ... free reference data /// </summary> public override void Close() { //Dispose of any cached table instances here foreach (var table in _tables.Values) { ((ProMdbPluginTableTemplate)table).Dispose(); } _tables.Clear(); if (_accessDb != null) { _accessDb.Close(); _accessDb = null; } }
private void InitAccessDB(string path) { if (_accessDb == null) { try { _accessDb = new ProMdbAccessDb.ProMdbAccessDb(path); } catch (Exception ex) { _accessError = ex.Message; _accessDb = 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 CustomDataLink file contains lineitems with link to other folder where our customdata // is stored var alreadyProcessedPath = new List <string>(); var children = new List <ProDataSubItem>(); var dataFolders = System.IO.File.ReadAllLines(this.Path); for (var idx = 0; idx < dataFolders.Length; idx++) { dataFolders[idx] = dataFolders[idx].TrimEnd(new char [] { '\\', '/' }); } foreach (var ext in FileExtensions) { foreach (var dataFolder in dataFolders) { if (string.IsNullOrEmpty(dataFolder)) { continue; } var files = System.IO.Directory.GetFiles(dataFolder, $@"*{ext}", System.IO.SearchOption.AllDirectories); foreach (var fullName in files) { var fileName = System.IO.Path.GetFileNameWithoutExtension(fullName); var fileExt = System.IO.Path.GetExtension(fullName).ToLower(); switch (fileExt) { case ".gpx": { var uniquePath = fullName; var child = new ProDataSubItem(fileName, uniquePath, this.TypeID, null, ProDataSubItem.EnumSubItemType.GpxType); children.Add(GetParentFolder(dataFolder, child)); } break; case ".mdb": { ProMdbAccessDb.ProMdbAccessDb accessDb = null; var dbChildren = new List <ProDataSubItem>(); try { var fileMdbPath = $@"{fullName}"; accessDb = new ProMdbAccessDb.ProMdbAccessDb(fileMdbPath); _proMdbAccessDbs.Add(accessDb); // child items must also derive from CustomItemBase var lstTbl = accessDb.GetSpatialTables(); foreach (var tblName in lstTbl.Keys) { // the path has to be 'unique' for each entry otherwise the UI // will not treat the enumeration as a real enumeration var uniqueDbPath = System.IO.Path.Combine(fileMdbPath, tblName); var dbChild = new ProDataSubItem(tblName, uniqueDbPath, this.TypeID, lstTbl[tblName], ProDataSubItem.EnumSubItemType.MdbType); dbChildren.Add(dbChild); } } catch (Exception ex) { accessDb = null; throw new Exception($@"Check this download: https://www.microsoft.com/en-us/download/details.aspx?id=13255 Error: {ex.Message}"); } if (dbChildren.Count() == 0) { break; } var uniquePath = fullName; var child = new ProDataSubItem(fileName, uniquePath, this.TypeID, null, ProDataSubItem.EnumSubItemType.MdbType, dbChildren); children.Add(GetParentFolder(dataFolder, child)); } break; case ".jpg": { var ximgInfo = new XimgInfo(fullName); System.Diagnostics.Debug.WriteLine($@"Image {ximgInfo.IsImage}"); if (!ximgInfo.IsImage || !ximgInfo.IsGpsEnabled) { continue; } //// Get the PropertyItems property from image. // the path has to be 'unique' for each entry otherwise the UI // will not treat the enumeration as a real enumeration // However in this case we only have one single item var parentFolder = System.IO.Path.GetDirectoryName(fullName); if (dataFolder.Equals(parentFolder)) { System.Diagnostics.Debug.WriteLine($@"Lat: {ximgInfo.Latitude} Lon: {ximgInfo.Longitude} Alt: {ximgInfo.Altitude}"); var uniquePath = fullName; var child = new ProDataSubItem(fileName, uniquePath, this.TypeID, null, ProDataSubItem.EnumSubItemType.ImgType); children.Add(GetParentFolder(dataFolder, child)); } else { // directory full of photos if (alreadyProcessedPath.Contains(parentFolder)) { // already processed this parent folder } else { alreadyProcessedPath.Add(parentFolder); var jpgChildren = new List <ProDataSubItem>(); var jpgFiles = System.IO.Directory.GetFiles(parentFolder, $@"*{ext}", System.IO.SearchOption.TopDirectoryOnly); foreach (var jpgFullName in jpgFiles) { var xInfo = new XimgInfo(jpgFullName); System.Diagnostics.Debug.WriteLine($@"Image {xInfo.IsImage}"); if (!xInfo.IsImage || !xInfo.IsGpsEnabled) { continue; } jpgChildren.Add(new ProDataSubItem(jpgFullName, jpgFullName, this.TypeID, null, ProDataSubItem.EnumSubItemType.ImgType)); } var uniquePath = System.IO.Path.Combine(parentFolder, $@"{System.IO.Path.GetFileName(parentFolder)} Jpgs"); var name = System.IO.Path.GetFileName(uniquePath); var rootNode = new ProDataSubItem(name, uniquePath, this.TypeID, null, ProDataSubItem.EnumSubItemType.ImgDirType, jpgChildren); children.Add(GetParentFolder(dataFolder, rootNode)); } } //var img = System.Drawing.Image.FromStream (fs); //var propItems = img.PropertyItems; //foreach (var propItem in propItems) //{ // System.Diagnostics.Debug.WriteLine($@"iD: 0x{propItem.Id.ToString("x")}"); //} //// see: https://www.exiv2.org/tags.html //System.Diagnostics.Debug.WriteLine($@"Image Aspect = {img.Width} x {img.Height}"); //System.Diagnostics.Debug.WriteLine($@"Make = {ReadImageProperty(img, 0x110)}"); //System.Diagnostics.Debug.WriteLine($@"Date = {ReadImageProperty(img, 0x0132)}"); //var gps = ImageMetadataReader.ReadMetadata(fs).OfType<GpsDirectory>().FirstOrDefault(); //var location = gps.GetGeoLocation(); //System.Diagnostics.Debug.WriteLine($@"Location: {location.Longitude} {location.Latitude}"); } break; } } } } this.AddRangeToChildren(children); }