예제 #1
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);
            }
           
        }
예제 #2
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.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);
            });
        }
예제 #3
0
 private void HandleSitePolicy(ProvisioningTemplate provisioningTemplate, SiteInformation siteRequest, Template template)
 {
     if (!template.UseTemplateDefinedPolicy)
     {
         if (!string.IsNullOrWhiteSpace(siteRequest.SitePolicy))
         {
             provisioningTemplate.SitePolicy = siteRequest.SitePolicy;
         }
     }
 }
예제 #4
0
 internal ProvisioningTemplate HandleProvisioningTemplate(ProvisioningTemplate provisioningTemplate, SiteInformation siteRequest, Template template)
 {
     this.HandleExternalSharing(provisioningTemplate, siteRequest);
     this.HandleSitePolicy(provisioningTemplate, siteRequest, template);
     this.HandleAdditionalAdministrators(provisioningTemplate, siteRequest);
     this.HandlePropertyBagEntries(provisioningTemplate, siteRequest);
     this.HandleCustomActions(provisioningTemplate, siteRequest);
     this.HandleParameters(provisioningTemplate, siteRequest);
     return provisioningTemplate;
 }
예제 #5
0
 public SiteProvisioningManager(SiteInformation siteRequest, Template template)
 {
     if (template.SharePointOnPremises)
     {
         _siteprovisioningService = new OnPremSiteProvisioningService();
     }
     else
     {
         _siteprovisioningService = new Office365SiteProvisioningService();
     }
 }
예제 #6
0
 /// <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);
     }
    
 }
예제 #7
0
        public MdlzCommonCustomizations(SiteInformation _request, ProvisioningTemplate _provTemplate, Template template)
        {
            request = _request;
            provTemplate = _provTemplate;

            if (appSettings == null)
            {
                IConfigurationFactory _cf = ConfigurationFactory.GetInstance();
                IAppSettingsManager _manager = _cf.GetAppSetingsManager();
                appSettings = _manager.GetAppSettings();
            }
            Authentication = new AppOnlyAuthenticationSite();
            Authentication.SiteUrl = _request.Url;
        }
예제 #8
0
        public string GenerateSiteUrl(
            SiteInformation siteRequest, 
            Template template, 
            bool avoidDuplicateUrls = false)
        {
            var url = template.HostPath;
            if(!url.EndsWith("/"))
            {
                url += "/";
            }
            url += siteRequest.Title.UrlNameFromString();

            return url;
        }
예제 #9
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");                
            }           
        }
예제 #10
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);
            }
        }
예제 #11
0
        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);
        }
예제 #12
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;
        }
 public abstract Web CreateSubSite(SiteInformation siteRequest, Template template);
예제 #14
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;
        }
예제 #15
0
 public abstract void CreateSiteCollection(SiteInformation siteRequest, Template template);
예제 #16
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);
        }
예제 #17
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();
                    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);
        }