private async Task <HyperLink[]> GetOneNotePagesAsync(OneNoteService service, string notebookId, string propertyName, int incidentId) { var sectionId = await service.GetSectionIdAsync(notebookId, propertyName); if (string.IsNullOrEmpty(sectionId)) { return(new HyperLink[0]); } return(await service.GetPagesAsync(sectionId, incidentId)); }
public async Task ShowTaskTest() { var service = new OneNoteService(); var pageId = new Dictionary <string, string>(); await service.InitAsync(MockData.Token, pageId, mockClient); var taskList = await service.GetTasksAsync(MockData.ToDo); Assert.IsTrue(taskList != null && taskList.Count > 0); }
public async Task <ActionResult> AnnotateImages(int incidentId) { var sharePointToken = AuthenticationHelper.GetAccessTokenAsync(AppSettings.DemoSiteServiceResourceId); var oneNoteToken = AuthenticationHelper.GetOneNoteAccessTokenAsync(); var graphService = AuthenticationHelper.GetGraphServiceAsync(); var dashboardService = new Dashboard(await sharePointToken); var oneNoteService = new OneNoteService(AADAppSettings.OneNoteResourceUrl, await oneNoteToken); var pageUrl = await dashboardService.AnnotateImagesAsync(await graphService, oneNoteService, Server.MapPath("/"), incidentId); return(Redirect(pageUrl)); }
private async Task <OneNoteService.NoteBook> GetOrCreateNoteBook(OneNoteService service, string name) { var notebook = await service.GetNoteBookAsync(name); if (notebook == null) { try { notebook = await service.CreateNoteBookAsync(name); } catch { } } return(notebook); }
public async Task ShowTaskTest() { var service = new OneNoteService(); var pageId = new Dictionary <string, string>() { { "ToDo", "ToDo" }, { "Grocery", "Grocery" }, { "Shopping", "Shopping" } }; await service.InitAsync("test", pageId, mockClient); var taskList = await service.GetTasksAsync("ToDo"); Assert.IsTrue(taskList != null && taskList.Count > 0); }
public async Task MarkTaskTest() { var service = new OneNoteService(); var pageId = new Dictionary <string, string>(); await service.InitAsync(MockData.Token, pageId, mockClient); var taskList = await service.GetTasksAsync(MockData.ToDo); await service.MarkTasksCompletedAsync(MockData.ToDo, taskList.GetRange(0, 1)); var markedTaskList = await service.GetTasksAsync(MockData.ToDo); Assert.IsTrue(markedTaskList != null && markedTaskList.Count > 0 && markedTaskList[0].IsCompleted); }
public async Task AddTaskTests() { var service = new OneNoteService(); var pageId = new Dictionary <string, string>(); await service.InitAsync(MockData.Token, pageId, mockClient); var taskList = await service.GetTasksAsync(MockData.ToDo); await service.AddTaskAsync(MockData.ToDo, MockData.TaskContent); var addedTaskList = await service.GetTasksAsync(MockData.ToDo); Assert.IsTrue(taskList.Count + 1 == addedTaskList.Count); }
public async Task DeleteTaskTest() { var service = new OneNoteService(); var pageId = new Dictionary <string, string>(); await service.InitAsync(MockData.Token, pageId, mockClient); var taskList = await service.GetTasksAsync(MockData.ToDo); await service.DeleteTasksAsync(MockData.ToDo, taskList.GetRange(0, 1)); var deletedTaskList = await service.GetTasksAsync(MockData.ToDo); Assert.IsTrue(taskList.Count == deletedTaskList.Count + 1); Assert.IsFalse(deletedTaskList.Contains(taskList[0])); }
public async Task <ActionResult> OneNote() { var token = await AuthenticationHelper.GetOneNoteAccessTokenAsync(); var service = new OneNoteService(AADAppSettings.OneNoteResourceUrl, token); var notebookId = (await service.GetNoteBookAsync("Contoso Property Management")).Id; var sectionId = await service.GetSectionIdAsync(notebookId, "Au Residence"); var pages = await service.GetPagesAsync(sectionId, 4); var content = string.Join("<br />", pages.Select(i => string.Format(@"<a href='{0}' target='_blank'>{1}</a>", i.WebUrl, i.Title))); return(Content(content)); }
public async Task MarkTaskTest() { var service = new OneNoteService(); var pageId = new Dictionary <string, string>() { { "ToDo", "ToDo" }, { "Grocery", "Grocery" }, { "Shopping", "Shopping" } }; await service.InitAsync("test", pageId, mockClient); var taskList = await service.GetTasksAsync("ToDo"); await service.MarkTasksCompletedAsync("ToDo", taskList.GetRange(0, 1)); var markedTaskList = await service.GetTasksAsync("ToDo"); Assert.IsTrue(markedTaskList != null && markedTaskList.Count > 0 && markedTaskList[0].IsCompleted); }
public async Task DeleteTaskTest() { var service = new OneNoteService(); var pageId = new Dictionary <string, string>() { { "ToDo", "ToDo" }, { "Grocery", "Grocery" }, { "Shopping", "Shopping" } }; await service.InitAsync("test", pageId, mockClient); var taskList = await service.GetTasksAsync("ToDo"); await service.DeleteTasksAsync("ToDo", taskList.GetRange(0, 1)); var deletedTaskList = await service.GetTasksAsync("ToDo"); Assert.IsTrue(taskList.Count == deletedTaskList.Count + 1); Assert.IsFalse(deletedTaskList.Contains(taskList[0])); }
public async Task <ActionResult> InspectionDetails(int id) { var outlookToken = await AuthenticationHelper.GetAccessTokenAsync(AADAppSettings.OutlookResourceId); var sharePointToken = AuthenticationHelper.GetAccessTokenAsync(AppSettings.DemoSiteServiceResourceId); var graphService = AuthenticationHelper.GetGraphServiceAsync(); var oneNoteToken = AuthenticationHelper.GetOneNoteAccessTokenAsync(); var oneNoteService = new OneNoteService(AADAppSettings.OneNoteResourceUrl, await oneNoteToken); Dashboard dashboardModel = new Dashboard(await sharePointToken); var model = await dashboardModel.GetDashboardInspectionDetailsViewModelAsync(await graphService, oneNoteService, id, User.Identity.Name); if (model == null) { return(HttpNotFound()); } return(View(model)); }
public async Task <string> AnnotateImagesAsync(GraphServiceClient graphService, string siteRootDirectory, int incidentId) { var getIncident = GetIncidentByIdAsync(incidentId); var incidentVideos = GetVideosAsync(AppSettings.VideoPortalIncidentsChannelName, incidentId); var incident = await getIncident; var property = incident.sl_propertyID; var unifiedGroupFetcher = graphService.Groups[property.sl_group]; var unifiedGroup = await unifiedGroupFetcher.Request().GetAsync(); var notebookName = unifiedGroup.DisplayName + " Notebook"; var notebook = await OneNoteService.GetNoteBookByNameAsync(unifiedGroup, notebookName); var section = await OneNoteService.GetOrCreateSectionIdAsync(notebook.sectionsUrl, property.Title); var inspectionPhotos = GetInspectionOrRepairPhotosAsync("Room Inspection Photos", incident.sl_inspectionIDId.Value, incident.sl_roomID.Id); var pageUrl = await OneNoteService.CreatePageForIncidentAsync(graphService, siteRootDirectory, unifiedGroup, section, incident, await inspectionPhotos, await incidentVideos); return(pageUrl); }
public async Task <DashboardInspectionDetailsViewModel> GetDashboardInspectionDetailsViewModelAsync(GraphServiceClient graphService, int incidentId, string CurrentUser) { Graph.User[] getRepairPeople = null; Task <RepairPhoto[]> getRepairPhotos = null; var videos = await GetVideosAsync(AppSettings.VideoPortalIncidentsChannelName, incidentId); var incident = await GetIncidentByIdAsync(incidentId); if (incident.sl_inspectionIDId == null) { return(null); } var property = incident.sl_propertyID; var propertyImgUrl = GetPropertyPhotoAsync(property.Id); var inspectionID = incident.sl_inspectionIDId.Value; var inspection = await GetInspectionByIdAsync(inspectionID); var getInspectionPhotos = await GetInspectionPhotosAsync(inspectionID); var incidentStatus = incident.sl_status; if (incidentStatus == "Pending Assignment") { getRepairPeople = await graphService.GetGroupMembersAsync("Repair People"); } if (incidentStatus == "Repair Pending Approval" || incidentStatus == "Repair Approved") { getRepairPhotos = GetRepairPhotosAsync(incidentId); } var unifiedGroupFetcher = graphService.Groups[property.sl_group]; var unifiedGroup = await unifiedGroupFetcher.Request().GetAsync(); var groupFiles = await GetGroupFilesAsync(unifiedGroupFetcher); var groupConversations = await GetConversationsAsync(unifiedGroupFetcher, unifiedGroup.Mail); var propertyExcelWorkbook = await ExcelService.GetPropertyExcelWorkbooksAsync(property.sl_group); var notebook = await OneNoteService.GetNoteBookByNameAsync(unifiedGroup, unifiedGroup.DisplayName + " Notebook"); var oneNotePages = (notebook != null) ? await Services.OneNoteService.GetOneNotePagesAsync(graphService, unifiedGroup) : await Task.FromResult(new HyperLink[0]); var groupMembers = await graphService.GetGroupMembersAsync(unifiedGroupFetcher); var plan = await PlanService.GetPlanAsync(unifiedGroup); List <O365Task> tasks = new List <O365Task>(); if (plan != null) { tasks = await GetO365TasksAsync(graphService, plan); } var recentEarliestDateTime = new DateTimeOffset(DateTime.UtcNow).AddDays(-7); var recentDocuments = groupFiles .Where(i => i.dateTimeLastModified > recentEarliestDateTime) .ToList(); property.propertyImgUrl = await propertyImgUrl; var isCurrentUserDispatcher = CurrentUser == AppSettings.DispatcherEmail; var bannotateImage = true; if (notebook == null || string.IsNullOrEmpty(notebook.oneNoteWebUrl) || oneNotePages.Where(x => x.Title.ToString().Equals(string.Format("Incident[{0}]", incidentId))).Count() > 0) { bannotateImage = false; } var viewModel = new DashboardInspectionDetailsViewModel { viewName = IncidentStatusViewMappings[incidentStatus], PropertyDetail = property, incidentId = incidentId, incident = incident, UnifiedGroupNickName = unifiedGroup.MailNickname, UnifiedGroupId = unifiedGroup.Id, UnifiedGroupEmail = unifiedGroup.Mail, inspection = inspection, videos = videos, files = groupFiles .Select(i => HyperLink.Create(i.name, i.webUrl, i.id)) .ToArray(), recentDocuments = recentDocuments .Select(i => HyperLink.Create(i.name, i.webUrl, i.id)) .ToArray(), members = groupMembers, roomInspectionPhotos = getInspectionPhotos, inspectionComment = await GetInspectionCommentAsync(inspectionID, incident.sl_roomID.Id), tasks = tasks.ToArray(), repairPeople = getRepairPeople != null ? getRepairPeople : new Graph.User[0], repairPhotos = getRepairPhotos != null ? await getRepairPhotos : new RepairPhoto[0], DispatcherMails = isCurrentUserDispatcher ? await GetMailsForDispatcherAsync(graphService, CurrentUser) : new HyperLink[0], oneNotePages = oneNotePages, oneNoteUrl = notebook != null ? notebook.oneNoteWebUrl: "", conversations = groupConversations, PlanId = plan != null ? plan.id : string.Empty, PropertyExcelWorkbook = propertyExcelWorkbook, bAnnotateImage = bannotateImage }; return(viewModel); }
public async Task <DashboardInspectionDetailsViewModel> GetDashboardInspectionDetailsViewModelAsync(Graph.GraphService graphService, OneNoteService oneNoteService, int incidentId, string CurrentUser) { Task <Graph.IUser[]> getRepairPeople = null; Task <RepairPhoto[]> getRepairPhotos = null; var videos = GetVideosAsync(AppSettings.VideoPortalIncidentsChannelName, incidentId); var notebook = GetOrCreateNoteBook(oneNoteService, notebookName); var incident = await GetIncidentByIdAsync(incidentId); if (incident.sl_inspectionIDId == null) { return(null); } var inspectionID = incident.sl_inspectionIDId.Value; var inspection = GetInspectionByIdAsync(inspectionID); var getInspectionPhotos = GetInspectionPhotosAsync(inspectionID); var incidentStatus = incident.sl_status; if (incidentStatus == "Pending Assignment") { getRepairPeople = graphService.GetGroupMembersAsync("Repair People"); } if (incidentStatus == "Repair Pending Approval" || incidentStatus == "Repair Approved") { getRepairPhotos = GetRepairPhotosAsync(incidentId); } var property = incident.sl_propertyID; var propertyImgUrl = GetPropertyPhotoAsync(property.Id); var pages = (await notebook) != null ? GetOneNotePagesAsync(oneNoteService, (await notebook).Id, property.Title, incidentId) : Task.FromResult(new HyperLink[0]); var unifiedGroupFetcher = graphService.groups.GetById(property.sl_group); var unifiedGroup = unifiedGroupFetcher.ExecuteAsync(); var groupFiles = GetGroupFilesAsync(unifiedGroupFetcher, (await unifiedGroup).mailNickname); var groupConversations = GetConversationsAsync(unifiedGroupFetcher, (await unifiedGroup).mail); // Repair people are included in property group. // Before we get members of a group, we must make sure that repair people have been retrieved. // Otherwise, we'll get an error: // The context is already tracking a different entity with the same resource Uri. if (getRepairPeople != null) { await getRepairPeople; } var groupMembers = graphService.GetGroupMembersAsync(unifiedGroupFetcher); var recentEarliestDateTime = new DateTimeOffset(DateTime.UtcNow).AddDays(-7); var recentDocuments = (await groupFiles) .Where(i => i.dateTimeLastModified > recentEarliestDateTime) .ToList(); property.propertyImgUrl = await propertyImgUrl; var isCurrentUserDispatcher = CurrentUser == AppSettings.DispatcherEmail; var viewModel = new DashboardInspectionDetailsViewModel { viewName = IncidentStatusViewMappings[incidentStatus], PropertyDetail = property, incidentId = incidentId, incident = incident, UnifiedGroupNickName = (await unifiedGroup).mailNickname, UnifiedGroupId = (await unifiedGroup).objectId, UnifiedGroupEmail = (await unifiedGroup).mail, inspection = await inspection, videos = await videos, files = (await groupFiles) .Select(i => HyperLink.Create(i.name, i.webUrl)) .ToArray(), recentDocuments = recentDocuments .Select(i => HyperLink.Create(i.name, i.webUrl)) .ToArray(), members = await groupMembers, roomInspectionPhotos = await getInspectionPhotos, inspectionComment = await GetInspectionCommentAsync(inspectionID, incident.sl_roomID.Id), //tasks = await GetTaskHyperLinksAsync(unifiedGroup) repairPeople = getRepairPeople != null ? await getRepairPeople : new Graph.IUser[0], repairPhotos = getRepairPhotos != null ? await getRepairPhotos : new RepairPhoto[0], DispatcherMails = isCurrentUserDispatcher ? await GetMailsForDispatcherAsync(graphService, CurrentUser) : new HyperLink[0], oneNoteUrl = (await notebook) != null ? (await notebook).Url : "", oneNotePages = await pages, conversations = await groupConversations }; return(viewModel); }
//public async Task CreateTaskAsync(Graph.GraphService graphService, CreateTaskViewModel model) //{ // var inspection = await GetInspectionById(model.InspectionId); // var property = inspection.sl_propertyID; // var unifiedGroupFetcher = graphService.groups.GetById(property.sl_group); // var unifiedGroup = await unifiedGroupFetcher.ExecuteAsync(); // var task = new Graph.Task // { // title = model.Title, // percentComplete = 0, // startDate = inspection.sl_datetime, // dueDate = inspection.sl_datetime, // // TODO: description = model.Description, // }; // await unifiedGroupFetcher.tasks.AddTaskAsync(task); //} public async Task <string> AnnotateImagesAsync(Graph.GraphService graphService, OneNoteService oneNoteService, string siteRootDirectory, int incidentId) { var getIncident = GetIncidentByIdAsync(incidentId); var incidentVideos = GetVideosAsync(AppSettings.VideoPortalIncidentsChannelName, incidentId); var incident = await getIncident; var property = incident.sl_propertyID; var sectionId = await GetOrCreateNoteBook(oneNoteService, notebookName) .ContinueWith(async task => { var _notebookId = task.Result.Id; var _sectionId = await oneNoteService.GetSectionIdAsync(_notebookId, property.Title); if (_sectionId == null) { _sectionId = await oneNoteService.CreateSectionAsync(_notebookId, property.Title); } return(_sectionId); }); var inspectionPhotos = GetInspectionOrRepairPhotosAsync("Room Inspection Photos", incident.sl_inspectionIDId.Value, incident.sl_roomID.Id); var pageUrl = await oneNoteService.CreatePageForIncidentAsync(siteRootDirectory, await sectionId, incident, await inspectionPhotos, await incidentVideos); return(pageUrl); }