/// <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(SiteRequestInformation 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); } }); }
/// <summary> /// TODO /// </summary> /// <param name="siteRequest"></param> /// <param name="template"></param> public void CreateSiteCollection(SiteRequestInformation siteRequest, Template template) { _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant(); _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl; _siteprovisioningService.CreateSiteCollection(siteRequest, template); if (siteRequest.EnableExternalSharing) { _siteprovisioningService.SetExternalSharing(siteRequest); } }
/// <summary> /// TODO /// </summary> /// <param name="siteRequest"></param> /// <param name="template"></param> public void CreateSiteCollection(SiteRequestInformation siteRequest, Template template) { _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant(); _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl; _siteprovisioningService.CreateSiteCollection(siteRequest, template); if(siteRequest.EnableExternalSharing) { _siteprovisioningService.SetExternalSharing(siteRequest); } }
public SiteProvisioningManager(SiteRequestInformation siteRequest, Template template) { if (template.SharePointOnPremises) { _siteprovisioningService = new OnPremSiteProvisioningService(); } else { _siteprovisioningService = new Office365SiteProvisioningService(); } }
public override void CreateSiteCollection(SiteRequestInformation 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_Successfull, siteRequest.Url); this.HandleDefaultGroups(siteRequest); }
public override void CreateSiteCollection(SiteRequestInformation siteRequest, Template template) { Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Starting, siteRequest.Url); UsingContext(ctx => { try { 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(); } 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_Successfull, siteRequest.Url); }); }
/// <summary> /// TODO /// </summary> /// <param name="web"></param> /// <exception cref="ProvisioningTemplateException">An Exception that occurs when applying the template to a site</exception> public void ApplyProvisioningTemplates(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest) { try { this._siteprovisioningService.Authentication = new AppOnlyAuthenticationSite(); this._siteprovisioningService.Authentication.SiteUrl = siteRequest.Url; this._siteprovisioningService.SetSitePolicy(siteRequest.SitePolicy); var _web = _siteprovisioningService.GetWebByUrl(siteRequest.Url); provisioningTemplate.Connector = this.GetProvisioningConnector(); provisioningTemplate = new TemplateConversion().HandleProvisioningTemplate(provisioningTemplate, siteRequest); _web.ApplyProvisioningTemplate(provisioningTemplate); } catch(Exception _ex) { //TODO RESOURCE FILES var _message =string.Format("Error Occured when applying the template: {0}", _ex.Message); throw new ProvisioningTemplateException(_message, _ex); } }
public static SiteRequestInformation ToSiteRequestInformation(SiteRequest request) { var _owner = new SiteUser() { Name = request.PrimaryOwner }; List<SiteUser> _additionalAdmins = new List<SiteUser>(); foreach (var secondaryOwner in request.AdditionalAdministrators) { if(!string.IsNullOrEmpty(secondaryOwner)) { var _sharePointUser = new SiteUser(); _sharePointUser.Name = secondaryOwner; _additionalAdmins.Add(_sharePointUser); } } var _newRequest = new SiteRequestInformation(); _newRequest.Title = request.Title; _newRequest.Description = request.Description; _newRequest.Url = request.Url; _newRequest.TimeZoneId = request.TimeZoneID; _newRequest.Lcid = request.lcid; _newRequest.Template = request.Template; _newRequest.SitePolicy = request.SitePolicy; _newRequest.SiteOwner = _owner; _newRequest.AdditionalAdministrators = _additionalAdmins; _newRequest.SharePointOnPremises = request.SharePointOnPremises; _newRequest.BusinessCase = request.BusinessCase; _newRequest.EnableExternalSharing = request.EnableExternalSharing; if(request.Properties != null) { //Serialize Property Bag Entries _newRequest.PropertiesJSON = JsonConvert.SerializeObject(request.Properties); } return _newRequest; }
/// <summary> /// /// </summary> /// <param name="siteInfo"></param> public override void SetExternalSharing(SiteRequestInformation siteInfo) { UsingContext(ctx => { try { Tenant _tenant = new Tenant(ctx); SiteProperties _siteProps = _tenant.GetSitePropertiesByUrl(siteInfo.Url, false); ctx.Load(_tenant); ctx.Load(_siteProps); ctx.ExecuteQuery(); bool _shouldBeUpdated = false; var _tenantSharingCapability = _tenant.SharingCapability; var _siteSharingCapability = _siteProps.SharingCapability; var _targetSharingCapability = SharingCapabilities.Disabled; if (siteInfo.EnableExternalSharing && _tenantSharingCapability != SharingCapabilities.Disabled) { _targetSharingCapability = SharingCapabilities.ExternalUserSharingOnly; _shouldBeUpdated = true; } if (_siteSharingCapability != _targetSharingCapability && _shouldBeUpdated) { _siteProps.SharingCapability = _targetSharingCapability; _siteProps.Update(); ctx.ExecuteQuery(); Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Successfull, siteInfo.Url); } } catch (Exception _ex) { Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Exception, siteInfo.Url, _ex); } }); }
public SiteRequestInformation GetSiteRequestMock() { var _owner = new SiteUser() { Name = "*****@*****.**" }; //Add addtional Users List<SiteUser> _additionalAdmins = new List<SiteUser>(); SiteUser _admin1 = new SiteUser(); _admin1.Name = "*****@*****.**"; SiteUser _admin2 = new SiteUser(); // _admin2.Email = "*****@*****.**"; _admin2.Name = "*****@*****.**"; _additionalAdmins.Add(_admin1); _additionalAdmins.Add(_admin2); var _siteInfo = new SiteRequestInformation() { Title = "Test Title", Description = "Test Description", Template = "CT2", Url = "https://spsites.contoso.com/sites/B3", SitePolicy = "HBI", SiteOwner = _owner, AdditionalAdministrators = _additionalAdmins, EnableExternalSharing = true, SharePointOnPremises = true }; return _siteInfo; }
/// <summary> /// /// </summary> /// <param name="siteInfo"></param> public override void SetExternalSharing(SiteRequestInformation siteInfo) { UsingContext(ctx => { try { Tenant _tenant = new Tenant(ctx); SiteProperties _siteProps = _tenant.GetSitePropertiesByUrl(siteInfo.Url, false); ctx.Load(_tenant); ctx.Load(_siteProps); ctx.ExecuteQuery(); bool _shouldBeUpdated = false; var _tenantSharingCapability = _tenant.SharingCapability; var _siteSharingCapability = _siteProps.SharingCapability; var _targetSharingCapability = SharingCapabilities.Disabled; if(siteInfo.EnableExternalSharing && _tenantSharingCapability != SharingCapabilities.Disabled) { _targetSharingCapability = SharingCapabilities.ExternalUserSharingOnly; _shouldBeUpdated = true; } if (_siteSharingCapability != _targetSharingCapability && _shouldBeUpdated) { _siteProps.SharingCapability = _targetSharingCapability; _siteProps.Update(); ctx.ExecuteQuery(); Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Successfull, siteInfo.Url); } } catch(Exception _ex) { Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Exception, siteInfo.Url, _ex); } }); }
/// <summary> /// Sends a Notification that the Site was created /// </summary> /// <param name="info"></param> protected void SendSuccessEmail(SiteRequestInformation info) { //TODO CLEAN UP EMAILS try { StringBuilder _admins = new StringBuilder(); SuccessEmailMessage _message = new SuccessEmailMessage(); _message.SiteUrl = info.Url; _message.SiteOwner = info.SiteOwner.Name; _message.Subject = "Notification: Your new SharePoint site is ready"; _message.To.Add(info.SiteOwner.Name); foreach (var admin in info.AdditionalAdministrators) { _message.Cc.Add(admin.Name); _admins.Append(admin.Name); _admins.Append(" "); } _message.SiteAdmin = _admins.ToString(); EmailHelper.SendNewSiteSuccessEmail(_message); } catch(Exception ex) { Log.Error("Provisioning.Job.SiteProvisioningJob.SendSuccessEmail", "There was an error sending email. The Error Message: {0}, Exception: {1}", ex.Message, ex); } }
/// <summary> /// Sends an Failure Email Notification /// </summary> /// <param name="info"></param> /// <param name="errorMessage"></param> protected void SendFailureEmail(SiteRequestInformation info, string errorMessage) { try { StringBuilder _admins = new StringBuilder(); FailureEmailMessage _message = new FailureEmailMessage(); _message.SiteUrl = info.Url; _message.SiteOwner = info.SiteOwner.Name; _message.Subject = "Alert: Your new SharePoint site request had a problem."; _message.ErrorMessage = errorMessage; _message.To.Add(info.SiteOwner.Name); if (!string.IsNullOrEmpty(this._settings.SupportEmailNotification)) { string[] supportAdmins = this._settings.SupportEmailNotification.Split(';'); foreach (var supportAdmin in supportAdmins) { _message.To.Add(supportAdmin); } } foreach (var admin in info.AdditionalAdministrators) { _message.Cc.Add(admin.Name); _admins.Append(admin.Name); _admins.Append(" "); } _message.SiteAdmin = _admins.ToString(); EmailHelper.SendFailEmail(_message); } catch(Exception ex) { Log.Error("Provisioning.Job.SiteProvisioningJob.SendSuccessEmail", "There was an error sending email. The Error Message: {0}, Exception: {1}", ex.Message, ex); } }
/// <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(SiteRequestInformation 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); } }); }
/// <summary> /// Sets External Sharing /// This is not supported in on-premises builds. /// </summary> /// <param name="url"></param> public override void SetExternalSharing(SiteRequestInformation siteInfo) { Log.Warning("Provisioning.Common.OnPremSiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_NotSupported, siteInfo.Url); return; }
public override void CreateSiteCollection(SiteRequestInformation 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_Successfull, siteRequest.Url); this.HandleDefaultGroups(siteRequest); }
public abstract void CreateSiteCollection(SiteRequestInformation siteRequest, Template template);
public abstract void SetExternalSharing(SiteRequestInformation siteInfo);
/// <summary> /// TODO /// </summary> /// <param name="web"></param> /// <exception cref="ProvisioningTemplateException">An Exception that occurs when applying the template to a site</exception> public void ApplyProvisioningTemplates(ProvisioningTemplate provisioningTemplate, SiteRequestInformation siteRequest) { try { this._siteprovisioningService.Authentication = new AppOnlyAuthenticationSite(); this._siteprovisioningService.Authentication.SiteUrl = siteRequest.Url; this._siteprovisioningService.SetSitePolicy(siteRequest.SitePolicy); var _web = _siteprovisioningService.GetWebByUrl(siteRequest.Url); provisioningTemplate.Connector = this.GetProvisioningConnector(); provisioningTemplate = new TemplateConversion().HandleProvisioningTemplate(provisioningTemplate, siteRequest); _web.ApplyProvisioningTemplate(provisioningTemplate); } catch (Exception _ex) { //TODO RESOURCE FILES var _message = string.Format("Error Occured when applying the template: {0}", _ex.Message); throw new ProvisioningTemplateException(_message, _ex); } }