static void Main(string[] args) { string requestorName = "Keyser Söze"; string siteUrl = "https://vesaj.sharepoint.com/sites/dev"; SiteModifyRequest request = new SiteModifyRequest() { RequestorName = requestorName, SiteUrl = siteUrl }; new SiteManager().AddAsyncOperationRequestToQueue(request, ConfigurationManager.AppSettings["StorageConnectionString"]); }
// This function will get triggered/executed when a new message is written // on an Azure Queue called queue. public static void ProcessQueueMessage( [QueueTrigger(SiteManager.StorageQueueName)] SiteModifyRequest modifyRequest, TextWriter log) { log.WriteLine(string.Format("{0} '{1}' {2} '{3}'.", "Received new site modification request with URL", modifyRequest.SiteUrl, "from person named as ", modifyRequest.RequestorName)); try { Uri targetSite = new Uri(modifyRequest.SiteUrl); //Get the realm for the URL string realm = TokenHelper.GetRealmFromTargetUrl(targetSite); //Get the access token for the URL. // Requires this app to be registered with the tenant string accessToken = TokenHelper.GetAppOnlyAccessToken( TokenHelper.SharePointPrincipal, targetSite.Authority, realm).AccessToken; //Get client context with access token using (var ctx = TokenHelper.GetClientContextWithAccessToken( targetSite.ToString(), accessToken)) { // Call actual business logic component new SiteManager().PerformSiteModification(ctx, modifyRequest); } } catch (Exception ex) { log.WriteLine(string.Format("Site modification to URL {0} failed with following details.", modifyRequest.SiteUrl)); log.WriteLine(ex.ToString()); throw; } }
protected void btnSync_Click(object sender, EventArgs e) { var spContext = SharePointContextProvider.Current.GetSharePointContext(Context); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { //get the current user to be set for the process var currUser = clientContext.Web.CurrentUser; clientContext.Load(currUser); clientContext.ExecuteQuery(); // Add request to the process queue SiteModifyRequest request = new SiteModifyRequest() { RequestorName = currUser.Title, SiteUrl = Page.Request["SPHostUrl"] }; new SiteManager().PerformSiteModification(clientContext, request); // Change active view processViews.ActiveViewIndex = 1; lblStatus.Text = "Synchronous operation completed."; } }
protected void btnAsync_Click(object sender, EventArgs e) { var spContext = SharePointContextProvider.Current.GetSharePointContext(Context); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { //get the current user to be set for the process var currUser = clientContext.Web.CurrentUser; clientContext.Load(currUser); clientContext.ExecuteQuery(); // Add request to queue SiteModifyRequest request = new SiteModifyRequest() { RequestorName = currUser.Title, SiteUrl = Page.Request["SPHostUrl"] }; new SiteManager().AddAsyncOperationRequestToQueue(request, ConfigurationManager.AppSettings["StorageConnectionString"]); // Change active view processViews.ActiveViewIndex = 1; lblStatus.Text = "Asynchronous operation started, end user can continue."; } }