Exemple #1
0
        public void LoadSites(ClientContext tenantAdminClientContext)
        {
            var allSitesList = this.store.GetAndInitialize <List <SiteInformation> >(storeOptions.GetKey(keyAllSitesList));

            if (allSitesList.Count > 0)
            {
                this.SiteInformation.Clear();
                this.SiteInformation.AddRange(allSitesList);
                return;
            }

            tenantAdminClientContext.Web.EnsureProperty(p => p.Url);
            var sitesList = tenantAdminClientContext.Web.GetList($"{tenantAdminClientContext.Web.Url}/Lists/{SitesInformationListUrl}");

            tenantAdminClientContext.ExecuteQueryRetry();

            // Query the list to obtain the sites to return
            CamlQuery camlQuery = new CamlQuery
            {
                ViewXml = SitesListQuery
            };

            do
            {
                var sites = sitesList.GetItems(camlQuery);
                sitesList.Context.Load(sites, i => i.IncludeWithDefaultProperties(li => li.FieldValuesAsText), i => i.ListItemCollectionPosition);
                sitesList.Context.ExecuteQueryRetry();
                foreach (var site in sites)
                {
                    // Only keep which are not deleted
                    if (site["TimeDeleted"] != null)
                    {
                        continue;
                    }

                    // No point in keeping this data in memory if we're sure there's no site that will use it
                    //if (!containsWildCardUrl)
                    //{
                    //    if (addedSites.FindIndex(x => x.Equals(site["SiteUrl"].ToString(), StringComparison.OrdinalIgnoreCase)) == -1)
                    //    {
                    //        continue;
                    //    }
                    //}

                    if (this.SiteInformation.Where(p => p.SiteUrl.Equals(site["SiteUrl"].ToString())).FirstOrDefault() == null)
                    {
                        DateTime.TryParse(site["LastActivityOn"]?.ToString(), out DateTime lastActivityOn);

                        var siteInfo = new SiteInformation()
                        {
                            SiteUrl      = site["SiteUrl"].ToString(),
                            Title        = site["Title"] != null ? site["Title"].ToString() : "",
                            PagesVisited = site["PagesVisited"] != null?int.Parse(site["PagesVisited"].ToString()) : 0,
                                               PageViews = site["PageViews"] != null?int.Parse(site["PageViews"].ToString()) : 0,
                                                               LastActivityOn = lastActivityOn
                        };

                        if (site["AllowGuestUserSignIn"] != null)
                        {
                            siteInfo.AllowGuestUserSignIn = bool.Parse(site["AllowGuestUserSignIn"].ToString());
                        }

                        if (site["ExternalSharing"] != null)
                        {
                            if (site["ExternalSharing"].ToString().Equals("On", StringComparison.InvariantCultureIgnoreCase))
                            {
                                siteInfo.ExternalSharing = true;
                            }
                            else
                            {
                                siteInfo.ExternalSharing = false;
                            }
                        }

                        if (site.IsPropertyAvailable("ShareByEmailEnabled") && site["ShareByEmailEnabled"] != null)
                        {
                            siteInfo.ShareByEmailEnabled = bool.Parse(site["ShareByEmailEnabled"].ToString());
                        }

                        if (site.IsPropertyAvailable("ShareByLinkEnabled") && site["ShareByLinkEnabled"] != null)
                        {
                            siteInfo.ShareByLinkEnabled = bool.Parse(site["ShareByLinkEnabled"].ToString());
                        }

                        this.SiteInformation.Add(siteInfo);
                    }
                }
                camlQuery.ListItemCollectionPosition = sites.ListItemCollectionPosition;
            } while (camlQuery.ListItemCollectionPosition != null);

            // Cache the data for future use
            this.store.Set <List <SiteInformation> >(this.storeOptions.GetKey(keyAllSitesList), this.SiteInformation, storeOptions.EntryOptions);
        }
Exemple #2
0
        private void LoadSites(ClientContext tenantAdminClientContext)
        {
            tenantAdminClientContext.Web.EnsureProperty(p => p.Url);
            var sitesList = tenantAdminClientContext.Web.GetList($"{tenantAdminClientContext.Web.Url}/Lists/{SitesInformationListUrl}");

            tenantAdminClientContext.ExecuteQueryRetry();

            // Query the list to obtain the sites to return
            CamlQuery camlQuery = new CamlQuery
            {
                ViewXml = SitesListQuery
            };

            do
            {
                var sites = sitesList.GetItems(camlQuery);
                sitesList.Context.Load(sites, i => i.IncludeWithDefaultProperties(li => li.FieldValuesAsText), i => i.ListItemCollectionPosition);
                sitesList.Context.ExecuteQueryRetry();
                foreach (var site in sites)
                {
                    if (this.SiteInformation.Where(p => p.SiteUrl.Equals(site["SiteUrl"].ToString())).FirstOrDefault() == null)
                    {
                        DateTime.TryParse(site["LastActivityOn"]?.ToString(), out DateTime lastActivityOn);

                        var siteInfo = new SiteInformation()
                        {
                            SiteUrl      = site["SiteUrl"].ToString(),
                            Title        = site["Title"] != null ? site["Title"].ToString() : "",
                            PagesVisited = site["PagesVisited"] != null?int.Parse(site["PagesVisited"].ToString()) : 0,
                                               PageViews = site["PageViews"] != null?int.Parse(site["PageViews"].ToString()) : 0,
                                                               LastActivityOn = lastActivityOn
                        };

                        if (site["AllowGuestUserSignIn"] != null)
                        {
                            siteInfo.AllowGuestUserSignIn = bool.Parse(site["AllowGuestUserSignIn"].ToString());
                        }

                        if (site["ExternalSharing"] != null)
                        {
                            if (site["ExternalSharing"].ToString().Equals("On", StringComparison.InvariantCultureIgnoreCase))
                            {
                                siteInfo.ExternalSharing = true;
                            }
                            else
                            {
                                siteInfo.ExternalSharing = false;
                            }
                        }

                        if (site["ShareByEmailEnabled"] != null)
                        {
                            siteInfo.ShareByEmailEnabled = bool.Parse(site["ShareByEmailEnabled"].ToString());
                        }

                        if (site["ShareByLinkEnabled"] != null)
                        {
                            siteInfo.ShareByLinkEnabled = bool.Parse(site["ShareByLinkEnabled"].ToString());
                        }

                        this.SiteInformation.Add(siteInfo);
                    }
                }
                camlQuery.ListItemCollectionPosition = sites.ListItemCollectionPosition;
            } while (camlQuery.ListItemCollectionPosition != null);
        }