Beispiel #1
0
        /// <summary>
        /// subItem has a path that needs to be parsed (from the back) in order to build the
        /// directory tree.  Only the top node of the directory tree (at topNodeName) will be
        /// returned and then added to the root.
        /// </summary>
        /// <param name="topNodeName">top directory where all data is located</param>
        /// <param name="subItem">Item to be inserted at the end of the branch</param>
        /// <returns>top node that needs to be added to the root 'data folder'</returns>
        private ProDataSubItem GetParentFolder(string topNodeName, ProDataSubItem subItem)
        {
            var parts        = topNodeName.Split(new char [] { '/', '\\' });
            var rootPartsCnt = parts.Length;

            parts = subItem.Path.Split(new char[] { '/', '\\' });
            var topNode = subItem;

            for (int idx = parts.Length - 2; idx >= rootPartsCnt; idx--)
            {
                var completeFolderPath = string.Empty;
                for (int iidx = 0; iidx <= idx; iidx++)
                {
                    if (iidx > 0)
                    {
                        completeFolderPath += @"\";
                    }
                    completeFolderPath += parts[iidx];
                }
                var uniquePath = System.IO.Path.Combine(Path, completeFolderPath);
                topNode = new ProDataSubItem(parts[idx], uniquePath, this.TypeID,
                                             null, ProDataSubItem.EnumSubItemType.DirType, new List <ProDataSubItem> {
                    topNode
                });
            }
            return(topNode);
        }
Beispiel #2
0
        //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 line items 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 ".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)} Jpeg Images");
                                    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);
        }