예제 #1
0
파일: Program.cs 프로젝트: ivanvagunin/PnP
        /// <summary>
        ///  Can be used to test the storage queue message creation and to see the format what is created to the queue
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Update  parameters accordingly based on our environment from app.config
            // Update these accordingly for your environment
            string tenantName = ConfigurationManager.AppSettings["TenantName"];
            string ownwerEmail = ConfigurationManager.AppSettings["SiteColTestOwnerEmail"];

            // Create provisioning message objects for the storage queue
            ProvisioningData data = new ProvisioningData();
            data.TenantName = tenantName;
            // Add request data in
            data.RequestData = new SiteRequestData(){
                 Title = "Sample from queue",
                 Template = "STS#0",
                 Lcid = 1033,
                 Owner = ownwerEmail, 
                 StorageMaximumLevel = 100,
                 TimeZoneId = 16, 
                 Url = Guid.NewGuid().ToString().Replace("-", "")
            };
            // Add branding data structure in
            data.BrandingData = new SiteBrandingData(){
                LogoImagePath = "",
                ThemeBackgrounImagePath = "",
                ThemeColorFilePath = "",
                ThemeFontFilePath = "", 
                ThemeMasterPageName = "",
                ThemeName = ""
            };

            new SiteRequestManager().AddConfigRequestToQueue(data,
                                            CloudConfigurationManager.GetSetting("StorageConnectionString"));
        }
예제 #2
0
        /// <summary>
        /// Used to upload and apply branding to the newly created site. You could add new libraries and whatever needed.
        /// </summary>
        /// <param name="webUrl"></param>
        /// <param name="token"></param>
        /// <param name="realm"></param>
        private static void ApplyTemplateForCreatedSiteCollection(string webUrl, ProvisioningData provisionData)
        {
            //get the new site collection
            var    siteUri = new Uri(webUrl);
            string realm   = TokenHelper.GetRealmFromTargetUrl(siteUri);
            var    token   = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            using (var ctx = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), token))
            {
                // Set the time out as high as possible
                ctx.RequestTimeout = Timeout.Infinite;

                // Let's first upload the custom theme to host web
                DeployThemeToWeb(ctx.Web,
                                 provisionData.BrandingData.ThemeName,
                                 provisionData.BrandingData.ThemeColorFilePath,
                                 string.Empty,
                                 provisionData.BrandingData.ThemeBackgrounImagePath,
                                 provisionData.BrandingData.ThemeMasterPageName);

                // Apply theme. We could upload a custom one as well or apply any other changes to newly created site
                SetThemeBasedOnName(ctx.Web, "Garage");

                // Upload the assets to host web
                SetLogoToWeb(ctx.Web, provisionData.BrandingData.LogoImagePath);
            }
        }
예제 #3
0
        /// <summary>
        /// Used to add new storage queue entry.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="siteUrl"></param>
        /// <param name="storageConnectionString"></param>
        public void AddConfigRequestToQueue(ProvisioningData provisioningData, string storageConnectionString)
        {
            CloudStorageAccount storageAccount =
                                CloudStorageAccount.Parse(storageConnectionString);

            // Get queue... create if does not exist.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue queue =
                queueClient.GetQueueReference(SiteRequestManager.StorageQueueName);
            queue.CreateIfNotExists();

            // Add entry to queue
            queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(provisioningData)));

        }
예제 #4
0
        /// <summary>
        /// Used to add new storage queue entry.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="siteUrl"></param>
        /// <param name="storageConnectionString"></param>
        public void AddConfigRequestToQueue(ProvisioningData provisioningData, string storageConnectionString)
        {
            CloudStorageAccount storageAccount =
                CloudStorageAccount.Parse(storageConnectionString);

            // Get queue... create if does not exist.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       =
                queueClient.GetQueueReference(SiteRequestManager.StorageQueueName);

            queue.CreateIfNotExists();

            // Add entry to queue
            queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(provisioningData)));
        }
예제 #5
0
파일: Program.cs 프로젝트: tandis/PnP
        static void Main(string[] args)
        {
            // Update these accordingly for your environment
            string tenantName = ConfigurationManager.AppSettings["TenantName"];
            string ownwerEmail = ConfigurationManager.AppSettings["SiteColTestOwnerEmail"];

            //create site collection using the Tenant object. Notice that you will need to have valid app ID and secret for this one
            var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantName));
            string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
            var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;
            using (var adminContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
            {
                // Let's randomize URL for your testing
                string webUrl = Guid.NewGuid().ToString().Replace("-", "");
                var webFullUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantName, "sites", webUrl);

                if (!new SiteRequestManager().SiteURLAlreadyInUse(adminContext, webFullUrl))
                {
                    // Call the creation.
                    ProvisioningData data = new ProvisioningData();
                    data.TenantName = tenantName;
                    // Add request data in
                    data.RequestData = new SiteRequestData()
                    {
                        Title = "Test Provisioning",
                        Template = "STS#0",
                        Lcid = 1033,
                        Owner = "*****@*****.**",
                        StorageMaximumLevel = 100,
                        TimeZoneId = 10,  // US east coast
                        Url = webUrl
                    };
                    // Add branding data structure in
                    data.BrandingData = new SiteBrandingData()
                    {
                        LogoImagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\garagelogo.png"),
                        ThemeBackgrounImagePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\garagebg.jpg"),
                        ThemeColorFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\garagewhite.spcolor"),
                        ThemeFontFilePath = "",
                        ThemeName = "Garage",
                        ThemeMasterPageName = "seattle.master"
                    };

                    // Process request for new site
                    new SiteRequestManager().ProcessSiteCreationRequest(adminContext, data);
                }
            }
        }
예제 #6
0
        public string ProcessSiteCreationRequest(ClientContext adminCtx, ProvisioningData provisionData)
        {
            // Create the site collection
            //get the base tenant administration urls
            var webFullUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", provisionData.TenantName, "sites", provisionData.RequestData.Url);

            var tenant     = new Tenant(adminCtx);
            var properties = new SiteCreationProperties()
            {
                Url                 = webFullUrl,
                Owner               = provisionData.RequestData.Owner,
                Title               = provisionData.RequestData.Title,
                Template            = provisionData.RequestData.Template,
                TimeZoneId          = provisionData.RequestData.TimeZoneId,
                Lcid                = provisionData.RequestData.Lcid,
                StorageMaximumLevel = provisionData.RequestData.StorageMaximumLevel
            };

            //start the SPO operation to create the site
            SpoOperation op = tenant.CreateSite(properties);

            adminCtx.Load(tenant);
            adminCtx.Load(op, i => i.IsComplete);
            adminCtx.ExecuteQuery();

            //check if site creation operation is complete
            while (!op.IsComplete)
            {
                //wait 15 seconds and try again
                System.Threading.Thread.Sleep(15000);
                op.RefreshLoad();
                adminCtx.ExecuteQuery();
            }

            // Apply branding if theme information is provided
            if (!string.IsNullOrEmpty(provisionData.BrandingData.ThemeName))
            {
                ApplyTemplateForCreatedSiteCollection(webFullUrl, provisionData);
            }

            return(webFullUrl);
        }
예제 #7
0
        public string ProcessSiteCreationRequest(ClientContext adminCtx, ProvisioningData provisionData)
        {
            // Create the site collection
            //get the base tenant administration urls
            var webFullUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", provisionData.TenantName, "sites", provisionData.RequestData.Url);

            var tenant = new Tenant(adminCtx);
            var properties = new SiteCreationProperties()
            {
                Url = webFullUrl,
                Owner = provisionData.RequestData.Owner,
                Title = provisionData.RequestData.Title,
                Template = provisionData.RequestData.Template,
                TimeZoneId = provisionData.RequestData.TimeZoneId,
                Lcid = provisionData.RequestData.Lcid,
                StorageMaximumLevel = provisionData.RequestData.StorageMaximumLevel
            };

            //start the SPO operation to create the site
            SpoOperation op = tenant.CreateSite(properties);
            adminCtx.Load(tenant);
            adminCtx.Load(op, i => i.IsComplete);
            adminCtx.ExecuteQuery();

            //check if site creation operation is complete
            while (!op.IsComplete)
            {
                //wait 15 seconds and try again
                System.Threading.Thread.Sleep(15000);
                op.RefreshLoad();
                adminCtx.ExecuteQuery();
            }

            // Apply branding if theme information is provided
            if (!string.IsNullOrEmpty(provisionData.BrandingData.ThemeName))
            {
                ApplyTemplateForCreatedSiteCollection(webFullUrl, provisionData);
            }

            return webFullUrl;
        }
예제 #8
0
        private void AddRequestToQueue(string ownerEmail)
        {
            ProvisioningData data = new ProvisioningData();
            // Add request data in
            data.RequestData = new SiteRequestData()
            {
                Title = txtTitle.Text,
                Template = listTemplates.SelectedValue,
                Lcid = uint.Parse(language.SelectedValue),
                Owner = ownerEmail,
                StorageMaximumLevel = int.Parse(txtStorage.Text),
                TimeZoneId = int.Parse(timeZone.SelectedValue),
                Url = txtUrl.Text
            };

            // Resolve tenant name
            var tenantStr = Page.Request["SPHostUrl"].ToLower().Replace("-my", "").Substring(8);
            data.TenantName = tenantStr.Substring(0, tenantStr.IndexOf("."));

            new SiteRequestManager().AddConfigRequestToQueue(data,
                                            CloudConfigurationManager.GetSetting("StorageConnectionString"));
        }
예제 #9
0
        /// <summary>
        /// Used to upload and apply branding to the newly created site. You could add new libraries and whatever needed.
        /// </summary>
        /// <param name="webUrl"></param>
        /// <param name="token"></param>
        /// <param name="realm"></param>
        private static void ApplyTemplateForCreatedSiteCollection(string webUrl, ProvisioningData provisionData)
        {
            //get the new site collection
            var siteUri = new Uri(webUrl);
            string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
            var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;

            using (var ctx = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), token))
            {
                // Set the time out as high as possible
                ctx.RequestTimeout = Timeout.Infinite;

                // Let's first upload the custom theme to host web
                DeployThemeToWeb(ctx.Web,
                                provisionData.BrandingData.ThemeName,
                                provisionData.BrandingData.ThemeColorFilePath,
                                string.Empty,
                                provisionData.BrandingData.ThemeBackgrounImagePath,
                                provisionData.BrandingData.ThemeMasterPageName);

                // Apply theme. We could upload a custom one as well or apply any other changes to newly created site
                SetThemeBasedOnName(ctx.Web, "Garage");

                // Upload the assets to host web
                SetLogoToWeb(ctx.Web, provisionData.BrandingData.LogoImagePath);
            }
        }