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); }
static void Main(string[] args) { // Determine the system connectivity mode based on the command line // arguments: -http, -tcp or -auto (defaults to auto) ServiceBusEnvironment.SystemConnectivity.Mode = GetConnectivityMode(args); string serviceNamespace = ConfigurationManager.AppSettings["General.SBServiceNameSpace"]; string issuerName = ConfigurationManager.AppSettings["General.SBIssuerName"]; string issuerSecret = EncryptionUtility.Decrypt(ConfigurationManager.AppSettings["SBIssuerSecret"], ConfigurationManager.AppSettings["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(); SharePointProvisioningData sharePointProvisioningData = new SharePointProvisioningData(); sharePointProvisioningData.Title = "Test site on-premises"; sharePointProvisioningData.Url = String.Format("{0}{1}", "https://bertonline.sharepoint.com/sites/", Guid.NewGuid().ToString()); sharePointProvisioningData.Template = "ContosoCollaboration"; sharePointProvisioningData.Name = ""; sharePointProvisioningData.DataClassification = "HBI"; SharePointUser[] owners = new SharePointUser[1]; SharePointUser owner = new SharePointUser(); owner.Login = "******"; owner.Name = "Kevin Cook"; owner.Email = "*****@*****.**"; owners[0] = owner; sharePointProvisioningData.Owners = owners; channel.ProvisionSiteCollection(sharePointProvisioningData); //Console.WriteLine("Enter text to echo (or [Enter] to exit):"); //string input = Console.ReadLine(); //while (input != String.Empty) //{ // try // { // Console.WriteLine("Server echoed: {0}", channel.Echo(input)); // } // catch (Exception e) // { // Console.WriteLine("Error: " + e.Message); // } // input = Console.ReadLine(); //} Console.ReadLine(); channel.Close(); channelFactory.Close(); }