/// <summary>
        /// Gets the item by path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public static ReportingServiceItem GetItemByPath(string path)
        {
            ReportingServicesProvider provider = new ReportingServicesProvider();

            path = provider.GetFolderPath(path);

            ReportingServiceItem rsItem = GetItemsFlat(provider.ReportPath, true, true)
                                          .Where(i => i.Path.Equals(path, StringComparison.InvariantCultureIgnoreCase))
                                          .FirstOrDefault();

            return(rsItem);
        }
        /// <summary>
        /// Gets the folder tree.
        /// </summary>
        /// <param name="rootPath">The root path.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <param name="includeHidden">if set to <c>true</c> [include hidden].</param>
        /// <returns></returns>
        public static ReportingServiceItem GetFoldersTree(string rootPath, bool recursive, bool includeHidden)
        {
            var rawItems = GetFoldersFlat(rootPath, recursive, includeHidden);

            rootPath = new ReportingServicesProvider().GetFolderPath(rootPath);
            ReportingServiceItem rsi = new ReportingServiceItem {
                Type = ItemType.Folder, Path = rootPath, Name = rootPath.Substring(rootPath.LastIndexOf("/") + 1)
            };

            rsi.Children = LoadChildren(rawItems, rsi.Path);

            return(rsi);
        }
        /// <summary>
        /// Gets the report tree.
        /// </summary>
        /// <param name="rootPath">The root path.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <param name="includeHidden">if set to <c>true</c> [include hidden].</param>
        /// <returns></returns>
        public static ReportingServiceItem GetReportTree(string rootPath, bool recursive, bool includeHidden)
        {
            var rawItems = GetItemsFlat(rootPath, recursive, includeHidden);

            rawItems.RemoveAll(i => i.Type == ItemType.DataSource);

            ReportingServiceItem rsi = new ReportingServiceItem();

            rootPath = new ReportingServicesProvider().GetFolderPath(rootPath);
            rsi.Name = rootPath.Substring(rootPath.LastIndexOf("/") + 1);
            rsi.Path = rootPath;
            rsi.Type = ItemType.Folder;

            rsi.Children = LoadChildren(rawItems, rsi.Path);

            return(rsi);
        }
        /// <summary>
        /// Gets the folders in a flat list.
        /// </summary>
        /// <param name="rootPath">The root path.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <param name="includeHidden">if set to <c>true</c> [include hidden].</param>
        /// <returns></returns>
        public static List <ReportingServiceItem> GetFoldersFlat(string rootPath, bool recursive, bool includeHidden)
        {
            rawItems = new List <ReportingServiceItem>();

            var apiItems = GetCatalogItems(rootPath, recursive)
                           .Where(c => c.TypeName.Equals("folder", StringComparison.InvariantCultureIgnoreCase))
                           .Where(c => includeHidden || c.Hidden == false);

            foreach (var item in apiItems)
            {
                ReportingServiceItem i = new ReportingServiceItem();
                i.Name   = item.Name;
                i.Path   = item.Path;
                i.Type   = ItemType.Folder;
                i.Hidden = item.Hidden;

                rawItems.Add(i);
            }

            return(rawItems);
        }
        /// <summary>
        /// Gets the items in a flat list.
        /// </summary>
        /// <param name="rootPath">The root path.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <param name="includeHidden">if set to <c>true</c> [include hidden].</param>
        /// <returns></returns>
        private static List <ReportingServiceItem> GetItemsFlat(string rootPath, bool recursive, bool includeHidden)
        {
            var apiItems = GetCatalogItems(rootPath, recursive)
                           .Where(i => includeHidden || i.Hidden == false);

            var rawItems = new List <ReportingServiceItem>();

            foreach (var item in apiItems)
            {
                ReportingServiceItem i = new ReportingServiceItem();
                i.Name   = item.Name;
                i.Path   = item.Path;
                i.Hidden = item.Hidden;

                switch (item.TypeName.ToLower())
                {
                case "folder":
                    i.Type = ItemType.Folder;
                    break;

                case "report":
                    i.Type = ItemType.Report;
                    break;

                case "datasource":
                    i.Type = ItemType.DataSource;
                    break;

                default:
                    break;
                }

                rawItems.Add(i);
            }
            return(rawItems);
        }