public bool ProvisionSiteCollection(Contract.SharePointProvisioningData sharePointProvisioningData) { bool processed = false; try { SiteProvisioningBase siteToProvision = null; switch (sharePointProvisioningData.Template) { case SiteProvisioningTypes.ContosoCollaboration: siteToProvision = new ContosoCollaboration(); break; case SiteProvisioningTypes.ContosoProject: siteToProvision = new ContosoProject(); break; } siteToProvision.SharePointProvisioningData = sharePointProvisioningData; HookupAuthentication(siteToProvision); // Hookup class that will hold the on-prem overrides SiteProvisioningOnPremises spo = new SiteProvisioningOnPremises(); siteToProvision.SiteProvisioningOnPremises = spo; // Provision the site collection processed = siteToProvision.Execute(); } catch (Exception ex) { Console.WriteLine(ex.Message); //log error } return processed; }
private bool ProcessMessage(string message) { bool processed = true; SharePointProvisioningData sharePointProvisioningData = DeserializeData(message); if (sharePointProvisioningData.DataClassification.Equals("HBI", StringComparison.InvariantCultureIgnoreCase)) { try { // Determine the system connectivity mode based on the command line // arguments: -http, -tcp or -auto (defaults to auto) ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect; string serviceNamespace = RoleEnvironment.GetConfigurationSettingValue("General.SBServiceNameSpace"); string issuerName = RoleEnvironment.GetConfigurationSettingValue("General.SBIssuerName"); string issuerSecret = EncryptionUtility.Decrypt(RoleEnvironment.GetConfigurationSettingValue("General.SBIssuerSecret"), RoleEnvironment.GetConfigurationSettingValue("General.EncryptionThumbPrint")); // create the service URI based on the service namespace Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "SharePointProvisioning"); // create the credentials object for the endpoint TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior(); sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret); // create the channel factory loading the configuration ChannelFactory<ISharePointProvisioningChannel> channelFactory = new ChannelFactory<ISharePointProvisioningChannel>("RelayEndpoint", new EndpointAddress(serviceUri)); // apply the Service Bus credentials channelFactory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential); // create and open the client channel ISharePointProvisioningChannel channel = channelFactory.CreateChannel(); channel.Open(); channel.ProvisionSiteCollection(sharePointProvisioningData); channel.Close(); channelFactory.Close(); } catch (Exception ex) { Debug.WriteLine(ex.Message); //log error } } else { try { SiteProvisioningBase siteToProvision = null; switch (sharePointProvisioningData.Template) { case SiteProvisioningTypes.ContosoCollaboration: siteToProvision = new ContosoCollaboration(); break; case SiteProvisioningTypes.ContosoProject: siteToProvision = new ContosoProject(); break; } siteToProvision.SharePointProvisioningData = sharePointProvisioningData; HookupAuthentication(siteToProvision); // Provision the site collection processed = siteToProvision.Execute(); } catch (Exception ex) { Debug.WriteLine(ex.Message); //log error } } // always return true to get the item of the queue...no retry mechanism foreseen return true; }