コード例 #1
0
        //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, OneNoteServiceFactory oneNoteServiceFactory, 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.GetById(property.sl_group);
            var unifiedGroup        = unifiedGroupFetcher.ExecuteAsync();

            var oneNoteService = await oneNoteServiceFactory.CreateOneNoteServiceForUnifiedGroup(await unifiedGroup);

            var notebookName = (await unifiedGroup).displayName + " Notebook";
            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);
        }
コード例 #2
0
        private async Task <String[]> GetPropertyOwnersAsync(Graph.GraphService graphService)
        {
            var resturl        = "/_api/lists/GetByTitle('Properties')/Items?$select=sl_owner";
            var responseString = await RestHelper.GetDemoSiteJsonAsync(resturl, _token);

            var properties = JObject.Parse(responseString)["d"]["results"].ToObject <Property[]>();

            var users = await graphService.GetAllUsersAsync(properties.Select(i => i.sl_owner));

            return(users.Select(i => i.mail).ToArray());
        }
コード例 #3
0
        private async Task <RepairPeople> GetRepairPeopleByEmailAddressAsync(string userPrincipalName)
        {
            Graph.GraphService graphService = await AuthenticationHelper.GetGraphServiceAsync();

            Microsoft.Graph.IUser repairPeople = await GraphServiceExtension.GetFirstUserAsync(graphService, i => i.mail == userPrincipalName);

            if (repairPeople == null)
            {
                return(null);
            }

            return(new RepairPeople()
            {
                Title = repairPeople.displayName,
                sl_emailaddress = repairPeople.userPrincipalName
            });
        }
コード例 #4
0
        private async Task <HyperLink[]> GetMailsForDispatcherAsync(Graph.GraphService graphService, string CurrentUser)
        {
            List <HyperLink> result = new List <HyperLink>();

            var messages = await(await graphService.users.GetById(CurrentUser).Messages.ExecuteAsync()).GetAllAsnyc();

            var propertyOwners = await GetPropertyOwnersAsync(graphService);

            foreach (Graph.IMessage message in messages)
            {
                if (message.ToRecipients.Any(i => propertyOwners.Contains(i.EmailAddress.Address)))
                {
                    result.Add(new HyperLink
                    {
                        Title  = message.Subject,
                        WebUrl = message.WebLink
                    });
                    break;
                }
            }

            return(result.ToArray());
        }
コード例 #5
0
        public async Task <DashboardInspectionDetailsViewModel> GetDashboardInspectionDetailsViewModelAsync(Graph.GraphService graphService, OneNoteServiceFactory oneNoteServiceFactory, int incidentId, string CurrentUser)
        {
            Task <Graph.IUser[]> getRepairPeople = null;
            Task <RepairPhoto[]> getRepairPhotos = null;

            var videos = 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          = 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 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);

            var notebookName   = (await unifiedGroup).displayName + " Notebook";;
            var oneNoteService = oneNoteServiceFactory.CreateOneNoteServiceForUnifiedGroup(await unifiedGroup);
            var notebook       = GetOrCreateNoteBook(await oneNoteService, notebookName);
            var pages          = (await notebook) != null
                ? GetOneNotePagesAsync(await oneNoteService, (await notebook).Id, property.Title, incidentId)
                : Task.FromResult(new HyperLink[0]);

            // 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);
        }
コード例 #6
0
        public async Task <bool> UploadFileAsync(Graph.GraphService graphService, UploadFileModel model)
        {
            var graphToken    = AuthenticationHelper.GetGraphAccessTokenAsync();
            var propertyGroup = await graphService.GetGroupByDisplayNameAsync(model.PropertyTitle);

            if (propertyGroup == null)
            {
                return(false);
            }

            string id         = string.Empty;
            string requestUri = string.Format("{0}{1}/groups/{2}/files",
                                              AADAppSettings.GraphResourceUrl,
                                              AppSettings.DemoSiteCollectionOwner.Split('@')[1], propertyGroup.objectId);

            //create placeholder
            HttpWebRequest reqCreatePlaceholder = (HttpWebRequest)HttpWebRequest.Create(requestUri);

            reqCreatePlaceholder.Method = "POST";
            reqCreatePlaceholder.Headers.Add("Authorization", await graphToken);
            reqCreatePlaceholder.ContentType = "application/json";
            string content = string.Format("{{type:'File',name:'{0}'}}", model.File.FileName);

            byte[] contentBody = System.Text.ASCIIEncoding.UTF8.GetBytes(content);

            using (Stream dataStream = reqCreatePlaceholder.GetRequestStream())
            {
                dataStream.Write(contentBody, 0, contentBody.Length);
            }

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)reqCreatePlaceholder.GetResponse())
                {
                    if (response.StatusCode == HttpStatusCode.Created)
                    {
                        string responseString = (new StreamReader(response.GetResponseStream())).ReadToEnd();
                        id = Newtonsoft.Json.Linq.JObject.Parse(responseString)["id"].ToString();
                    }
                }
            }
            catch
            {
                throw;
            }

            if (string.IsNullOrEmpty(id))
            {
                return(false);
            }

            //upload file
            HttpWebRequest req_uploadFile = (HttpWebRequest)HttpWebRequest.Create(string.Format("{0}/{1}/uploadContent", requestUri, id));

            req_uploadFile.Method = "POST";
            req_uploadFile.Headers.Add("Authorization", await graphToken);

            using (var dataStream = req_uploadFile.GetRequestStream())
                await model.File.InputStream.CopyToAsync(dataStream);

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)req_uploadFile.GetResponse())
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception el)
            {
                throw el;
            }


            return(false);
        }