当前位置: 首页>>代码示例>>C#>>正文


C# Tenant.GetSiteByUrl方法代码示例

本文整理汇总了C#中Tenant.GetSiteByUrl方法的典型用法代码示例。如果您正苦于以下问题:C# Tenant.GetSiteByUrl方法的具体用法?C# Tenant.GetSiteByUrl怎么用?C# Tenant.GetSiteByUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tenant的用法示例。


在下文中一共展示了Tenant.GetSiteByUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSiteCollection

        public override void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
 
            UsingContext(ctx =>
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();

                    Tenant _tenant = new Tenant(ctx);
                    var _newsite = new SiteCreationProperties();
                    _newsite.Title = siteRequest.Title;
                    _newsite.Url = siteRequest.Url;
                    _newsite.Owner = siteRequest.SiteOwner.Name;
                    _newsite.Template = template.RootTemplate;
                    _newsite.Lcid = siteRequest.Lcid;
                    _newsite.TimeZoneId = siteRequest.TimeZoneId;
                    _newsite.StorageMaximumLevel = template.StorageMaximumLevel;
                    _newsite.StorageWarningLevel = template.StorageWarningLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeMaximumLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeWarningLevel;

                    SpoOperation op = _tenant.CreateSite(_newsite);
                    ctx.Load(_tenant);
                    ctx.Load(op, i => i.IsComplete);
                    ctx.ExecuteQuery();

                    while (!op.IsComplete)
                    {
                        //wait 30seconds and try again
                        System.Threading.Thread.Sleep(30000);
                        op.RefreshLoad();
                        ctx.ExecuteQuery();
                    }
                    
                    var _site = _tenant.GetSiteByUrl(siteRequest.Url);
                    var _web = _site.RootWeb;
                    _web.Description = siteRequest.Description;
                    _web.Update();
                    ctx.Load(_web);
                    ctx.ExecuteQuery();

                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.CreateSiteCollection", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
                }
            
                catch (Exception ex)
                {
                    Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
                        PCResources.SiteCreation_Creation_Failure, 
                        siteRequest.Url, ex.Message, ex);
                    throw;
                }
               Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
            });
        }
开发者ID:sndkr,项目名称:PnP,代码行数:57,代码来源:Office365SiteProvisioningService.cs

示例2: HandleDefaultGroups

        /// <summary>
        /// With on-premises builds default groups are not created during site provisioning 
        /// so we have to create them.
        /// </summary>
        /// <param name="properties"></param>
        public virtual void HandleDefaultGroups(SiteInformation properties)
        {            
            string _ownerGroupDisplayName =string.Format(PCResources.Site_Web_OwnerGroup_Title, properties.Title);
            string _memberGroupDisplayName = string.Format(PCResources.Site_Web_MemberGroup_Title, properties.Title);
            string _vistorGroupDisplayName = string.Format(PCResources.Site_Web_VisitorGroup_Title, properties.Title);

            UsingContext(ctx =>
            {
                Tenant tenant = new Tenant(ctx);
                var site = tenant.GetSiteByUrl(properties.Url);
                var web = site.RootWeb;

                ctx.Load(web.AssociatedOwnerGroup);
                ctx.Load(web.AssociatedMemberGroup);
                ctx.Load(web.AssociatedVisitorGroup);
                ctx.ExecuteQuery();

                Group _ownerGroup;
                Group _memberGroup;
                Group _visitorGroup;
                if (web.AssociatedOwnerGroup.ServerObjectIsNull == true) {
                    _ownerGroup = web.AddGroup(_ownerGroupDisplayName, PCResources.Site_Web_OwnerGroup_Description, true, false);
                }
                else {
                    _ownerGroup = web.AssociatedOwnerGroup;
                }
                if (web.AssociatedMemberGroup.ServerObjectIsNull == true) {
                    _memberGroup = web.AddGroup(_memberGroupDisplayName, PCResources.Site_Web_MemberGroup_Description, false, false);
                }
                else {
                    _memberGroup = web.AssociatedMemberGroup;
                }
                if (web.AssociatedVisitorGroup.ServerObjectIsNull == true) {
                        _visitorGroup = web.AddGroup(_vistorGroupDisplayName, PCResources.Site_Web_VisitorGroup_Description, false, false );
                }
                else {
                    _visitorGroup = web.AssociatedVisitorGroup;
                }

                web.AssociateDefaultGroups(_ownerGroup, _memberGroup, _visitorGroup);
                ctx.ExecuteQuery();
               Log.Info("Provisioning.Common.OnPremSiteProvisioningService.HandleDefaultGroups", PCResources.Site_Web_DefaultGroups_Created, properties.Url);

                using (var newSiteCtx = ctx.Clone(properties.Url))
                {
                    newSiteCtx.Web.AddPermissionLevelToGroup(_ownerGroupDisplayName, RoleType.Administrator);
                    newSiteCtx.Web.AddPermissionLevelToGroup(_memberGroupDisplayName, RoleType.Editor);
                    newSiteCtx.Web.AddPermissionLevelToGroup(_vistorGroupDisplayName, RoleType.Reader);
                    newSiteCtx.ExecuteQuery();
                   Log.Info("Provisioning.Common.OnPremSiteProvisioningService.HandleDefaultGroups", PCResources.Site_Web_Groups_Security_Permissions_Set, 
                        _ownerGroupDisplayName, 
                        _memberGroupDisplayName, 
                        _vistorGroupDisplayName);
                }
            });

        }
开发者ID:nats31,项目名称:PnP,代码行数:62,代码来源:OnPremSiteProvisioningService.cs

示例3: GetExternalUsersForSiteTenant

        /// <summary>
        /// Returns a list all external users for a given site that have at least the viewpages permission
        /// </summary>
        /// <param name="web">Tenant administration web</param>
        /// <param name="siteUrl">Url of the site fetch the external users for</param>
        /// <returns>A list of <see cref="OfficeDevPnP.Core.Entities.ExternalUserEntity"/> objects</returns>
        public static List<ExternalUserEntity> GetExternalUsersForSiteTenant(this Web web, Uri siteUrl)
        {
            if (siteUrl == null)
                throw new ArgumentNullException("siteUrl");

            Tenant tenantAdmin = new Tenant(web.Context);
            Office365Tenant tenant = new Office365Tenant(web.Context);
            Site site = tenantAdmin.GetSiteByUrl(siteUrl.OriginalString);
            web = site.RootWeb;

            List<ExternalUserEntity> externalUsers = new List<ExternalUserEntity>();
            int pageSize = 50;
            int position = 0;
            GetExternalUsersResults results = null;

            while (true)
            {
                results = tenant.GetExternalUsersForSite(siteUrl.OriginalString, position, pageSize, string.Empty, SortOrder.Ascending);
                web.Context.Load(results, r => r.UserCollectionPosition, r => r.TotalUserCount, r => r.ExternalUserCollection);
                web.Context.ExecuteQuery();

                foreach (var externalUser in results.ExternalUserCollection)
                {

                    User user = web.SiteUsers.GetByEmail(externalUser.AcceptedAs);
                    web.Context.Load(user);
                    web.Context.ExecuteQuery();

                    var permission = web.GetUserEffectivePermissions(user.LoginName);
                    web.Context.ExecuteQuery();
                    var doesUserHavePermission = permission.Value.Has(PermissionKind.ViewPages);
                    if (doesUserHavePermission)
                    {
                        externalUsers.Add(new ExternalUserEntity()
                        {
                            DisplayName = externalUser.DisplayName,
                            AcceptedAs = externalUser.AcceptedAs,
                            InvitedAs = externalUser.InvitedAs,
                            InvitedBy = externalUser.InvitedBy,
                            UniqueId = externalUser.UniqueId,
                            WhenCreated = externalUser.WhenCreated
                        });
                    }

                }

                position = results.UserCollectionPosition;

                if (position == -1 || position == results.TotalUserCount)
                {
                    break;
                }
            }

            return externalUsers;
        }
开发者ID:ADefWebserver,项目名称:PnP,代码行数:62,代码来源:SecurityExtensions.cs

示例4: CreateSiteCollection

        public override void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);

            UsingContext(ctx =>
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();                    

                    Tenant _tenant = new Tenant(ctx);
                    var _newsite = new SiteCreationProperties();
                    _newsite.Title = siteRequest.Title;                    
                    _newsite.Url = siteRequest.Url;
                    _newsite.Owner = siteRequest.SiteOwner.Email;
                    _newsite.Template = template.RootTemplate;
                    _newsite.Lcid = siteRequest.Lcid;
                    _newsite.TimeZoneId = siteRequest.TimeZoneId;
                    _newsite.StorageMaximumLevel = template.StorageMaximumLevel;
                    _newsite.StorageWarningLevel = template.StorageWarningLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeMaximumLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeWarningLevel;


                    try
                    {
                        SpoOperation _spoOperation = _tenant.CreateSite(_newsite);
                        ctx.Load(_tenant);
                        ctx.Load(_spoOperation);
                        ctx.ExecuteQuery();

                        try
                        {
                            this.OperationWithRetry(ctx, _spoOperation, siteRequest);
                        }
                        catch(ServerException ex)
                        {
                            var _message = string.Format("Error occured while provisioning site {0}, ServerErrorTraceCorrelationId: {1} Exception: {2}", siteRequest.Url, ex.ServerErrorTraceCorrelationId, ex);
                            Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", _message);
                            throw;
                        }
                                                

                    }
                    catch (ServerException ex)
                    {
                        var _message = string.Format("Error occured while provisioning site {0}, ServerErrorTraceCorrelationId: {1} Exception: {2}", siteRequest.Url, ex.ServerErrorTraceCorrelationId, ex);
                        Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", _message);
                        throw;
                    }


                    var _site = _tenant.GetSiteByUrl(siteRequest.Url);
                    var _web = _site.RootWeb;
                    _web.Description = siteRequest.Description;
                    _web.Update();
                    ctx.Load(_web);
                    ctx.ExecuteQuery();
                    User newOwner = _web.EnsureUser(siteRequest.SiteOwner.Email);
                    ctx.Load(newOwner);
                    ctx.ExecuteQuery();

                    if (!newOwner.ServerObjectIsNull.Value)
                    {
                        //_site.Owner = newOwner;
                        //ctx.Load(_site);
                        //ctx.Load(_site.Owner);
                        //ctx.ExecuteQuery();
                        newOwner.IsSiteAdmin = true;
                        newOwner.Update();
                        ctx.Load(newOwner);
                        ctx.ExecuteQuery();
               }
                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.CreateSiteCollection", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
                }

                catch (Exception ex)
                {
                    Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
                        PCResources.SiteCreation_Creation_Failure,
                        siteRequest.Url, ex.Message, ex);
                    throw;
                }
                Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
            }, SPDataConstants.CSOM_WAIT_TIME);
        }
开发者ID:iozag,项目名称:PnP,代码行数:87,代码来源:Office365SiteProvisioningService.cs

示例5: CreateSiteCollection

        public override void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
           Log.Info("Provisioning.Common.OnPremSiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
            
            Web _web = null;
            try
            {
                UsingContext(ctx =>
                {
                    Tenant _tenant = new Tenant(ctx);
                    var _newsite = new SiteCreationProperties();
                    _newsite.Title = siteRequest.Title;
                    _newsite.Url = siteRequest.Url;
                    _newsite.Owner = siteRequest.SiteOwner.Name;
                    _newsite.Template = template.RootTemplate;
                    _newsite.Lcid = siteRequest.Lcid;
                    _newsite.TimeZoneId = siteRequest.TimeZoneId;
                    _newsite.StorageMaximumLevel = template.StorageMaximumLevel;
                    _newsite.StorageWarningLevel = template.StorageWarningLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeMaximumLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeWarningLevel;
                    _tenant.CreateSite(_newsite);
                    ctx.ExecuteQuery();

                    Tenant tenant = new Tenant(ctx);
                    var site = tenant.GetSiteByUrl(siteRequest.Url);

                    using (var _cloneCtx = site.Context.Clone(siteRequest.Url))
                    {
                         _web = _cloneCtx.Site.RootWeb;
                         _web.Description = siteRequest.Description;
                         _web.Update();
                        _cloneCtx.Load(_web);
                        _cloneCtx.ExecuteQuery();
                    }
                }, 1200000);
            }
            catch(Exception ex)
            {
                Log.Error("Provisioning.Common.OnPremSiteProvisioningService.CreateSiteCollection",
                    PCResources.SiteCreation_Creation_Failure, 
                    siteRequest.Url, 
                    ex,
                    ex.InnerException);
                throw;
            }
           Log.Info("Provisioning.Common.OnPremSiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
            this.HandleDefaultGroups(siteRequest);
        }
开发者ID:nats31,项目名称:PnP,代码行数:49,代码来源:OnPremSiteProvisioningService.cs

示例6: SubSiteExistsTest

        public void SubSiteExistsTest()
        {
            using (var tenantContext = TestCommon.CreateTenantClientContext())
            {
                var tenant = new Tenant(tenantContext);
                string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
                Console.WriteLine("SubSiteExistsTest: step 1");
                string siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
                Console.WriteLine("SubSiteExistsTest: step 1.1");
                string subSiteUrlGood = "";
                string subSiteUrlWrong = "";

                Site site = tenant.GetSiteByUrl(siteToCreateUrl);
                tenant.Context.Load(site);
                tenant.Context.ExecuteQueryRetry();
                Web web = site.RootWeb;
                web.Context.Load(web);
                web.Context.ExecuteQueryRetry();
                Console.WriteLine("SubSiteExistsTest: step 1.2");

                //Create sub site
                SiteEntity sub = new SiteEntity() { Title = "Test Sub", Url = "sub", Description = "Test" };
                web.CreateWeb(sub);
                siteToCreateUrl = UrlUtility.EnsureTrailingSlash(siteToCreateUrl);
                subSiteUrlGood = String.Format("{0}{1}", siteToCreateUrl, sub.Url);
                subSiteUrlWrong = String.Format("{0}{1}", siteToCreateUrl, "8988980");

                // Check real sub site
                Console.WriteLine("SubSiteExistsTest: step 2");
                bool subSiteExists = tenant.SubSiteExists(subSiteUrlGood);
                Console.WriteLine("SubSiteExistsTest: step 2.1");
                Assert.IsTrue(subSiteExists);

                // check non existing sub site
                Console.WriteLine("SubSiteExistsTest: step 3");
                bool subSiteExists2 = tenant.SubSiteExists(subSiteUrlWrong);
                Console.WriteLine("SubSiteExistsTest: step 3.1");
                Assert.IsFalse(subSiteExists2);

                // check root site (= site collection). Will return true when existing
                Console.WriteLine("SubSiteExistsTest: step 4");
                bool subSiteExists3 = tenant.SubSiteExists(siteToCreateUrl);
                Console.WriteLine("SubSiteExistsTest: step 4.1");
                Assert.IsTrue(subSiteExists3);

                // check root site (= site collection) that does not exist. Will return false when non-existant
                Console.WriteLine("SubSiteExistsTest: step 5");
                bool subSiteExists4 = tenant.SubSiteExists(siteToCreateUrl + "8808809808");
                Console.WriteLine("SubSiteExistsTest: step 5.1");
                Assert.IsFalse(subSiteExists4);
            }
        }
开发者ID:stijnbrouwers,项目名称:PnP-Sites-Core,代码行数:52,代码来源:TenantExtensionsTests.cs

示例7: CreateSiteCollection

        private void CreateSiteCollection(SiteCollectionProvisioningJob job)
        {
            Console.WriteLine("Creating Site Collection \"{0}\".", job.RelativeUrl);

            // Define the full Site Collection URL
            String siteUrl = String.Format("{0}{1}",
                PnPPartnerPackSettings.InfrastructureSiteUrl.Substring(0, PnPPartnerPackSettings.InfrastructureSiteUrl.IndexOf("sharepoint.com/") + 14),
                job.RelativeUrl);

            using (var adminContext = PnPPartnerPackContextProvider.GetAppOnlyTenantLevelClientContext())
            {
                // Configure the Site Collection properties
                SiteEntity newSite = new SiteEntity();
                newSite.Description = job.Description;
                newSite.Lcid = (uint)job.Language;
                newSite.Title = job.SiteTitle;
                newSite.Url = siteUrl;
                newSite.SiteOwnerLogin = job.PrimarySiteCollectionAdmin;
                newSite.StorageMaximumLevel = job.StorageMaximumLevel;
                newSite.StorageWarningLevel = job.StorageWarningLevel;
                newSite.Template = PnPPartnerPackSettings.DefaultSiteTemplate;
                newSite.TimeZoneId = job.TimeZone;
                newSite.UserCodeMaximumLevel = job.UserCodeMaximumLevel;
                newSite.UserCodeWarningLevel = job.UserCodeWarningLevel;

                // Create the Site Collection and wait for its creation (we're asynchronous)
                var tenant = new Tenant(adminContext);
                tenant.CreateSiteCollection(newSite, true, true); // TODO: Do we want to empty Recycle Bin?

                Site site = tenant.GetSiteByUrl(siteUrl);
                Web web = site.RootWeb;

                adminContext.Load(site, s => s.Url);
                adminContext.Load(web, w => w.Url);
                adminContext.ExecuteQueryRetry();

                // Enable Secondary Site Collection Administrator
                if (!String.IsNullOrEmpty(job.SecondarySiteCollectionAdmin))
                {
                    Microsoft.SharePoint.Client.User secondaryOwner = web.EnsureUser(job.SecondarySiteCollectionAdmin);
                    secondaryOwner.IsSiteAdmin = true;
                    secondaryOwner.Update();

                    web.SiteUsers.AddUser(secondaryOwner);
                    adminContext.ExecuteQueryRetry();
                }

                Console.WriteLine("Site \"{0}\" created.", site.Url);

                // Check if external sharing has to be enabled
                if (job.ExternalSharingEnabled)
                {
                    EnableExternalSharing(tenant, site);

                    // Enable External Sharing
                    Console.WriteLine("Enabled External Sharing for site \"{0}\".",
                        site.Url);
                }
            }

            // Move to the context of the created Site Collection
            using (ClientContext clientContext = PnPPartnerPackContextProvider.GetAppOnlyClientContext(siteUrl))
            {
                Site site = clientContext.Site;
                Web web = site.RootWeb;

                clientContext.Load(site, s => s.Url);
                clientContext.Load(web, w => w.Url);
                clientContext.ExecuteQueryRetry();

                // Check if we need to enable PnP Partner Pack overrides
                if (job.PartnerPackExtensionsEnabled)
                {
                    // Enable Responsive Design
                    PnPPartnerPackUtilities.EnablePartnerPackOnSite(site.Url);

                    Console.WriteLine("Enabled PnP Partner Pack Overrides on site \"{0}\".",
                        site.Url);
                }

                // Check if the site has to be responsive
                if (job.ResponsiveDesignEnabled)
                {
                    // Enable Responsive Design
                    PnPPartnerPackUtilities.EnableResponsiveDesignOnSite(site.Url);

                    Console.WriteLine("Enabled Responsive Design Template to site \"{0}\".",
                        site.Url);
                }

                // Apply the Provisioning Template
                Console.WriteLine("Applying Provisioning Template \"{0}\" to site.",
                    job.ProvisioningTemplateUrl);

                // Determine the reference URLs and file names
                String templatesSiteUrl = PnPPartnerPackUtilities.GetSiteCollectionRootUrl(job.ProvisioningTemplateUrl);
                String templateFileName = job.ProvisioningTemplateUrl.Substring(job.ProvisioningTemplateUrl.LastIndexOf("/") + 1);

                using (ClientContext repositoryContext = PnPPartnerPackContextProvider.GetAppOnlyClientContext(templatesSiteUrl))
                {
//.........这里部分代码省略.........
开发者ID:comblox,项目名称:PnP-Partner-Pack,代码行数:101,代码来源:SiteCollectionProvisioningJobHandler.cs

示例8: CreateSiteCollection

        public string CreateSiteCollection()
        {
            var user = GetSpUser.ResolveUserById(_ctx, _actionRequest.User);
            var tenant = new Tenant(_ctx);

            var webUrl =
                $"https://{_actionRequest.TenantName}.sharepoint.com/{_siteCollectionRequest.ManagedPath}/{_actionRequest.Name}";
            if (tenant.SiteExists(webUrl))
            {
                // "Site already existed. Used URL - {0}"
            }
            else
            {

                var newsite = new SiteCreationProperties
                {
                    Title = _actionRequest.Name,
                    Url = webUrl,
                    Owner = user.Email,
                    Template = "STS#0",
                    Lcid = _siteCollectionRequest.Lcid,
                    TimeZoneId = _siteCollectionRequest.TimeZoneId,
                    StorageMaximumLevel = _siteCollectionRequest.StorageMaximumLevel,
                    StorageWarningLevel = _siteCollectionRequest.StorageMaximumLevel,
                    UserCodeMaximumLevel = 0,
                    UserCodeWarningLevel = 0
                };

                SpoOperation op = tenant.CreateSite(newsite);
                _ctx.Load(tenant);
                _ctx.Load(op, i => i.IsComplete);
                _ctx.ExecuteQuery();

                var step = 0;
                while (!op.IsComplete)
                {
                    step = step + 1;
                    Updatehelper.UpdateProgressView($"{step} Creating site collection", _actionRequest);
                    Thread.Sleep(10000);
                    op.RefreshLoad();
                    _ctx.ExecuteQuery();
                }
            }
            var site = tenant.GetSiteByUrl(webUrl);
                var web = site.RootWeb;
                web.Description = _actionRequest.Description;
                web.Update();
                _ctx.Load(web);
            _ctx.ExecuteQuery();

            return web.Url;
        }
开发者ID:sogeti,项目名称:Site-provisioning,代码行数:52,代码来源:SiteCollectionManager.cs

示例9: GetSiteGuidByUrlTenant

        /// <summary>
        /// Gets the ID of site collection with specified URL
        /// </summary>
        /// <param name="web">Tenant admin web</param>
        /// <param name="siteUrl">A URL that specifies a site collection to get ID.</param>
        /// <returns>The Guid of a site collection</returns>
        public static Guid GetSiteGuidByUrlTenant(this Web web, Uri siteUrl)
        {
            Guid siteGuid = Guid.Empty;

            Site site = null;
            Tenant tenant = new Tenant(web.Context);
            site = tenant.GetSiteByUrl(siteUrl.OriginalString);
            web.Context.Load(site);
            web.Context.ExecuteQuery();
            siteGuid = site.Id;

            return siteGuid;
        }
开发者ID:BNATENSTEDT,项目名称:PnP,代码行数:19,代码来源:SiteExtensions.cs

示例10: CheckIfSiteExistsInTenant

        /// <summary>
        /// Returns if a site collection is in a particular status. If the url contains a sub site then returns true is the sub site exists, false if not. 
        /// Status is irrelevant for sub sites
        /// </summary>
        /// <param name="web">Tenant admin web</param>
        /// <param name="siteUrl">Url to the site collection</param>
        /// <param name="status">Status to check (Active, Creating, Recycled)</param>
        /// <returns>True if in status, false if not in status</returns>
        public static bool CheckIfSiteExistsInTenant(this Web web, string siteUrl, string status)
        {
            bool ret = false;
            //Get the site name
            var url = new Uri(siteUrl);
            var UrlDomain = string.Format("{0}://{1}", url.Scheme, url.Host);
            int idx = url.PathAndQuery.Substring(1).IndexOf("/") + 2;
            var UrlPath = url.PathAndQuery.Substring(0, idx);
            var Name = url.PathAndQuery.Substring(idx);
            var index = Name.IndexOf('/');
            Tenant tenant = new Tenant(web.Context);

            //Judge whether this site collection is existing or not
            if (index == -1)
            {
                var properties = tenant.GetSitePropertiesByUrl(siteUrl, false);
                web.Context.Load(properties);
                web.Context.ExecuteQuery();
                ret = properties.Status.Equals(status, StringComparison.OrdinalIgnoreCase);
            }
            //Judge whether this sub web site is existing or not
            else
            {
                var site = tenant.GetSiteByUrl(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}{1}{2}", UrlDomain, UrlPath, Name.Split("/".ToCharArray())[0]));
                var subweb = site.OpenWeb(Name.Substring(index + 1));
                web.Context.Load(subweb, w => w.Title);
                web.Context.ExecuteQuery();
                ret = true;
            }
            return ret;
        }
开发者ID:BNATENSTEDT,项目名称:PnP,代码行数:39,代码来源:SiteExtensions.cs

示例11: LoadSiteStatus

 /// <summary>
 /// Load the latest site collection status from SharePoint
 /// </summary>
 /// <param name="e">Timer job event arguments</param>
 /// <param name="tenant">The tenant object</param>
 /// <param name="site">The site object</param>
 /// <param name="properties">The site properties object</param>
 private void LoadSiteStatus(TimerJobRunEventArgs e, out Tenant tenant, out Site site, out SiteProperties properties)
 {
     var tenantClientContext = e.TenantClientContext;
     Log.Info(base.Name, TimerJobsResources.SynchJob_GetSiteStatus, e.Url);
     tenant = new Tenant(tenantClientContext);
     site = tenant.GetSiteByUrl(e.Url);
     properties = tenant.GetSitePropertiesByUrl(e.Url, includeDetail: false);
     tenantClientContext.Load(tenant,
         t => t.SharingCapability);
     tenantClientContext.Load(site,
         s => s.RootWeb.Title,
         s => s.RootWeb.Description,
         s => s.RootWeb.Language,
         s => s.RootWeb.Created,
         s => s.Id);
     tenantClientContext.Load(properties,
         s => s.StorageMaximumLevel,
         s => s.StorageWarningLevel,
         s => s.UserCodeMaximumLevel,
         s => s.UserCodeWarningLevel,
         s => s.TimeZoneId,
         s => s.SharingCapability);
     tenantClientContext.ExecuteQueryRetry();
 }
开发者ID:Calisto1980,项目名称:PnP,代码行数:31,代码来源:SynchronizationJob.cs

示例12: Preprocess

        /// <summary>
        /// Update HasBroadAccess to 1 for both of the site collection and the current web record if any large security group permission assignment was found on the current web
        /// </summary>
        /// <param name="dbSiteRecord">The site collection record</param>
        /// <param name="dbWebRecord">The current web record</param>
        /// <param name="e">The timer job run event arguments</param>
        public override void Preprocess(SiteInformation dbSiteRecord, WebInformation dbWebRecord, TimerJobRunEventArgs e)
        {
            var tenant = new Tenant(e.TenantClientContext);
            var site = tenant.GetSiteByUrl(e.Url);
            var web = e.Url == dbWebRecord.SiteUrl
                ? site.RootWeb
                : site.OpenWeb(e.Url.Substring(dbWebRecord.Name.IndexOf('/') + 1));
            // load additional properties could be used to optimize the permission checking process
            e.TenantClientContext.Load(web,
                w => w.HasUniqueRoleAssignments,
                w => w.Url,
                w => w.ServerRelativeUrl,
                w => w.ParentWeb.ServerRelativeUrl);

            var assignments = new List<PermissionAssignment>();
            var entries = from groupLoginName in BroadAccessGroups.Keys
                select new PermissionAssignment
                {
                    Url = e.Url,
                    Group = groupLoginName,
                    Permission = web.GetUserEffectivePermissions(groupLoginName)
                };
            assignments.AddRange(entries);
            e.TenantClientContext.ExecuteQuery();

            var incompliantAssignments = assignments.Where(
                p => p.Permission.Value != null && (
                    p.Permission.Value.Has(PermissionKind.ViewPages) ||
                    p.Permission.Value.Has(PermissionKind.ViewListItems)));

            dbWebRecord.HasBroadAccess = incompliantAssignments.Any();
            if (dbWebRecord.HasBroadAccess)
            {
                dbWebRecord.BroadAccessGroups = string.Join(";",
                    (from a in incompliantAssignments select a.Group).ToArray());
                dbSiteRecord.HasBroadAccess = true;
            }
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:44,代码来源:HbiBroadAccessPolicy.cs

示例13: GetSiteCollectionContext

        public static ClientContext GetSiteCollectionContext(ClientContext clientContext, string url)
        {
            var tenant = new Tenant(clientContext);
            var site = tenant.GetSiteByUrl(url);
            clientContext.Load(site);
            clientContext.ExecuteQuery();

            return site.Context as ClientContext;
        }
开发者ID:rajendra1809,项目名称:Property-Inspection-Code-Sample,代码行数:9,代码来源:csomUtil.cs

示例14: CreateSiteCollection

        public override void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
 
            UsingContext(ctx =>
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();
                    bool timeout_detected = false;

                    Tenant _tenant = new Tenant(ctx);
                    var _newsite = new SiteCreationProperties();
                    _newsite.Title = siteRequest.Title;
                    _newsite.Url = siteRequest.Url;
                    _newsite.Owner = siteRequest.SiteOwner.Name;
                    _newsite.Template = template.RootTemplate;
                    _newsite.Lcid = siteRequest.Lcid;
                    _newsite.TimeZoneId = siteRequest.TimeZoneId;
                    _newsite.StorageMaximumLevel = template.StorageMaximumLevel;
                    _newsite.StorageWarningLevel = template.StorageWarningLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeMaximumLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeWarningLevel;

                    SpoOperation op = _tenant.CreateSite(_newsite);
                    ctx.Load(_tenant);
                    ctx.Load(op, i => i.IsComplete);

                    try
                    {
                        ctx.ExecuteQuery();
                        while (!op.IsComplete)
                        {
                            //wait 30seconds and try again
                            System.Threading.Thread.Sleep(30000);
                            op.RefreshLoad();
                            ctx.ExecuteQuery();
                            // we need this one in Azure Web jobs (it pings the service so it knows it's still alive)
                            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
                               "Waiting for Site Collection to be created....");
                        }
                    }
                    catch (WebException we)
                    {
                        if (we.Status != WebExceptionStatus.Timeout)
                        {
                            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
                              "Creation WebException (" + we.ToString() + ")");
                            throw;
                        }
                    }
                    Site _site = null;

                    // NOTE: this is experimental due to current issues with the site collection creation
                    while (_site == null)
                    {
                        try {
                            _site = _tenant.GetSiteByUrl(siteRequest.Url);
                        }
                        catch (Exception ex)
                        {
                            _site = null;
                            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
                               "Waiting for Site Collection to be created (" + ex.ToString() + ")");
                            System.Threading.Thread.Sleep(30000);
                        }
                    }
                    var _web = _site.RootWeb;
                    _web.Description = siteRequest.Description;
                    _web.Update();
                    ctx.Load(_web);
                    ctx.ExecuteQuery();

                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.CreateSiteCollection", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
                }
            
                catch (Exception ex)
                {
                    Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
                        PCResources.SiteCreation_Creation_Failure, 
                        siteRequest.Url, ex.Message, ex);
                    throw;
                }
               Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
            }, 25000);
        }
开发者ID:tandis,项目名称:PnP,代码行数:87,代码来源:Office365SiteProvisioningService.cs

示例15: CreateSiteCollection

        private void CreateSiteCollection(SiteCollectionProvisioningJob job)
        {
            Console.WriteLine("Creating Site Collection \"{0}\".", job.RelativeUrl);

            // Define the full Site Collection URL
            String siteUrl = String.Format("{0}{1}",
                PnPPartnerPackSettings.InfrastructureSiteUrl.Substring(0, PnPPartnerPackSettings.InfrastructureSiteUrl.IndexOf("sharepoint.com/") + 14),
                job.RelativeUrl);

            // Load the template from the source Templates Provider
            if (!String.IsNullOrEmpty(job.TemplatesProviderTypeName))
            {
                ProvisioningTemplate template = null;

                var templatesProvider = PnPPartnerPackSettings.TemplatesProviders[job.TemplatesProviderTypeName];
                if (templatesProvider != null)
                {
                    template = templatesProvider.GetProvisioningTemplate(job.ProvisioningTemplateUrl);
                }

                if (template != null)
                {
                    using (var adminContext = PnPPartnerPackContextProvider.GetAppOnlyTenantLevelClientContext())
                    {
                        adminContext.RequestTimeout = Timeout.Infinite;

                        // Configure the Site Collection properties
                        SiteEntity newSite = new SiteEntity();
                        newSite.Description = job.Description;
                        newSite.Lcid = (uint)job.Language;
                        newSite.Title = job.SiteTitle;
                        newSite.Url = siteUrl;
                        newSite.SiteOwnerLogin = job.PrimarySiteCollectionAdmin;
                        newSite.StorageMaximumLevel = job.StorageMaximumLevel;
                        newSite.StorageWarningLevel = job.StorageWarningLevel;

                        // Use the BaseSiteTemplate of the template, if any, otherwise
                        // fallback to the pre-configured site template (i.e. STS#0)
                        newSite.Template = !String.IsNullOrEmpty(template.BaseSiteTemplate) ?
                            template.BaseSiteTemplate :
                            PnPPartnerPackSettings.DefaultSiteTemplate;

                        newSite.TimeZoneId = job.TimeZone;
                        newSite.UserCodeMaximumLevel = job.UserCodeMaximumLevel;
                        newSite.UserCodeWarningLevel = job.UserCodeWarningLevel;

                        // Create the Site Collection and wait for its creation (we're asynchronous)
                        var tenant = new Tenant(adminContext);
                        tenant.CreateSiteCollection(newSite, true, true); // TODO: Do we want to empty Recycle Bin?

                        Site site = tenant.GetSiteByUrl(siteUrl);
                        Web web = site.RootWeb;

                        adminContext.Load(site, s => s.Url);
                        adminContext.Load(web, w => w.Url);
                        adminContext.ExecuteQueryRetry();

                        // Enable Secondary Site Collection Administrator
                        if (!String.IsNullOrEmpty(job.SecondarySiteCollectionAdmin))
                        {
                            Microsoft.SharePoint.Client.User secondaryOwner = web.EnsureUser(job.SecondarySiteCollectionAdmin);
                            secondaryOwner.IsSiteAdmin = true;
                            secondaryOwner.Update();

                            web.SiteUsers.AddUser(secondaryOwner);
                            adminContext.ExecuteQueryRetry();
                        }

                        Console.WriteLine("Site \"{0}\" created.", site.Url);

                        // Check if external sharing has to be enabled
                        if (job.ExternalSharingEnabled)
                        {
                            EnableExternalSharing(tenant, site);

                            // Enable External Sharing
                            Console.WriteLine("Enabled External Sharing for site \"{0}\".",
                                site.Url);
                        }
                    }

                    // Move to the context of the created Site Collection
                    using (ClientContext clientContext = PnPPartnerPackContextProvider.GetAppOnlyClientContext(siteUrl))
                    {
                        clientContext.RequestTimeout = Timeout.Infinite;

                        Site site = clientContext.Site;
                        Web web = site.RootWeb;

                        clientContext.Load(site, s => s.Url);
                        clientContext.Load(web, w => w.Url);
                        clientContext.ExecuteQueryRetry();

                        // Check if we need to enable PnP Partner Pack overrides
                        if (job.PartnerPackExtensionsEnabled)
                        {
                            // Enable Responsive Design
                            PnPPartnerPackUtilities.EnablePartnerPackOnSite(site.Url);

                            Console.WriteLine("Enabled PnP Partner Pack Overrides on site \"{0}\".",
//.........这里部分代码省略.........
开发者ID:OfficeDev,项目名称:PnP-Partner-Pack,代码行数:101,代码来源:SiteCollectionProvisioningJobHandler.cs


注:本文中的Tenant.GetSiteByUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。