Пример #1
0
        /// <summary>
        /// Perform call to on-prem
        /// </summary>
        /// <param name="request"></param>
        /// <param name="log"></param>
        private static void ProcessOnPremRequest(SiteCollectionRequest request, TextWriter log)
        {

            log.WriteLine(String.Format("Send request to create new site collection at {0}", DateTime.Now.ToLongTimeString()));

            string returnMessage = new ServiceBusMessageManager().SendSiteRequestMessage(request,
                                                            ConfigurationManager.AppSettings[Consts.ServiceBusNamespaceKey],
                                                            ConfigurationManager.AppSettings[Consts.ServiceBusSecretKey]);

            log.WriteLine(String.Format("Got followign message back '{0}' at {1}", returnMessage, DateTime.Now.ToLongTimeString()));

        }
Пример #2
0
        /// <summary>
        /// Operation to create new site collections in the service side
        /// </summary>
        /// <param name="siteTitle"></param>
        /// <param name="siteTemplate"></param>
        /// <param name="ownerIdentifier"></param>
        /// <param name="serviceBusNameSpace"></param>
        /// <param name="serviceBusSecret"></param>
        public string SendSiteRequestMessage(SiteCollectionRequest request, string serviceBusNamespace, string serviceBusSecret)
        {
            var cf = new ChannelFactory<ISiteRequest>(
                        new NetTcpRelayBinding(),
                        new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("sb", serviceBusNamespace, "solver")));

            cf.Endpoint.Behaviors.Add(
                new TransportClientEndpointBehavior { 
                    TokenProvider = TokenProvider.CreateSharedSecretTokenProvider("owner", serviceBusSecret) });

            // Open channel and call the method
            var ch = cf.CreateChannel();
            string createdUrl = ch.ProvisionSiteCollection(request);
            cf.Close();

            return createdUrl;
        }
Пример #3
0
        static void Main(string[] args)
        {
            string returnMessage = "";

            try
            {
                string message = string.Format("Test message sent at {0}", DateTime.Now.ToLongTimeString());
                System.Console.WriteLine(String.Format("Sending this message: '{0}'", message));

                // Send message using centralized business component for testing purposes
                returnMessage = new ServiceBusMessageManager().SendMessage(message,
                                                                ConfigurationManager.AppSettings[Consts.ServiceBusNamespaceKey],
                                                                ConfigurationManager.AppSettings[Consts.ServiceBusSecretKey]);

                System.Console.WriteLine(String.Format("Got back this message: '{0}' at {1}", returnMessage, DateTime.Now.ToLongTimeString()));

                // Alternative to test site collection creation using console
                SiteCollectionRequest request = new SiteCollectionRequest()
                 {
                     Template = "STS#0",
                     Title = "New site",
                     OwnerIdentifier = "",
                     TargetEnvironment = Consts.DeploymentTypeOnPremises
                 };
                System.Console.WriteLine(String.Format("Send request to create new site collection at {0}", DateTime.Now.ToLongTimeString()));
                returnMessage = new ServiceBusMessageManager().SendSiteRequestMessage(request,
                                                                ConfigurationManager.AppSettings[Consts.ServiceBusNamespaceKey],
                                                                ConfigurationManager.AppSettings[Consts.ServiceBusSecretKey]);


                System.Console.ForegroundColor = ConsoleColor.Green;
                System.Console.WriteLine(String.Format("Got followign message back: '{0}' at {1}", returnMessage, DateTime.Now.ToLongTimeString()));
            }
            catch (Exception ex)
            {
                System.Console.ForegroundColor = ConsoleColor.Red;
                System.Console.WriteLine(String.Format("Exception with the execution. Error description: '{0}'", ex.ToString()));
            }


            // Just to keep it hanging in the service... could be hosted for example as windows service for better handling
            System.Console.ForegroundColor = ConsoleColor.Gray;
            System.Console.WriteLine("Press ENTER to close");
            System.Console.ReadLine();

        }
Пример #4
0
        /// <summary>
        /// Actual business logic to create the site collections.
        /// See more details on the requirements for on-premises from following blog post:
        /// http://blogs.msdn.com/b/vesku/archive/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom.aspx
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private static string ProcessSiteCreationRequest(SiteCollectionRequest request)
        {
            // Get the base tenant admin url needed for site collection creation
            string tenantStr = ConfigurationManager.AppSettings[Consts.AdminSiteCollectionUrl];

            // Resolve root site collection URL from host web.
            string rootSiteUrl = ConfigurationManager.AppSettings[Consts.LeadingURLForSiteCollections];

            // Create unique URL based on GUID. In real production implementation you might do this otherways, but this is for simplicity purposes
            var webUrl = string.Format("{0}/sites/{1}", rootSiteUrl, Guid.NewGuid().ToString().Replace("-", ""));
            var tenantAdminUri = ConfigurationManager.AppSettings[Consts.AdminSiteCollectionUrl];

            // Notice that we do NOT use app model where for this sample. We use just specific service account. Could be easily
            // changed for example based on following sample: https://github.com/OfficeDev/PnP/tree/master/Samples/Provisioning.OnPrem.Async 
            using (var ctx = new ClientContext(tenantAdminUri))
            {
                ctx.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings[Consts.ProvisioningAccount], 
                                                                    ConfigurationManager.AppSettings[Consts.ProvisioningPassword], 
                                                                    ConfigurationManager.AppSettings[Consts.ProvisioningDomain]);
                // Set the time out as high as possible
                ctx.RequestTimeout = Timeout.Infinite;

                var tenant = new Tenant(ctx);
                var properties = new SiteCreationProperties()
                {
                    Url = webUrl,
                    Owner = string.Format("{0}\\{1}", 
                                ConfigurationManager.AppSettings[Consts.ProvisioningDomain], 
                                ConfigurationManager.AppSettings[Consts.ProvisioningAccount]),
                    Title = request.Title,
                    Template = "STS#0" // Create always team site, but specialize the site based on the template value
                };

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

            // Do some branding for the new site
            SetThemeToNewSite(webUrl);

            // Do addditional customziations based on the selected template request.Template

            return webUrl;
        }
Пример #5
0
        /// <summary>
        /// Ccloud request processing. Based on following project: 
        /// This should be located in cloud specific buisness logic component, but added here for simplicity reasons.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="log"></param>
        private static void ProcessCloudRequest(SiteCollectionRequest request, TextWriter log)
        {
            //get the base tenant admin urls
            string tenantStr = ConfigurationManager.AppSettings["Office365Tenant"];

            //create site collection using the Tenant object
            var webUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantStr, "sites", Guid.NewGuid().ToString().Replace("-", ""));
            var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));

            // Connecting to items using app only token
            string realm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
            var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, realm).AccessToken;
            using (var adminContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token))
            {
                var tenant = new Tenant(adminContext);
                var properties = new SiteCreationProperties()
                {
                    Url = webUrl,
                    Owner = request.OwnerIdentifier,
                    Title = request.Title,
                    Template = "STS#0", // Create always team site and specialize after site collection is created as needed
                    StorageMaximumLevel = 100,
                    UserCodeMaximumLevel = 100
                };

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

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

            log.WriteLine(String.Format("Create new site collection with URL '{1}' at {0}", webUrl, DateTime.Now.ToLongTimeString()));
            ApplyTemplateForCreatedSiteCollection(webUrl, token, realm);
            log.WriteLine(String.Format("Applied custom branding to new site collection with URL '{1}' at {0}", webUrl, DateTime.Now.ToLongTimeString()));
        }
Пример #6
0
        /// <summary>
        /// Operation to create new site collections in the service side
        /// </summary>
        /// <param name="siteTitle"></param>
        /// <param name="siteTemplate"></param>
        /// <param name="ownerIdentifier"></param>
        /// <param name="serviceBusNameSpace"></param>
        /// <param name="serviceBusSecret"></param>
        public string SendSiteRequestMessage(SiteCollectionRequest request, string serviceBusNamespace, string serviceBusSecret)
        {
            var cf = new ChannelFactory <ISiteRequest>(
                new NetTcpRelayBinding(),
                new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("sb", serviceBusNamespace, "solver")));

            cf.Endpoint.Behaviors.Add(
                new TransportClientEndpointBehavior {
                TokenProvider = TokenProvider.CreateSharedSecretTokenProvider("owner", serviceBusSecret)
            });

            // Open channel and call the method
            var    ch         = cf.CreateChannel();
            string createdUrl = ch.ProvisionSiteCollection(request);

            cf.Close();

            return(createdUrl);
        }
Пример #7
0
 /// <summary>
 /// Main business logic to drive provisioning
 /// </summary>
 /// <param name="message">Request details</param>
 /// <param name="serviceBusNamespace">Service bus namespace, used if on+p</param>
 /// <param name="serviceBusSecret">Service bus secret</param>
 /// <returns></returns>
 public bool ProcessCloudSiteRequest(SiteCollectionRequest request)
 {
     return(false);
 }
Пример #8
0
 /// <summary>
 /// Main business logic to drive provisioning
 /// </summary>
 /// <param name="message">Request details</param>
 /// <param name="serviceBusNamespace">Service bus namespace, used if on+p</param>
 /// <param name="serviceBusSecret">Service bus secret</param>
 /// <returns></returns>
 public bool ProcessOnPremSiteRequest(SiteCollectionRequest request, string serviceBusNamespace, string serviceBusSecret)
 {
     return(true);
 }
Пример #9
0
        // Site creation request to queue
        private void ProcessSiteRequest(string adminEmail)
        {

            CloudStorageAccount storageAccount =
                                CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Get queue... create if does not exist.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue queue =
                queueClient.GetQueueReference(Provisioning.Hybrid.Simple.Common.Consts.StorageQueueName);
            queue.CreateIfNotExists();

            // Pass in data for modification
            var newSiteRequest = new SiteCollectionRequest()
            {
                Title = txtTitle.Text,
                OwnerIdentifier = adminEmail,
                TargetEnvironment = drlEnvironment.SelectedValue,
                Template = drlTemplate.SelectedValue
            };

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