Exemplo n.º 1
0
        /// <summary>
        /// Crawls this instance.
        /// </summary>
        /// <exception cref="SPSCrawlerException"><c>SPSCrawlerException</c>.</exception>
        public void Crawl()
        {
            // Select top web or current
            using (SPWeb web = GetTopWeb())
            {
                try
                {
                    // Filter we only need lists
                    var dataFilter = new SPSHierarchyFilter
                    {
                        SortHierarchy  = false,
                        IncludeLists   = true,
                        IncludeWebs    = _recursive,
                        IncludeFolders = false
                    };

                    dataFilter.OnFilter += InvokeCollector;

                    // DataSource
                    using (var dataSource = new SPSHierarchyDataSource(web))
                    {
                        dataSource.Filter = dataFilter;
                        // get all elements . on filter does the rollup
                        dataSource.GetAll();
                    }

                    Processed = true;
                }
                catch (SPException ex)
                {
                    throw new SPSCrawlerException(ex);
                }
            }
        }
        private static TreeNode PopulateTreeNodes(SPSHierarchyDataSource dataSource, TreeBound delegateBound)
        {
            TreeNode root;

            using (SPSNodeCollection dataNodes = dataSource.GetAll())
            {
                SPSNodeBase dataRoot = dataNodes[0];
                root = new TreeNode(dataRoot.Name, dataRoot.UrlSegment, dataRoot.ImageUrl, dataRoot.NavigateUrl, "");

                if (delegateBound != null)
                {
                    delegateBound(root, dataRoot);
                }

                PopulateTreeNodesRecursive(root, dataRoot.Children, delegateBound);
            }
            return(root);
        }
        //public DataRowView GetSelectedData()
        //{
        //    if (SelectedRow != null && HasResults)
        //    {
        //        return Data.Tables[0].DefaultView[SelectedRow.Value];
        //    }
        //    Data.Tables[0].Rows.Add(Data.Tables[0].NewRow());
        //    return Data.Tables[0].DefaultView[0];
        //}

        #region Private Methods

        /// <summary>
        /// Rolls the up.
        /// </summary>
        private DataSet RollUp()
        {
            Debug.WriteLine("RollUp Called");

            if (!_processed)
            {
                Debug.WriteLine("RollUp Processing");

                _dataSet.Tables[0].Rows.Clear();
                _rowNumber = 0;

                // Select top web or current
                using (SPWeb web = GetWebToUse())
                {
                    try
                    {
                        // Filter we only need lists
                        SPSHierarchyFilter dataFilter = new SPSHierarchyFilter
                        {
                            SortHierarchy  = false,
                            IncludeLists   = true,
                            IncludeWebs    = _camlQueryRecursive,
                            IncludeFolders = false
                        };

                        dataFilter.OnFilter += DataSourceFilter;

                        // DataSource
                        using (SPSHierarchyDataSource source = new SPSHierarchyDataSource(web))
                        {
                            source.Filter = dataFilter;
                            // get all elements . on filter does the rollup
                            source.GetAll();
                        }
                        _processed = true;
                    }
                    catch (SPException ex)
                    {
                        SendError(new SPSErrorArgs(ex.TargetSite.Name, ex.Message, ex));
                    }
                }
            }
            return(_dataSet);
        }