Beispiel #1
0
        private void OperationWithRetry(ClientContext ctx, SpoOperation operation, SiteInformation siteRequest)
        {
            int currentRetry = 0;

            for (;;)
            {
                try
                {
                    System.Threading.Thread.Sleep(30000);
                    ctx.Load(operation);
                    ctx.ExecuteQuery();
                    Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", "Waiting for Site Collection {0} to be created", siteRequest.Url);
                    if (operation.IsComplete)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    currentRetry++;

                    if (currentRetry > this._retryCount || !IsTransientException(ex))
                    {
                        throw;
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Member to create a site collection
        /// </summary>
        /// <param name="siteRequest">The SiteRequest</param>
        /// <param name="template">The Template</param>
        public void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
            _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;

            ReflectionManager rm = new ReflectionManager();

            var siteUrlProvider = rm.GetSiteUrlProvider("SiteUrlProvider");
            if(siteUrlProvider != null)
            {
                var newUrl = siteUrlProvider.GenerateSiteUrl(siteRequest, template);
                if (!String.IsNullOrEmpty(newUrl))
                {
                    Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site {0} was renamed to {1}", siteRequest.Url, newUrl);

                    SiteRequestFactory.GetInstance().GetSiteRequestManager().UpdateRequestUrl(siteRequest.Url, newUrl);
                    siteRequest.Url = newUrl;

                }
                
            }
            _siteprovisioningService.CreateSiteCollection(siteRequest, template);
            if(siteRequest.EnableExternalSharing)
            {
                _siteprovisioningService.SetExternalSharing(siteRequest);
            }
           
        }
        /// <summary>
        /// Member to create a site collection
        /// </summary>
        /// <param name="siteRequest">The SiteRequest</param>
        /// <param name="template">The Template</param>
        public void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
            _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;

            ReflectionManager rm = new ReflectionManager();

            var siteUrlProvider = rm.GetSiteUrlProvider("SiteUrlProvider");

            if (siteUrlProvider != null)
            {
                var newUrl = siteUrlProvider.GenerateSiteUrl(siteRequest, template);
                if (!String.IsNullOrEmpty(newUrl))
                {
                    Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site {0} was renamed to {1}", siteRequest.Url, newUrl);

                    SiteRequestFactory.GetInstance().GetSiteRequestManager().UpdateRequestUrl(siteRequest.Url, newUrl);
                    siteRequest.Url = newUrl;
                }
            }
            _siteprovisioningService.CreateSiteCollection(siteRequest, template);
            if (siteRequest.EnableExternalSharing)
            {
                _siteprovisioningService.SetExternalSharing(siteRequest);
            }
        }
Beispiel #4
0
        public override Web CreateSubSite(SiteInformation siteRequest, Template template)
        {
            Web    newWeb;
            int    pos        = siteRequest.Url.LastIndexOf("/");
            string parentUrl  = siteRequest.Url.Substring(0, pos);
            string subSiteUrl = siteRequest.Url.Substring(pos + 1, siteRequest.Url.Length);

            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
            Uri siteUri       = new Uri(siteRequest.Url);
            Uri subSiteParent = new Uri(parentUrl);

            string realm       = TokenHelper.GetRealmFromTargetUrl(subSiteParent);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, subSiteParent.Authority, realm).AccessToken;

            using (var ctx = TokenHelper.GetClientContextWithAccessToken(parentUrl, accessToken))
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();

                    try
                    {
                        // Get a reference to the parent Web
                        Web parentWeb = ctx.Web;

                        // Create the new sub site as a new child Web
                        WebCreationInformation webinfo = new WebCreationInformation();
                        webinfo.Description = siteRequest.Description;
                        webinfo.Language    = (int)siteRequest.Lcid;
                        webinfo.Title       = siteRequest.Title;
                        webinfo.Url         = subSiteUrl;
                        webinfo.UseSamePermissionsAsParentSite = true;
                        webinfo.WebTemplate = template.RootTemplate;

                        newWeb = parentWeb.Webs.Add(webinfo);
                        ctx.ExecuteQueryRetry();
                    }
                    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.CreateSubSite", _message);
                        throw;
                    }

                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.CreateSubSite", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
                }

                catch (Exception ex)
                {
                    Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite",
                              PCResources.SiteCreation_Creation_Failure,
                              siteRequest.Url, ex.Message, ex);
                    throw;
                }
                Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
            };

            return(newWeb);
        }
        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);
            });
        }
        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);
            });
        }
        /// <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);
                }
            });

        }
        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 =>
                {
                    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;
                    _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();
                    }

                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "OnPremSiteProvisioningService.CreateSiteCollection", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
                }, 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);
        }
        /// <summary>
        /// Member to create a site collection
        /// </summary>
        /// <param name="siteRequest">The SiteRequest</param>
        /// <param name="template">The Template</param>
        public void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
            _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;

            _siteprovisioningService.CreateSiteCollection(siteRequest, template);
            if (siteRequest.EnableExternalSharing)
            {
                _siteprovisioningService.SetExternalSharing(siteRequest);
            }
        }
Beispiel #10
0
 public SiteProvisioningManager(SiteInformation siteRequest, Template template)
 {
     if (template.SharePointOnPremises)
     {
         _siteprovisioningService = new OnPremSiteProvisioningService();
     }
     else
     {
         _siteprovisioningService = new Office365SiteProvisioningService();
     }
 }
Beispiel #11
0
 public SiteProvisioningManager(SiteInformation siteRequest, Template template)
 {
     if (template.SharePointOnPremises)
     {
         _siteprovisioningService = new OnPremSiteProvisioningService();
     }
     else
     {
         _siteprovisioningService = new Office365SiteProvisioningService();
     }
 }
Beispiel #12
0
    /// <summary>
    /// Member to create a site collection
    /// </summary>
    /// <param name="siteRequest">The SiteRequest</param>
    /// <param name="template">The Template</param>
    public void CreateSiteCollection(SiteInformation siteRequest, Template template)
    {
        _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
        _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;
 
        _siteprovisioningService.CreateSiteCollection(siteRequest, template);
        if(siteRequest.EnableExternalSharing)
        {
            _siteprovisioningService.SetExternalSharing(siteRequest);
        }
       
    }
Beispiel #13
0
        /// <summary>
        /// Used to set External Sharing
        /// </summary>
        /// <param name="siteInfo"></param>
        public override void SetExternalSharing(SiteInformation siteInfo)
        {
            UsingContext(ctx =>
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();

                    Tenant _tenant = new Tenant(ctx);

                    //_tenant.SetSiteProperties(siteInfo.Url, null, null, SharingCapabilities.ExternalUserSharingOnly, null, null, null, null);
                    SiteProperties _siteProps = _tenant.GetSitePropertiesByUrl(siteInfo.Url, false);
                    ctx.Load(_tenant);
                    ctx.Load(_siteProps);
                    ctx.ExecuteQuery();

                    var _tenantSharingCapability = _tenant.SharingCapability;
                    var _siteSharingCapability   = _siteProps.SharingCapability;
                    var _targetSharingCapability = SharingCapabilities.Disabled;

                    if (!siteInfo.EnableExternalSharing && _tenantSharingCapability != SharingCapabilities.Disabled)
                    {
                        _targetSharingCapability = SharingCapabilities.Disabled;

                        _siteProps.SharingCapability = _targetSharingCapability;
                        _siteProps.Update();
                        ctx.ExecuteQuery();
                        Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Successful, siteInfo.Url);
                    }
                    if (siteInfo.EnableExternalSharing && _tenantSharingCapability != SharingCapabilities.Disabled)
                    {
                        _targetSharingCapability = SharingCapabilities.ExternalUserSharingOnly;

                        _siteProps.SharingCapability = _targetSharingCapability;
                        _siteProps.Update();
                        ctx.ExecuteQuery();
                        Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Successful, siteInfo.Url);
                    }

                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.SetExternalSharing", _timespan.Elapsed, "SiteUrl={0}", siteInfo.Url);
                }
                catch (ServerException _ex)
                {
                    Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Exception, siteInfo.Url, _ex);
                }
                catch (Exception _ex)
                {
                    Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Exception, siteInfo.Url, _ex);
                }
            });
        }
Beispiel #14
0
 /// <summary>
 /// Member to apply the Provisioning Tempalte to a site
 /// </summary>
 /// <param name="web"></param>
 /// <exception cref="ProvisioningTemplateException">An Exception that occurs when applying the template to a site</exception>
 public void ApplyProvisioningTemplate(ProvisioningTemplate provisioningTemplate, SiteInformation siteRequest)
 {
     try
     {
         this._siteprovisioningService.Authentication = new AppOnlyAuthenticationSite();
         this._siteprovisioningService.Authentication.SiteUrl = siteRequest.Url;
         var _web = _siteprovisioningService.GetWebByUrl(siteRequest.Url);
         provisioningTemplate.Connector = this.GetProvisioningConnector();
         provisioningTemplate = new TemplateConversion().HandleProvisioningTemplate(provisioningTemplate, siteRequest);
         _web.ApplyProvisioningTemplate(provisioningTemplate);
     }
     catch(Exception _ex)
     {
         var _message =string.Format("Error Occured when applying the template: {0}", _ex.Message);
         throw new ProvisioningTemplateException(_message, _ex);
     }
 }
Beispiel #15
0
        /// <summary>
        /// Member to create a sub site
        /// </summary>
        /// <param name="siteRequest">The SiteRequest</param>
        /// <param name="template">The Template</param>
        public Web CreateSubSite(SiteInformation siteRequest, Template template)
        {
            Web newWeb = null;

            _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
            _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;

            ReflectionManager rm = new ReflectionManager();

            var siteUrlProvider = rm.GetSiteUrlProvider("SiteUrlProvider");

            if (siteUrlProvider != null)
            {
                var newUrl = siteUrlProvider.GenerateSiteUrl(siteRequest, template);
                if (!String.IsNullOrEmpty(newUrl))
                {
                    Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site {0} was renamed to {1}", siteRequest.Url, newUrl);

                    SiteRequestFactory.GetInstance().GetSiteRequestManager().UpdateRequestUrl(siteRequest.Url, newUrl);
                    siteRequest.Url = newUrl;
                }
            }

            // Check to see if the site already exists before attempting to create it
            bool siteExists = _siteprovisioningService.SubSiteExists(siteRequest.Url.ToString());

            if (!siteExists)
            {
                newWeb = _siteprovisioningService.CreateSubSite(siteRequest, template);
            }
            else
            {
                Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
                Uri    siteUri     = new Uri(siteRequest.Url);
                string realm       = TokenHelper.GetRealmFromTargetUrl(siteUri);
                string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

                using (var ctx = TokenHelper.GetClientContextWithAccessToken(siteRequest.Url, accessToken))
                {
                    newWeb = ctx.Web;
                }
            }

            return(newWeb);
        }
Beispiel #16
0
        public void UpdateSiteDescription(SiteInformation siteRequest)
        {
            Uri    siteUri     = new Uri(siteRequest.Url);
            string realm       = TokenHelper.GetRealmFromTargetUrl(siteUri);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteRequest.Url, accessToken))
            {
                // Update Site Description
                clientContext.Load(clientContext.Web, w => w.Description);
                clientContext.ExecuteQuery();

                clientContext.Web.Description = siteRequest.Description;
                clientContext.Web.Update();
                clientContext.Load(clientContext.Web, w => w.Description);
                clientContext.ExecuteQuery();
            }
        }
Beispiel #17
0
        public static SiteInformation 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 SiteInformation();
            _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;
            _newRequest.IsConfidential = request.IsConfidential;


            if(request.Properties != null)
            {
                //Serialize Property Bag Entries
                _newRequest.SiteMetadataJson = JsonConvert.SerializeObject(request.Properties);
            }
            return _newRequest;
        }
        /// <summary>
        /// Member to create a site collection
        /// </summary>
        /// <param name="siteRequest">The SiteRequest</param>
        /// <param name="template">The Template</param>
        public void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
            _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;

            ReflectionManager rm = new ReflectionManager();

            var siteUrlProvider = rm.GetSiteUrlProvider("SiteUrlProvider");
            if(siteUrlProvider != null)
            {
                var newUrl = siteUrlProvider.GenerateSiteUrl(siteRequest, template);
                if (!String.IsNullOrEmpty(newUrl))
                {
                    Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site {0} was renamed to {1}", siteRequest.Url, newUrl);

                    SiteRequestFactory.GetInstance().GetSiteRequestManager().UpdateRequestUrl(siteRequest.Url, newUrl);
                    siteRequest.Url = newUrl;

                }
                
            }



           // Check to see if the site already exists before attempting to create it
            bool siteExists = _siteprovisioningService.SiteExists(siteRequest.Url.ToString());

            if (!siteExists)
            {
                _siteprovisioningService.CreateSiteCollection(siteRequest, template);
                if (siteRequest.EnableExternalSharing)
                {
                    _siteprovisioningService.SetExternalSharing(siteRequest);
                }
            }
            else
            {                
                Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site already exists. Moving on to next provisioning step");                
            }           
        }
Beispiel #19
0
        public void UpdateRequestAccessEmail(SiteInformation siteRequest)
        {
            Uri    siteUri     = new Uri(siteRequest.Url);
            string realm       = TokenHelper.GetRealmFromTargetUrl(siteUri);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteRequest.Url, accessToken))
            {
                // Push notifications feature activation
                // This needs to be here until another approach is found where it is not needed
                clientContext.Web.ActivateFeature(new Guid("41e1d4bfb1a247f7ab80d5d6cbba3092"));

                // Update Request Access Email
                clientContext.Load(clientContext.Web, w => w.RequestAccessEmail);
                clientContext.ExecuteQuery();

                clientContext.Web.RequestAccessEmail = siteRequest.SiteOwner.Name;
                clientContext.Web.Update();
                clientContext.Load(clientContext.Web, w => w.RequestAccessEmail);
                clientContext.ExecuteQuery();
            }
        }
Beispiel #20
0
        /// <summary>
        /// Member to create a site collection
        /// </summary>
        /// <param name="siteRequest">The SiteRequest</param>
        /// <param name="template">The Template</param>
        public void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
            _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;

            ReflectionManager rm = new ReflectionManager();

            var siteUrlProvider = rm.GetSiteUrlProvider("SiteUrlProvider");

            if (siteUrlProvider != null)
            {
                var newUrl = siteUrlProvider.GenerateSiteUrl(siteRequest, template);
                if (!String.IsNullOrEmpty(newUrl))
                {
                    Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site {0} was renamed to {1}", siteRequest.Url, newUrl);

                    SiteRequestFactory.GetInstance().GetSiteRequestManager().UpdateRequestUrl(siteRequest.Url, newUrl);
                    siteRequest.Url = newUrl;
                }
            }



            // Check to see if the site already exists before attempting to create it
            bool siteExists = _siteprovisioningService.SiteExists(siteRequest.Url.ToString());

            if (!siteExists)
            {
                _siteprovisioningService.CreateSiteCollection(siteRequest, template);
                if (siteRequest.EnableExternalSharing)
                {
                    _siteprovisioningService.SetExternalSharing(siteRequest);
                }
            }
            else
            {
                Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site already exists. Moving on to next provisioning step");
            }
        }
Beispiel #21
0
        /// <summary>
        /// Member to apply the Provisioning Tempalte to a site
        /// </summary>
        /// <param name="web"></param>
        /// <exception cref="ProvisioningTemplateException">An Exception that occurs when applying the template to a site</exception>
        public void ApplyProvisioningTemplate(ProvisioningTemplate provisioningTemplate, SiteInformation siteRequest, Template template)
        {
            try
            {
                this._siteprovisioningService.Authentication = new AppOnlyAuthenticationSite();
                this._siteprovisioningService.Authentication.SiteUrl = siteRequest.Url;
                var _web = _siteprovisioningService.GetWebByUrl(siteRequest.Url);
                provisioningTemplate.Connector = this.GetProvisioningConnector();                
                provisioningTemplate = new TemplateConversion().HandleProvisioningTemplate(provisioningTemplate, siteRequest, template);

                ProvisioningTemplateApplyingInformation _pta = new ProvisioningTemplateApplyingInformation();
                _pta.ProgressDelegate = (message, step, total) =>
                {
                    Log.Info("SiteProvisioningManager.ApplyProvisioningTemplate", "Applying Provisioning template - Step {0}/{1} : {2} ", step, total, message);
                }; 
                _web.ApplyProvisioningTemplate(provisioningTemplate);
            }
            catch(Exception _ex)
            {
                var _message =string.Format("Error Occured when applying the template: {0} to site: {1}", _ex.Message, siteRequest.Url);
                throw new ProvisioningTemplateException(_message, _ex);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="siteInfo"></param>
        public override void SetExternalSharing(SiteInformation 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_Successful, siteInfo.Url);
                    }
                }
                catch (Exception _ex)
                {
                    Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Exception, siteInfo.Url, _ex);
                }
            });
        }
 /// <summary>
 /// Sets External Sharing
 /// This is not supported in on-premises builds.
 /// </summary>
 /// <param name="url"></param>
 public override void SetExternalSharing(SiteInformation siteInfo)
 {
     Log.Warning("Provisioning.Common.OnPremSiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_NotSupported, siteInfo.Url);
     return;
 }
 public abstract void CreateSiteCollection(SiteInformation siteRequest, Template template);
        public void UpdateSiteDescription(SiteInformation siteRequest)
        {
            Uri siteUri = new Uri(siteRequest.Url);
            string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteRequest.Url, accessToken))
            {
                // Update Site Description                
                clientContext.Load(clientContext.Web, w => w.Description);
                clientContext.ExecuteQuery();

                clientContext.Web.Description = siteRequest.Description;
                clientContext.Web.Update();
                clientContext.Load(clientContext.Web, w => w.Description);
                clientContext.ExecuteQuery();

            }
        }
        public void UpdateRequestAccessEmail(SiteInformation siteRequest)
        {
            Uri siteUri = new Uri(siteRequest.Url);
            string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteRequest.Url, accessToken))
            {
                // Push notifications feature activation 
                // This needs to be here until another approach is found where it is not needed
                clientContext.Web.ActivateFeature(new Guid("41e1d4bfb1a247f7ab80d5d6cbba3092"));

                // Update Request Access Email                
                clientContext.Load(clientContext.Web, w => w.RequestAccessEmail);
                clientContext.ExecuteQuery();

                clientContext.Web.RequestAccessEmail = siteRequest.SiteOwner.Email;
                clientContext.Web.Update();
                clientContext.Load(clientContext.Web, w => w.RequestAccessEmail);
                clientContext.ExecuteQuery();
            }
        }
        /// <summary>
        /// Member to create a sub site
        /// </summary>
        /// <param name="siteRequest">The SiteRequest</param>
        /// <param name="template">The Template</param>
        public Web CreateSubSite(SiteInformation siteRequest, Template template)
        {
            Web newWeb = null;

            _siteprovisioningService.Authentication = new AppOnlyAuthenticationTenant();
            _siteprovisioningService.Authentication.TenantAdminUrl = template.TenantAdminUrl;

            ReflectionManager rm = new ReflectionManager();

            var siteUrlProvider = rm.GetSiteUrlProvider("SiteUrlProvider");
            if (siteUrlProvider != null)
            {
                var newUrl = siteUrlProvider.GenerateSiteUrl(siteRequest, template);
                if (!String.IsNullOrEmpty(newUrl))
                {
                    Log.Info("SiteProvisioningManager.CreateSiteCollection", "Site {0} was renamed to {1}", siteRequest.Url, newUrl);

                    SiteRequestFactory.GetInstance().GetSiteRequestManager().UpdateRequestUrl(siteRequest.Url, newUrl);
                    siteRequest.Url = newUrl;

                }
            }

            // Check to see if the site already exists before attempting to create it
            bool siteExists = _siteprovisioningService.SubSiteExists(siteRequest.Url.ToString());

            if (!siteExists)
            {
                newWeb = _siteprovisioningService.CreateSubSite(siteRequest, template);
               
            }
            else
            {
                Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
                Uri siteUri = new Uri(siteRequest.Url);                
                string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
                string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

                using (var ctx = TokenHelper.GetClientContextWithAccessToken(siteRequest.Url, accessToken))
                {
                    newWeb = ctx.Web;
                }
            }

            return newWeb;
        }
 public abstract void SetExternalSharing(SiteInformation siteInfo);
Beispiel #29
0
        protected string CheckReservedNamespaces(SiteInformation siteRequest)
        {
            string returnValue = string.Empty;
            string siteUri = siteRequest.Url;
            //   string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
            //   string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            siteUri = siteUri.Replace("https://cocacola.sharepoint.com/teams", "https://teams.coca-cola.com/sites");
            siteUri = siteUri.Replace("https://cocacola.sharepoint.com/sites", "https://partner.coca-cola.com/sites");


            using (var ctx = new ClientContext("https://teams.coca-cola.com/sites/MTMigration"))
            {
                ctx.AuthenticationMode = ClientAuthenticationMode.Default;

                System.Net.NetworkCredential cred = new System.Net.NetworkCredential("na\\X30965", "Friday$123456789");
                ctx.Credentials = cred;
                List oList = ctx.Web.Lists.GetByTitle("SiteInventory");

                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = "<View><Query><Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>" + siteUri.Trim() + "</Value></Eq><Eq><FieldRef Name='MigrateSite' /><Value Type='Boolean'>1</Value></Eq></And></Where></Query><RowLimit>1</RowLimit></View>";

                ListItemCollection collListItem = oList.GetItems(camlQuery);
                ctx.Load(collListItem);
                ctx.Load(oList);
                ctx.ExecuteQuery();
                if (collListItem.Count > 0)
                {
                    returnValue = siteUri;
                }
            }
            return returnValue;
        }
        /// <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)
        {
            Log.Info("Provisioning.Common.OnPremSiteProvisioningService.HandleDefaultGroups", "Creating Groups for site {0} created", properties.Url);
            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 =>
            {
                Stopwatch _timespan = Stopwatch.StartNew();

                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);
                }

                _timespan.Stop();
                Log.TraceApi("SharePoint", "OnPremSiteProvisioningService.HandleDefaultGroups", _timespan.Elapsed, "SiteUrl={0}", properties.Url);
            });
        }
        /// <summary>
        /// Used to set External Sharing
        /// </summary>
        /// <param name="siteInfo"></param>
        public override void SetExternalSharing(SiteInformation siteInfo)
        {
            UsingContext(ctx =>
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();

                    Tenant _tenant = new Tenant(ctx);

                    //_tenant.SetSiteProperties(siteInfo.Url, null, null, SharingCapabilities.ExternalUserSharingOnly, null, null, null, null);
                    SiteProperties _siteProps = _tenant.GetSitePropertiesByUrl(siteInfo.Url, false);
                    ctx.Load(_tenant);
                    ctx.Load(_siteProps);
                    ctx.ExecuteQuery();
                    
                    var _tenantSharingCapability = _tenant.SharingCapability;
                    var _siteSharingCapability = _siteProps.SharingCapability;
                    var _targetSharingCapability = SharingCapabilities.Disabled;

                    if(!siteInfo.EnableExternalSharing && _tenantSharingCapability != SharingCapabilities.Disabled)
                    {
                        _targetSharingCapability = SharingCapabilities.Disabled;                        

                        _siteProps.SharingCapability = _targetSharingCapability;
                        _siteProps.Update();
                        ctx.ExecuteQuery();
                        Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Successful, siteInfo.Url);
                    }
                    if (siteInfo.EnableExternalSharing && _tenantSharingCapability != SharingCapabilities.Disabled)
                    {
                        _targetSharingCapability = SharingCapabilities.ExternalUserSharingOnly;                        

                        _siteProps.SharingCapability = _targetSharingCapability;
                        _siteProps.Update();
                        ctx.ExecuteQuery();
                        Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Successful, siteInfo.Url);
                    }

                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.SetExternalSharing", _timespan.Elapsed, "SiteUrl={0}", siteInfo.Url);
       
                   
                }
                catch(ServerException _ex)
                {
                    Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Exception, siteInfo.Url, _ex);
     
                }
                catch(Exception _ex)
                {
                    Log.Info("Provisioning.Common.Office365SiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_Exception, siteInfo.Url, _ex);
                }
             
            });
        }
        public override Web CreateSubSite(SiteInformation siteRequest, Template template)
        {
            Web newWeb;
            int pos = siteRequest.Url.LastIndexOf("/");
            string parentUrl = siteRequest.Url.Substring(0, pos);
            string subSiteUrl = siteRequest.Url.Substring(pos + 1, siteRequest.Url.Length);

            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
            Uri siteUri = new Uri(siteRequest.Url);
            Uri subSiteParent = new Uri(parentUrl);

            string realm = TokenHelper.GetRealmFromTargetUrl(subSiteParent);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, subSiteParent.Authority, realm).AccessToken;

            using (var ctx = TokenHelper.GetClientContextWithAccessToken(parentUrl, accessToken))
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();                  

                    try
                    {
                        // Get a reference to the parent Web
                        Web parentWeb = ctx.Web;

                        // Create the new sub site as a new child Web
                        WebCreationInformation webinfo = new WebCreationInformation();
                        webinfo.Description = siteRequest.Description;
                        webinfo.Language = (int)siteRequest.Lcid;
                        webinfo.Title = siteRequest.Title;
                        webinfo.Url = subSiteUrl;
                        webinfo.UseSamePermissionsAsParentSite = true;
                        webinfo.WebTemplate = template.RootTemplate;  

                        newWeb = parentWeb.Webs.Add(webinfo);
                        ctx.ExecuteQueryRetry();
                        
                    }
                    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.CreateSubSite", _message);
                        throw;
                    }
                    
                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.CreateSubSite", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
                }

                catch (Exception ex)
                {
                    Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite",
                        PCResources.SiteCreation_Creation_Failure,
                        siteRequest.Url, ex.Message, ex);
                    throw;
                }
                Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSubSite", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
                
            };

            return newWeb;
        }
Beispiel #33
0
        /// <summary>
        /// Sends a Notification that the Site was created
        /// </summary>
        /// <param name="info"></param>
        protected void SendSuccessEmail(SiteInformation 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>
 /// Sets External Sharing
 /// This is not supported in on-premises builds.
 /// </summary>
 /// <param name="url"></param>
 public override void SetExternalSharing(SiteInformation siteInfo)
 {
     Log.Warning("Provisioning.Common.OnPremSiteProvisioningService.SetExternalSharing", PCResources.ExternalSharing_NotSupported, siteInfo.Url);
     return;
 }
        public SiteInformation 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.Name = "*****@*****.**";
            _additionalAdmins.Add(_admin1);
            _additionalAdmins.Add(_admin2);

            var _siteInfo = new SiteInformation()
            {
                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;

        }
 public abstract void SetExternalSharing(SiteInformation siteInfo);
        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);
        }
Beispiel #38
0
        /// <summary>
        /// Member to apply the Provisioning Tempalte to a site
        /// </summary>
        /// <param name="web"></param>
        /// <exception cref="ProvisioningTemplateException">An Exception that occurs when applying the template to a site</exception>
        public void ApplyProvisioningTemplate(ProvisioningTemplate provisioningTemplate, SiteInformation siteRequest, Template template)
        {
            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, template);

                ProvisioningTemplateApplyingInformation _pta = new ProvisioningTemplateApplyingInformation();
                _pta.ProgressDelegate = (message, step, total) =>
                {
                    Log.Info("SiteProvisioningManager.ApplyProvisioningTemplate", "Applying Provisioning template - Step {0}/{1} : {2} ", step, total, message);
                };
                _web.ApplyProvisioningTemplate(provisioningTemplate);
            }
            catch (Exception _ex)
            {
                var _message = string.Format("Error Occured when applying the template: {0} to site: {1}", _ex.Message, siteRequest.Url);
                throw new ProvisioningTemplateException(_message, _ex);
            }
        }
        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);
        }
 /// <summary>
 /// Member to apply the Provisioning Tempalte to a site
 /// </summary>
 /// <param name="web"></param>
 /// <exception cref="ProvisioningTemplateException">An Exception that occurs when applying the template to a site</exception>
 public void ApplyProvisioningTemplate(ProvisioningTemplate provisioningTemplate, SiteInformation siteRequest)
 {
     try
     {
         this._siteprovisioningService.Authentication         = new AppOnlyAuthenticationSite();
         this._siteprovisioningService.Authentication.SiteUrl = siteRequest.Url;
         var _web = _siteprovisioningService.GetWebByUrl(siteRequest.Url);
         provisioningTemplate.Connector = this.GetProvisioningConnector();
         provisioningTemplate           = new TemplateConversion().HandleProvisioningTemplate(provisioningTemplate, siteRequest);
         _web.ApplyProvisioningTemplate(provisioningTemplate);
     }
     catch (Exception _ex)
     {
         var _message = string.Format("Error Occured when applying the template: {0}", _ex.Message);
         throw new ProvisioningTemplateException(_message, _ex);
     }
 }
        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);
        }
 public abstract Web CreateSubSite(SiteInformation siteRequest, Template template);
Beispiel #43
0
        /// <summary>
        /// Sends an Failure Email Notification
        /// </summary>
        /// <param name="info"></param>
        /// <param name="errorMessage"></param>
        protected void SendFailureEmail(SiteInformation info, string errorMessage, bool sendToAdmin)
        {
            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;
                if (sendToAdmin)
                {
                    _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)
                {
                    if (sendToAdmin)
                    {
                        _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);
            }

        }
Beispiel #44
0
        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);
        }
        private void OperationWithRetry(ClientContext ctx, SpoOperation operation, SiteInformation siteRequest)
        {
            int currentRetry = 0;
            for (;;)
            {
                try
                {
                    System.Threading.Thread.Sleep(30000);
                    ctx.Load(operation);
                    ctx.ExecuteQuery();
                    Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", "Waiting for Site Collection {0} to be created", siteRequest.Url);
                    if (operation.IsComplete) break;
                }
                catch (Exception ex)
                {
                    currentRetry++;

                    if (currentRetry > this._retryCount || !IsTransientException(ex))
                    {
                        throw;
                    }
                }
            }
        }
 public abstract void CreateSiteCollection(SiteInformation siteRequest, Template template);
        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);
        }
Beispiel #48
0
 public abstract Web CreateSubSite(SiteInformation siteRequest, Template template);