Пример #1
0
        private void DoTenant(Tenant tenant, BaseNode tenantNode, BaseNode rootNode)
        {
            try
            {
                var context   = tenant.Context as ClientContext;
                var siteProps = tenant.GetSiteProperties(0, true);
                context.Load(siteProps);
                context.ExecuteQuery();

                foreach (var site in siteProps)
                {
                    var websContext = AuthUtil.GetContext(this.AuthenticationType, site.Url, this.Username, this.Password);
                    // Leaving this commented out for now, slows the load down massively
                    //websContext.Web.EnsureProperties(w => w.Title, w => w.Url);

                    // By using a Scoped Web, we can let the iteration continue as normal and rendering can be quick
                    // Because otherwise we need to use Tenant.GetSiteByUrl() and request that each time
                    // Which makes rendering the contents of the tenant VERY slow.

                    BaseNode webNode = new ScopedWebNode(websContext);
                    webNode.Title         = site.Title;
                    webNode.Url           = site.Url;
                    webNode.ParentNode    = tenantNode;
                    webNode.RootNode      = rootNode;
                    webNode.NodeConnector = this;

                    if (string.IsNullOrWhiteSpace(webNode.Title))
                    {
                        webNode.Title = webNode.Url;
                    }

                    tenantNode.Children.Add(webNode);
                }
            }
            catch (Exception ex)
            {
                SPCoderLogging.Logger.Error($"Failed to fetch site: {ex.Message}");
            }
        }