/// <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);
        }
 public void AddChild(ProDataSubItem child)
 {
     this.AddRangeToChildren(new List <ProDataSubItem>()
     {
         child
     });
 }
        //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);
        }