/// <summary> /// Get the changed message details /// Update the local json file /// Continue to update the UI using SignalR /// </summary> /// <param name="notifications"></param> /// <returns></returns> public async Task GetChangedMessagesAsync(IEnumerable <NotificationItem> notifications) { DataService dataService = new DataService(); MailService mailService = new MailService(); int newMessages = 0; foreach (var notification in notifications) { var subscription = SubscriptionStore.GetSubscriptionInfo(notification.SubscriptionId); var graphClient = GraphServiceClientProvider.GetAuthenticatedClient(subscription.UserId); try { // Get the message var message = await mailService.GetMessage(graphClient, notification.ResourceData.Id); // update the local json file if (message != null) { var messageItem = new MessageItem { BodyPreview = message.BodyPreview, ChangeKey = message.ChangeKey, ConversationId = message.ConversationId, CreatedDateTime = (DateTimeOffset)message.CreatedDateTime, Id = message.Id, IsRead = (bool)message.IsRead, Subject = message.Subject }; var messageItems = new List <MessageItem> { messageItem }; dataService.StoreMessage(messageItems, message.ParentFolderId, null); newMessages += 1; } } catch (Exception e) { // ignored } } if (newMessages > 0) { NotificationService notificationService = new NotificationService(); notificationService.SendNotificationToClient(); } }
private static async Task <IDriveRecentCollectionPage> GetFilesAsync() { IDriveRecentCollectionPage driveRecentCollectionPage = null; try { graphClient = GraphServiceClientProvider.GetAuthenticatedClient(); driveRecentCollectionPage = await graphClient.Me.Drive.Recent().Request().GetAsync(); return(driveRecentCollectionPage); } catch (ServiceException e) { MessageBox.Show("We could not get the any Files: " + e.Error.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
private static async Task <Stream> GetMePhotoAsync() { Stream profilePhotoStream = null; try { graphClient = GraphServiceClientProvider.GetAuthenticatedClient(); profilePhotoStream = await graphClient.Me.Photo.Content.Request().GetAsync(); return(profilePhotoStream); } catch (ServiceException e) { MessageBox.Show("We could not get the current user photo: " + e.Error.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
private static async Task <User> GetMeAsync() { User currentUser = null; try { graphClient = GraphServiceClientProvider.GetAuthenticatedClient(); // Request to get the current logged in user object from Microsoft Graph currentUser = await graphClient.Me.Request().GetAsync(); return(currentUser); } catch (ServiceException e) { MessageBox.Show("We could not get the current user: "******"Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
private static async Task <IUserMessagesCollectionPage> GetMessagesAsync() { IUserMessagesCollectionPage messages = null; try { graphClient = GraphServiceClientProvider.GetAuthenticatedClient(); messages = await graphClient.Me .Messages .Request() .Select("From,Subject,IsRead,IsDraft,HasAttachments,CreatedDateTime") .GetAsync(); return(messages); } catch (ServiceException e) { MessageBox.Show("We could not get the any messages: " + e.Error.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
public async Task <ActionResult> DeleteSubscription(string subscriptionId) { try { SubscriptionStore.DeleteSubscriptionInfo(); GraphServiceClient graphClient = GraphServiceClientProvider.GetAuthenticatedClient(); await graphClient.Subscriptions[subscriptionId].Request().DeleteAsync(); return(RedirectToAction("SignOut", "Account")); } catch (ServiceException se) { if (se.Error.Code == "AuthenticationFailure") { return(new EmptyResult()); } return(RedirectToAction("Index", "Error", new { message = $"Error in {Request.RawUrl}: {se.Error.Code} {se.Error.Message}" })); } }