Beispiel #1
0
        public async Task <PlannerTask> CreateAsync(string planId, string title, DateTimeOffset?startDate, string ownerId, string description)
        {
            var newIdearBucket = await plannerService.GetNewIdeaBucketAsync(planId);

            if (newIdearBucket == null)
            {
                throw new ApplicationException("Could not found New Idea bucket.");
            }

            var plannerTask = new PlannerTask
            {
                PlanId        = planId,
                BucketId      = newIdearBucket.Id,
                Title         = title,
                StartDateTime = startDate,
                Assignments   = new PlannerAssignments()
            };

            plannerTask.Assignments.AddAssignee(ownerId);
            plannerTask = await graphServiceClient.Planner.Tasks.Request().AddAsync(plannerTask);

            //await Task.Delay(3000);

            var planerTaskDetails = new PlannerTaskDetails {
                Description = description
            };
            var plannerTaskRequestBuilder = graphServiceClient.Planner.Tasks[plannerTask.Id];

            PlannerTaskDetails details = null;

            int count = 1;

            while (true)
            {
                try
                {
                    details = await plannerTaskRequestBuilder.Details.Request().GetAsync();

                    break;
                }
                catch (Exception ex)
                {
                    if (count < 6)
                    {
                        await Task.Delay(1000);
                    }
                    else
                    {
                        throw new Exception("Task created. But failed to create its details. ", ex);
                    }
                }
                count++;
            }

            details = await plannerTaskRequestBuilder.Details
                      .Request(new[] { new HeaderOption("If-Match", details.GetEtag()) })
                      .UpdateAsync(planerTaskDetails);

            return(plannerTask);
        }
Beispiel #2
0
        private static async Task UpdateTaskDetails(GraphServiceClient graphClient, string groupId, PlannerTask task, DriveItem attachFile)
        {
            PlannerTaskDetails taskDetails = await GetPlannerTaskDetailsAsync(graphClient, task);

            taskDetails.References = new PlannerExternalReferences();
            taskDetails.References.AddReference(attachFile.WebUrl, attachFile.Name);

            taskDetails.Checklist = new PlannerChecklistItems();
            taskDetails.Checklist.AddChecklistItem("Meet Visitor in Lobby");

            //not useing anymore
            //                .Header("Prefer", "return=represendation")

            PlannerTaskDetails updatedTask = await graphClient.Planner.Tasks[task.Id].Details.Request()
                                             .Header("If-Match", taskDetails.GetEtag())
                                             .Header("Prefer", "return=represendation")
                                             .UpdateAsync(taskDetails);
        }
        public async Async.Task PlannerTaskDetailsUpdate()
        {
            var group = await CreateGroup();

            this.testGroup = group;
            var plannerPlan = await CreatePlan(group); // You may need to add a Delay in this since there is some latency.

            PlannerTask taskToCreate = new PlannerTask();

            taskToCreate.PlanId = plannerPlan.Id;
            taskToCreate.Title  = "New task title";

            PlannerTask createdTask = await graphClient.Planner.Tasks.Request().AddAsync(taskToCreate);

            PlannerTaskDetails taskDetails = await graphClient.Planner.Tasks[createdTask.Id].Details.Request().GetAsync();

            PlannerTaskDetails taskDetailsToUpdate = new PlannerTaskDetails();

            taskDetailsToUpdate.Checklist = new PlannerChecklistItems();
            string checklistItemId1 = taskDetailsToUpdate.Checklist.AddChecklistItem("Do something");
            string checklistItemId2 = taskDetailsToUpdate.Checklist.AddChecklistItem("Do something else");

            taskDetailsToUpdate.References = new PlannerExternalReferences();
            taskDetailsToUpdate.References.AddReference("http://developer.microsoft.com", "Developer resources");

            taskDetailsToUpdate.PreviewType = PlannerPreviewType.Checklist;
            taskDetailsToUpdate.Description = "Description of the task";

            string             etag = taskDetails.GetEtag();
            PlannerTaskDetails updatedTaskDetails = await graphClient.Planner.Tasks[createdTask.Id].Details.Request().Header("If-Match", etag).Header("Prefer", "return=representation").UpdateAsync(taskDetailsToUpdate);

            Assert.AreEqual("Description of the task", updatedTaskDetails.Description);
            Assert.AreEqual(PlannerPreviewType.Checklist, updatedTaskDetails.PreviewType);
            Assert.AreEqual(2, updatedTaskDetails.Checklist.Count());
            Assert.AreEqual("Do something", updatedTaskDetails.Checklist[checklistItemId1]?.Title);
            Assert.AreEqual("Do something else", updatedTaskDetails.Checklist[checklistItemId2]?.Title);
            Assert.AreEqual(1, updatedTaskDetails.References.Count());
            Assert.AreEqual("Developer resources", updatedTaskDetails.References["http://developer.microsoft.com"]?.Alias);
        }