public async Task CheckSubscriptionAsync(GraphServiceClient graphService) { Subscription subscription = System.Web.HttpContext.Current.Session["WebHookSubscription"] as Subscription; if (subscription != null && subscription.ExpirationDateTime.HasValue) { DateTimeOffset expiration = (DateTimeOffset)subscription.ExpirationDateTime; //check time if (DateTimeOffset.Now.CompareTo(expiration) >= 0) { //delete old and recreate one await graphService.DeleteSubscriptionAsync(subscription.Id); subscription = await graphService.CreateSubscriptionAsync(); if (subscription != null) { System.Web.HttpContext.Current.Session["WebHookSubscription"] = subscription; } } } else { subscription = await graphService.CreateSubscriptionAsync(); if (subscription != null) { System.Web.HttpContext.Current.Session["WebHookSubscription"] = subscription; } } }
public async Task <ActionResult> DeleteSubscription(string subscriptionId) { try { GraphServiceClient graphServiceClient = await AuthenticationHelper.GetGraphServiceAsync(AADAppSettings.GraphResourceUrl); var accessToken = await AuthenticationHelper.GetGraphAccessTokenAsync(); await graphServiceClient.DeleteSubscriptionAsync(accessToken, subscriptionId); } catch (ServiceException e) { return(Content("Throw exception " + e.Error.Message.ToString())); } return(RedirectToAction("Index", "WebHooks")); }
public async Task <ActionResult> DeleteSubscription() { Subscription subscription = System.Web.HttpContext.Current.Session["WebHookSubscription"] as Subscription; if (subscription != null) { try { GraphServiceClient graphServiceClient = await AuthenticationHelper.GetGraphServiceAsync(AADAppSettings.GraphResourceUrl); var accessToken = await AuthenticationHelper.GetGraphAccessTokenAsync(); await graphServiceClient.DeleteSubscriptionAsync(accessToken, subscription.Id); System.Web.HttpContext.Current.Session.Remove("WebHookSubscription"); } catch (ServiceException e) { return(Content("Throw exception " + e.Error.Message.ToString())); } return(RedirectToAction("Index", "WebHooks")); } return(Content("Subscription not found.")); }
public async Task CheckSubscriptionAsync(GraphServiceClient graphService, string accessToken) { Subscription subscription = System.Web.HttpContext.Current.Session["WebHookSubscription"] as Subscription; if (subscription != null && subscription.ExpirationDateTime.HasValue) { DateTimeOffset expiration = (DateTimeOffset)subscription.ExpirationDateTime; //check time if (DateTimeOffset.Now.CompareTo(expiration) >= 0) { //delete old and recreate one await graphService.DeleteSubscriptionAsync(accessToken, subscription.Id); subscription = await graphService.CreateSubscriptionAsync(accessToken); if (subscription != null) { System.Web.HttpContext.Current.Session["WebHookSubscription"] = subscription; } } } else { subscription = await graphService.CreateSubscriptionAsync(accessToken); if (subscription != null) { System.Web.HttpContext.Current.Session["WebHookSubscription"] = subscription; } } }