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(); }
private void ProcessSiteRequest() { try { string generalSiteDirectoryUrl = RoleEnvironment.GetConfigurationSettingValue("General.SiteDirectoryUrl"); string generalSiteDirectoryListName = RoleEnvironment.GetConfigurationSettingValue("General.SiteDirectoryListName"); string generalSiteDirectoryProvisioningPage = RoleEnvironment.GetConfigurationSettingValue("General.SiteDirectoryProvisioningPage"); string generalSiteCollectionUrl = RoleEnvironment.GetConfigurationSettingValue("General.SiteCollectionUrl"); string generalMailSMTPServer = RoleEnvironment.GetConfigurationSettingValue("General.MailSMTPServer"); string generalMailUser = RoleEnvironment.GetConfigurationSettingValue("General.MailUser"); string generalMailUserPassword = RoleEnvironment.GetConfigurationSettingValue("General.MailUserPassword"); string generalMailSiteRequested = RoleEnvironment.GetConfigurationSettingValue("General.MailSiteRequested"); string generalEncryptionThumbPrint = RoleEnvironment.GetConfigurationSettingValue("General.EncryptionThumbPrint"); //Manager initiation SiteDirectoryManager siteDirectoryManager = new SiteDirectoryManager(); //Decrypt mail password generalMailUserPassword = EncryptionUtility.Decrypt(generalMailUserPassword, generalEncryptionThumbPrint); // SharePoint context for the host web var spContext = SharePointContextProvider.Current.GetSharePointContext(Context); ClientContext hostWebClientContext = spContext.CreateAppOnlyClientContextForSPHost(); // Object that contains data about the site collection we're gonna provision SharePointProvisioningData siteData = new SharePointProvisioningData(); siteData.Url = String.Format("{0}{1}", generalSiteCollectionUrl, Guid.NewGuid().ToString()); // Deal with the Title siteData.Title = txtTitle.Text; // Deal with the template siteData.Template = drlTemplate.SelectedItem.Value; // Deal with the data classification siteData.DataClassification = drlClassification.SelectedItem.Value; // Deal with the site name (empty for root) siteData.Name = ""; // Deal with the site owners List<SharePointUser> ownersList = JsonUtility.Deserialize<List<SharePointUser>>(hdnAdministrators.Value); SharePointUser[] owners = new SharePointUser[ownersList.Count]; List<String> mailTo = new List<string>(ownersList.Count); string ownerNames = ""; string ownerAccounts = ""; int i = 0; foreach (SharePointUser owner in ownersList) { owner.Login = StripUPN(owner.Login); owners[i] = owner; mailTo.Add(owner.Email); if (ownerNames.Length > 0) { ownerNames = ownerNames + ", "; ownerAccounts = ownerAccounts + ", "; } ownerNames = ownerNames + owner.Name; ownerAccounts = ownerAccounts + owner.Login; i++; } siteData.Owners = owners; #if (DEBUG) //In debug mode have the WCF call ignore certificate errors System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { return true; }; #endif // Provision site collection on the using (SharePointProvisioning.SharePointProvisioningServiceClient service = new SharePointProvisioning.SharePointProvisioningServiceClient()) { if (service.ProvisionSiteCollection(siteData)) { string[] ownerLogins = new string[owners.Length]; int j = 0; foreach (SharePointUser owner in owners) { ownerLogins[j] = owner.Login; j++; } siteDirectoryManager.AddSiteDirectoryEntry(hostWebClientContext, hostWebClientContext.Web, generalSiteDirectoryUrl, generalSiteDirectoryProvisioningPage, generalSiteDirectoryListName, siteData.Title, siteData.Url, siteData.Template, ownerLogins); string mailBody = String.Format(generalMailSiteRequested, siteData.Title, ownerNames, ownerAccounts); MailUtility.SendEmail(generalMailSMTPServer, generalMailUser, generalMailUserPassword, mailTo, null, "Your SharePoint site request has been registered", mailBody); } } if (Page.Request["IsDlg"].Equals("0", StringComparison.InvariantCultureIgnoreCase)) { // redirect to host web home page Response.Redirect(Page.Request["SPHostUrl"]); } else { // refresh the page from which the dialog was opened. Normally this is always the SPHostUrl ClientScript.RegisterStartupScript(typeof(Default), "RedirectToSite", "navigateParent('" + Page.Request["SPHostUrl"] + "');", true); } } catch (Exception ex) { lblErrors.Text = String.Format("Error: {0} \n\r Stacktrace: {1}", ex.Message, ex.StackTrace); } }