コード例 #1
0
        /// <summary>
        /// Action for this SharePoint term group
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"TermGroupRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         g => g.Name);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"TermGroup | Name: {Element.Name}");

            // OnTermGroupRunningStart
            RunningManager.Logger.Debug("TermGroupRunner OnTermGroupRunningStart()");
            ActiveReceivers.ForEach(r => r.OnTermGroupRunningStart(Element));

            // If at least one receiver run term sets or deeper
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.TermSet)))
            {
                // Crawl term sets
                Context.Load(Element.TermSets);
                Context.ExecuteQuery();

                List <TermSetRunner> termSetRunners = new List <TermSetRunner>();
                foreach (TermSet set in Element.TermSets)
                {
                    termSetRunners.Add(new TermSetRunner(Manager, Context, set));
                }

                termSetRunners.ForEach(r => r.Process());
            }

            // OnTermGroupRunningEnd
            RunningManager.Logger.Debug("TermGroupRunner OnTermGroupRunningEnd()");
            ActiveReceivers.ForEach(r => r.OnTermGroupRunningEnd(Element));
        }
コード例 #2
0
        /// <summary>
        /// Action for this SharePoint tenant
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"TenantRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         t => t.RootSiteUrl);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"Tenant | URL: {Element.RootSiteUrl}");

            // OnTenantRunningStart
            RunningManager.Logger.Debug("TenantRunner OnTenantRunningStart()");
            ActiveReceivers.ForEach(r => r.OnTenantRunningStart(Element));

            // If at least one receiver run term stores or deeper
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.TermStore)))
            {
                // Open taxonomy session
                TaxonomySession taxSession = TaxonomySession.GetTaxonomySession(Context);

                // Crawl term stores
                Context.Load(taxSession,
                             s => s.TermStores);
                Context.ExecuteQuery();

                List <TermStoreRunner> termStoreRunners = new List <TermStoreRunner>();
                foreach (TermStore store in taxSession.TermStores)
                {
                    termStoreRunners.Add(new TermStoreRunner(Manager, Context, store));
                }

                termStoreRunners.ForEach(r => r.Process());
            }

            // If at least one receiver run site collections or deeper
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.SiteCollection)))
            {
                // Get site collections URLs
                SPOSitePropertiesEnumerable properties = Element.GetSiteProperties(0, true);
                Context.Load(properties);
                Context.ExecuteQuery();

                // Crawl among site collections
                List <string> siteCollectionUrls = properties.Select(p => p.Url).ToList();

                List <SiteCollectionRunner> siteCollectionRunners = new List <SiteCollectionRunner>();
                foreach (string siteCollectionUrl in siteCollectionUrls)
                {
                    ClientContext ctx = new ClientContext(siteCollectionUrl)
                    {
                        Credentials = Context.Credentials
                    };
                    siteCollectionRunners.Add(new SiteCollectionRunner(Manager, ctx, ctx.Site));
                }

                siteCollectionRunners.ForEach(r => r.Process());
            }

            // OnTenantRunningEnd
            RunningManager.Logger.Debug("TenantRunner OnTenantRunningEnd()");
            ActiveReceivers.ForEach(r => r.OnTenantRunningEnd(Element));
        }
コード例 #3
0
        /// <summary>
        /// Action for this SharePoint term
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"TermRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         t => t.Name);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"Term | Name: {Element.Name}");

            // OnTermRunningStart
            RunningManager.Logger.Debug("TermRunner OnTermRunningStart()");
            ActiveReceivers.ForEach(r => r.OnTermRunningStart(Element));

            // Crawl sub terms
            Context.Load(Element.Terms);
            Context.ExecuteQuery();

            List <TermRunner> termRunners = new List <TermRunner>();

            foreach (Term term in Element.Terms)
            {
                termRunners.Add(new TermRunner(Manager, Context, term));
            }

            termRunners.ForEach(r => r.Process());

            // OnTermRunningEnd
            RunningManager.Logger.Debug("TermRunner OnTermRunningEnd()");
            ActiveReceivers.ForEach(r => r.OnTermRunningEnd(Element));
        }
コード例 #4
0
        /// <summary>
        /// Action for this SharePoint list item
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"ListItemRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         li => li.DisplayName);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"ListItem | DisplayName: {Element.DisplayName}");

            // OnListItemRunning
            RunningManager.Logger.Debug("ListItemRunner OnListItemRunning()");
            ActiveReceivers.ForEach(r => r.OnListItemRunning(Element));

            // If at least one receiver run files
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.File)))
            {
                Context.Load(Element,
                             li => li.FileSystemObjectType);
                Context.ExecuteQuery();

                // If there is a file
                if (Element.FileSystemObjectType == FileSystemObjectType.File)
                {
                    // Run file on current list item
                    FileRunner fileRunner = new FileRunner(Manager, Context, Element.File);
                    fileRunner.Process();
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Action for this SharePoint view
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"ViewRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         v => v.Title,
                         v => v.ServerRelativeUrl);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"View | Title: {Element.Title} / URL: {Element.ServerRelativeUrl}");

            // OnViewRunning
            RunningManager.Logger.Debug("ViewRunner OnViewRunning()");
            ActiveReceivers.ForEach(r => r.OnViewRunning(Element));
        }
コード例 #6
0
        /// <summary>
        /// Action for this SharePoint file
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"FileRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         f => f.Name,
                         f => f.ServerRelativeUrl);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"File | Name: {Element.Name} / URL: {Element.ServerRelativeUrl}");

            // OnFileRunning
            RunningManager.Logger.Debug("FileRunner OnFileRunning()");
            ActiveReceivers.ForEach(r => r.OnFileRunning(Element));
        }
コード例 #7
0
        /// <summary>
        /// Action for this SharePoint group
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"GroupRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         f => f.Id,
                         f => f.Title);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"Group | Id: {Element.Id} / Title: {Element.Title}");

            // OnGroupRunning
            RunningManager.Logger.Debug("GroupRunner OnGroupRunning()");
            ActiveReceivers.ForEach(r => r.OnGroupRunning(Element));
        }
コード例 #8
0
        /// <summary>
        /// Action for this SharePoint site collection
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"SiteCollectionRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         s => s.Url,
                         s => s.RootWeb);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"SiteCollection | URL: {Element.Url}");

            // OnSiteCollectionRunningStart
            RunningManager.Logger.Debug("SiteCollectionRunner OnSiteCollectionRunningStart()");
            ActiveReceivers.ForEach(r => r.OnSiteCollectionRunningStart(Element, Element.RootWeb));

            // If at least one receiver run groups
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.Group)))
            {
                // Crawl groups
                Context.Load(Element.RootWeb.SiteGroups);
                Context.ExecuteQuery();

                List <GroupRunner> groupRunners = new List <GroupRunner>();

                foreach (Group group in Element.RootWeb.SiteGroups)
                {
                    groupRunners.Add(new GroupRunner(Manager, Context, group));
                }

                groupRunners.ForEach(r => r.Process());
            }

            // If at least one receiver run sites or deeper
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.Site)))
            {
                // Run site on current root site
                SiteRunner siteRunner = new SiteRunner(Manager, Context, Element.RootWeb);
                siteRunner.Process();
            }

            // OnSiteCollectionRunningEnd
            RunningManager.Logger.Debug("SiteCollectionRunner OnSiteCollectionRunningEnd()");
            ActiveReceivers.ForEach(r => r.OnSiteCollectionRunningEnd(Element, Element.RootWeb));
        }
コード例 #9
0
        /// <summary>
        /// Action for this SharePoint site
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"SiteRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         s => s.Title,
                         s => s.Url);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"Site | Title: {Element.Title} / URL: {Element.Url}");

            // OnSiteRunningStart
            RunningManager.Logger.Debug("SiteRunner OnSiteRunningStart()");
            ActiveReceivers.ForEach(r => r.OnSiteRunningStart(Element));

            // If at least one receiver run lists or deeper
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.List)))
            {
                // Crawl Lists
                Context.Load(Element.Lists,
                             coll => coll.Include(
                                 l => l.Hidden));
                Context.ExecuteQuery();

                List <ListRunner> listRunners = new List <ListRunner>();

                IEnumerable <List> lists;
                if (Manager.Receivers.Any(r => r.IncludeHiddenLists))
                {
                    lists = Element.Lists;
                }
                else
                {
                    lists = Element.Lists.Where(l => !l.Hidden);
                }

                foreach (List list in lists)
                {
                    listRunners.Add(new ListRunner(Manager, Context, list));
                }

                listRunners.ForEach(r => r.Process());
            }

            // OnSiteRunningEnd
            RunningManager.Logger.Debug("SiteRunner OnSiteRunningEnd()");
            ActiveReceivers.ForEach(r => r.OnSiteRunningEnd(Element));

            // If at least one receiver run subsites
            if (Manager.Receivers.Any(r => r.IncludeSubSites))
            {
                // Crawl Subsites
                Context.Load(Element.Webs);
                Context.ExecuteQuery();

                List <SiteRunner> siteRunners = new List <SiteRunner>();
                foreach (Web subWeb in Element.Webs)
                {
                    siteRunners.Add(new SiteRunner(Manager, Context, subWeb, true));
                }

                siteRunners.ForEach(r => r.Process());

                // OnSiteRunningEndAfterSubSites
                RunningManager.Logger.Debug("SiteRunner OnSiteRunningEndAfterSubSites()");
                ActiveReceivers.ForEach(r => r.OnSiteRunningEndAfterSubSites(Element));
            }
        }
コード例 #10
0
        /// <summary>
        /// Action for this SharePoint folder
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"FolderRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         f => f.Name,
                         f => f.ServerRelativeUrl,
                         f => f.ListItemAllFields["FileRef"],
                         f => f.ListItemAllFields.ParentList.ItemCount);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"Folder | Name: {Element.Name} / URL: {Element.ServerRelativeUrl}");

            // OnFolderRunningStart
            RunningManager.Logger.Debug("FolderRunner OnFolderRunningStart()");
            ActiveReceivers.ForEach(r => r.OnFolderRunningStart(Element));

            // If at least one receiver run list items of deeper
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.ListItem)))
            {
                List <ListItem> items = new List <ListItem>();

                if (Element.ListItemAllFields.ParentList.ItemCount > 5000)
                {
                    // Manage large lists
                    int count     = 0;
                    int inter     = 1000;
                    int countList = Element.ListItemAllFields.ParentList.ItemCount;

                    while (count < countList)
                    {
                        CamlQuery itemsQuery = new CamlQuery()
                        {
                            FolderServerRelativeUrl = Element.ListItemAllFields["FileRef"].ToString(),
                            ViewXml = $"<View><Query><Where><And><Gt><FieldRef Name='ID'/><Value Type='Counter'>{count}</Value></Gt><Leq><FieldRef Name='ID'/><Value Type='Counter'>{count + inter}</Value></Leq></And></Where><OrderBy Override='TRUE'><FieldRef Name='ID'/></OrderBy></Query></View><RowLimit>{inter}</RowLimit>"
                        };

                        ListItemCollection itemsResult = Element.ListItemAllFields.ParentList.GetItems(itemsQuery);
                        Context.Load(itemsResult);
                        Context.ExecuteQuery();
                        items.AddRange(itemsResult);

                        count += inter;
                    }
                }
                else
                {
                    CamlQuery itemsQuery = new CamlQuery()
                    {
                        FolderServerRelativeUrl = Element.ListItemAllFields["FileRef"].ToString(),
                        ViewXml = "<View><Query></Query></View>"
                    };

                    ListItemCollection itemsResult = Element.ListItemAllFields.ParentList.GetItems(itemsQuery);
                    Context.Load(itemsResult);
                    Context.ExecuteQuery();
                    items = itemsResult.ToList();
                }

                List <ListItemRunner> itemRunners = new List <ListItemRunner>();
                foreach (ListItem item in items)
                {
                    itemRunners.Add(new ListItemRunner(Manager, Context, item));
                }

                itemRunners.ForEach(r => r.Process());
            }

            // OnFolderRunningEnd
            RunningManager.Logger.Debug("FolderRunner OnFolderRunningEnd()");
            ActiveReceivers.ForEach(r => r.OnFolderRunningEnd(Element));

            List <ListItem> subFolders = new List <ListItem>();

            if (Element.ListItemAllFields.ParentList.ItemCount > 5000)
            {
                // Manage large lists
                int count     = 0;
                int inter     = 1000;
                int countList = Element.ListItemAllFields.ParentList.ItemCount;

                while (count < countList)
                {
                    CamlQuery subFoldersQuery = new CamlQuery()
                    {
                        FolderServerRelativeUrl = Element.ListItemAllFields["FileRef"].ToString(),
                        ViewXml = $"<View><Query><Where><And><And><Gt><FieldRef Name='ID'/><Value Type='Counter'>{count}</Value></Gt><Leq><FieldRef Name='ID'/><Value Type='Counter'>{count + inter}</Value></Leq></And><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></And></Where><OrderBy Override='TRUE'><FieldRef Name='ID'/></OrderBy></Query></View><RowLimit>{inter}</RowLimit>"
                    };

                    ListItemCollection subFoldersResult = Element.ListItemAllFields.ParentList.GetItems(subFoldersQuery);
                    Context.Load(subFoldersResult);
                    Context.ExecuteQuery();
                    subFolders.AddRange(subFoldersResult);

                    count += inter;
                }
            }
            else
            {
                CamlQuery subFoldersQuery = new CamlQuery()
                {
                    FolderServerRelativeUrl = Element.ListItemAllFields["FileRef"].ToString(),
                    ViewXml = "<View><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where></Query></View>"
                };

                // Crawl sub folders
                ListItemCollection subFoldersResult = Element.ListItemAllFields.ParentList.GetItems(subFoldersQuery);
                Context.Load(subFoldersResult,
                             coll => coll.Include(
                                 f => f.Folder));
                Context.ExecuteQuery();
                subFolders = subFoldersResult.ToList();
            }

            List <FolderRunner> folderRunners = new List <FolderRunner>();

            foreach (ListItem folder in subFolders)
            {
                folderRunners.Add(new FolderRunner(Manager, Context, folder.Folder));
            }

            folderRunners.ForEach(r => r.Process());

            // OnFolderRunningEndAfterSubFolders
            RunningManager.Logger.Debug("FolderRunner OnFolderRunningEndAfterSubFolders()");
            ActiveReceivers.ForEach(r => r.OnFolderRunningEndAfterSubFolders(Element));
        }
コード例 #11
0
        /// <summary>
        /// Action for this SharePoint list
        /// </summary>
        public override void Process()
        {
            RunningManager.Logger.Debug($"ListRunner Process() - {ActiveReceivers.Count} active receivers");
            Context.Load(Element,
                         l => l.Title,
                         l => l.RootFolder.ServerRelativeUrl);
            Context.ExecuteQuery();
            RunningManager.Logger.Debug($"List | Title: {Element.Title} / URL: {Element.RootFolder.ServerRelativeUrl}");

            // OnListRunningStart
            RunningManager.Logger.Debug("ListRunner OnListRunningStart()");
            ActiveReceivers.ForEach(r => r.OnListRunningStart(Element));

            // If at least one receiver run views
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.View)))
            {
                // Crawl views
                Context.Load(Element.Views);
                Context.ExecuteQuery();

                List <ViewRunner> viewRunners = new List <ViewRunner>();
                foreach (View view in Element.Views)
                {
                    viewRunners.Add(new ViewRunner(Manager, Context, view));
                }

                viewRunners.ForEach(r => r.Process());
            }

            // If at least one receiver run folders or deeper
            if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.Folder)))
            {
                List <ListItem> folders = new List <ListItem>();

                if (Element.ItemCount > 5000)
                {
                    // Manage large lists
                    int count     = 0;
                    int inter     = 1000;
                    int countList = Element.ItemCount;

                    while (count < countList)
                    {
                        CamlQuery foldersQuery = new CamlQuery()
                        {
                            ViewXml = $"<View><Query><Where><And><And><Gt><FieldRef Name='ID'/><Value Type='Counter'>{count}</Value></Gt><Leq><FieldRef Name='ID'/><Value Type='Counter'>{count + inter}</Value></Leq></And><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></And></Where><OrderBy Override='TRUE'><FieldRef Name='ID'/></OrderBy></Query></View><RowLimit>{inter}</RowLimit>"
                        };

                        ListItemCollection foldersResult = Element.GetItems(foldersQuery);
                        Context.Load(foldersResult);
                        Context.ExecuteQuery();
                        folders.AddRange(foldersResult);

                        count += inter;
                    }
                }
                else
                {
                    CamlQuery foldersQuery = new CamlQuery()
                    {
                        ViewXml = "<View><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where></Query></View>"
                    };

                    ListItemCollection foldersResult = Element.GetItems(foldersQuery);
                    Context.Load(foldersResult,
                                 coll => coll.Include(
                                     f => f.Folder));
                    Context.ExecuteQuery();
                    folders = foldersResult.ToList();
                }

                List <FolderRunner> folderRunners = new List <FolderRunner>();
                foreach (ListItem folder in folders)
                {
                    folderRunners.Add(new FolderRunner(Manager, Context, folder.Folder));
                }

                folderRunners.ForEach(r => r.Process());
            }
            else if (Manager.Receivers.Any(r => r.IsReceiverCalledOrDeeper(RunningLevel.ListItem)))
            {
                List <ListItem> items = new List <ListItem>();

                if (Element.ItemCount > 5000)
                {
                    // Manage large lists
                    int count     = 0;
                    int inter     = 1000;
                    int countList = Element.ItemCount;

                    while (count < countList)
                    {
                        CamlQuery itemsQuery = new CamlQuery()
                        {
                            ViewXml = $"<View Scope='RecursiveAll'><Query><Where><And><Gt><FieldRef Name='ID'/><Value Type='Counter'>{count}</Value></Gt><Leq><FieldRef Name='ID'/><Value Type='Counter'>{count + inter}</Value></Leq></And></Where><OrderBy Override='TRUE'><FieldRef Name='ID'/></OrderBy></Query></View><RowLimit>{inter}</RowLimit>"
                        };

                        ListItemCollection itemsResult = Element.GetItems(itemsQuery);
                        Context.Load(itemsResult);
                        Context.ExecuteQuery();
                        items.AddRange(itemsResult);

                        count += inter;
                    }
                }
                else
                {
                    CamlQuery itemsQuery = new CamlQuery()
                    {
                        ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"
                    };

                    ListItemCollection itemsResult = Element.GetItems(itemsQuery);
                    Context.Load(itemsResult);
                    Context.ExecuteQuery();
                    items = itemsResult.ToList();
                }

                List <ListItemRunner> itemRunners = new List <ListItemRunner>();
                foreach (ListItem item in items)
                {
                    itemRunners.Add(new ListItemRunner(Manager, Context, item));
                }

                itemRunners.ForEach(r => r.Process());
            }

            // OnListRunningEnd
            RunningManager.Logger.Debug("ListRunner OnListRunningEnd()");
            ActiveReceivers.ForEach(r => r.OnListRunningEnd(Element));
        }