예제 #1
0
        private async Task SaveIdea(IDialogContext context, IAwaitable <GraphServiceClient> result)
        {
            var planService = new PlannerService(await result);
            var ideaService = new IdeaService(await result);

            var plan = await planService.GetTeamPlanAsync(Team);

            if (plan == null)
            {
                throw new ApplicationException($"Could not found plan named '{Team.DisplayName}'");
            }

            var plannerTask = await ideaService.CreateAsync(plan.Id, idea.Title, idea.StartDate, idea.Owners.Select(i => i.Id).FirstOrDefault(), idea.Description);

            var plannerTaskUrl = ideaService.GetIdeaUrl(Team.Id, plan.Id, plannerTask.Id);

            try
            {
                var clientContext = await AuthenticationHelper.GetAppOnlySharePointClientContextAsync();

                var metricsService = new MetricsService(clientContext);
                await metricsService.CreateMetricIdeaAsync(metric.Id, plannerTask, Constants.IdeasPlan.Buckets.NewIdea, plannerTaskUrl);
            }
            catch (Exception ex)
            {
                await context.SayAsync("Failed to add item to MetricIdea list: " + ex.Message);
            }

            await context.SayAsync("Idea created.");

            context.Done(idea);
        }
예제 #2
0
        private async Task ListIdeasAsync(IDialogContext context, IAwaitable <GraphServiceClient> result)
        {
            var plannerService = new PlannerService(await result);
            var ideaService    = new IdeaService(await result);

            var plan = await plannerService.GetTeamPlanAsync(Team);

            var ideas = await ideaService.GetAsync(Team, plan.Id, status, from);

            var summary = ideas.Length > 0
                ? $"Getting {ideas.Length} {(ideas.Length > 1 ? "ideas" : "idea")} from Microsoft Planner, Please wait..."
                : "No idea was found.";
            await context.SayAsync(summary);

            foreach (var bucket in Constants.IdeasPlan.Buckets.All)
            {
                var bucketIdeas = ideas.Where(i => i.Bucket == bucket).ToArray();
                if (!bucketIdeas.Any())
                {
                    continue;
                }

                if (string.IsNullOrEmpty(status))
                {
                    await context.SayAsync($"{bucket} ({bucketIdeas.Length + " " + (bucket.Length > 1 ? "ideas" : "idea")})");
                }

                int pageSize  = 6;
                int pageCount = (bucketIdeas.Length + pageSize - 1) / pageSize;
                for (int page = 0; page < pageCount; page++)
                {
                    var message = context.MakeMessage();
                    message.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                    var pageIdeas = bucketIdeas.Skip(pageSize * page).Take(pageSize).ToArray();
                    foreach (var idea in pageIdeas)
                    {
                        await ideaService.GetDetailsAsync(idea);

                        var url    = ideaService.GetIdeaUrl(Team.Id, plan.Id, idea.Id);
                        var owners = $"Owners: {idea.Owners.Select(i => i.DisplayName).Join(", ")}";
                        var text   = $"Start Date<br/>{idea.StartDate?.DateTime.ToShortDateString()}";
                        if (idea.Description.IsNotNullAndEmpty())
                        {
                            text += $"<br/><br/>{idea.Description.Replace("\r\n", "<br/>").Replace("\n", "<br/>")}";
                        }
                        var viewAction = new CardAction(ActionTypes.OpenUrl, "View", value: url);
                        var heroCard   = new HeroCard(idea.Title, owners, text, buttons: new List <CardAction> {
                            viewAction
                        });
                        message.Attachments.Add(heroCard.ToAttachment());
                    }
                    await context.PostAsync(message);
                }
            }

            context.Done(ideas);
        }
        private async Task <DialogTurnResult> CreateIdeaPhase2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var tokenResponse = (TokenResponse)stepContext.Result;

            if (tokenResponse?.Token == null)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            var userProfile = await base.UserProfileAccessor.GetAsync(stepContext.Context);

            var team = userProfile.SelectedTeam;

            var createIdeaOptions = (CreateIdeaOptions)stepContext.Options;
            var planService       = new PlannerService(tokenResponse.Token);
            var plan = await planService.GetTeamPlanAsync(team.Id, team.DisplayName);

            if (plan == null)
            {
                var message = $"Failed to create the idea: could not find plan named '{team.DisplayName}'";
                await stepContext.Context.SendActivityAsync(message);
            }
            else
            {
                var description = $"Next Steps\r\n{createIdeaOptions.NextSteps}" +
                                  $"\r\n\r\nAligned to Metric\r\n{createIdeaOptions.Metric}";
                var ideaService = new IdeaService(tokenResponse.Token);
                try
                {
                    await ideaService.CreateAsync(plan.Id,
                                                  createIdeaOptions.Title,
                                                  new DateTimeOffset(createIdeaOptions.StartDate.Value, TimeSpan.Zero),
                                                  createIdeaOptions.Owner,
                                                  description
                                                  );

                    await stepContext.Context.SendActivityAsync("Idea created.");
                }
                catch (Exception ex)
                {
                    var message = $"Failed to create the idea: {ex.Message}";
                    await stepContext.Context.SendActivityAsync(message);
                }
            }
            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
예제 #4
0
        private async Task SaveIdea(IDialogContext context, IAwaitable <GraphServiceClient> result)
        {
            var planService = new PlannerService(await result);
            var ideaService = new IdeaService(await result);

            var plan = await planService.GetTeamPlanAsync(Team);

            if (plan == null)
            {
                throw new ApplicationException($"Could not found plan named '{Team.DisplayName}'");
            }

            var plannerTask = await ideaService.CreateAsync(plan.Id, idea.Title, idea.StartDate, idea.Owners.Select(i => i.Id).FirstOrDefault(), idea.Description);

            var plannerTaskUrl = ideaService.GetIdeaUrl(Team.Id, plan.Id, plannerTask.Id);

            try
            {
                var clientContext = await AuthenticationHelper.GetAppOnlySharePointClientContextAsync();

                var metricsService = new MetricsService(clientContext);
                await metricsService.CreateMetricIdeaAsync(metric.Id, plannerTask, Constants.IdeasPlan.Buckets.NewIdea, plannerTaskUrl);
            }
            catch (Exception ex)
            {
                await context.SayAsync("Failed to add item to MetricIdea list: " + ex.Message);
            }

            await context.SayAsync("Idea created.");

            //var viewAction = new CardAction(ActionTypes.OpenUrl, "View", value: plannerTaskUrl);
            //var heroCard = new HeroCard(
            //    text: "Idea created.",
            //    buttons: new List<CardAction> { viewAction });

            //var message = context.MakeMessage();
            //message.Attachments.Add(heroCard.ToAttachment());
            //await context.PostAsync(message);

            context.Done(idea);
        }
        private async Task <DialogTurnResult> ListIdeasPhase2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var tokenResponse = (TokenResponse)stepContext.Result;

            if (tokenResponse?.Token == null)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            var handler  = new JwtSecurityTokenHandler();
            var token    = handler.ReadJwtToken(tokenResponse.Token);
            var tenantId = token.Claims.FirstOrDefault(i => i.Type == "tid").Value;

            var userProfile = await UserProfileAccessor.GetAsync(stepContext.Context);

            var team = userProfile.SelectedTeam;

            var listIdeasOptions = (ListIdeasOptions)stepContext.Options;

            var plannerService = new PlannerService(tokenResponse.Token);
            var ideaService    = new IdeaService(tokenResponse.Token);

            var plan = await plannerService.GetTeamPlanAsync(team.Id, team.DisplayName);

            if (plan == null)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Could not found the plan."), cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            var bucketName = ideaService.GetBucketName(listIdeasOptions.Status);
            var ideas      = await ideaService.GetAsync(plan.Id, bucketName, listIdeasOptions.From);

            var summary = ideas.Length > 0
                ? $"Getting {ideas.Length} {(ideas.Length > 1 ? "ideas" : "idea")} from Microsoft Planner, please wait..."
                : "No idea was found.";
            await stepContext.Context.SendActivityAsync(summary);

            foreach (var bucket in IdeasPlan.Buckets.All)
            {
                var bucketIdeas = ideas.Where(i => StringComparer.InvariantCultureIgnoreCase.Equals(i.Bucket, bucket)).ToArray();
                if (!bucketIdeas.Any())
                {
                    continue;
                }

                if (string.IsNullOrEmpty(bucketName))
                {
                    await stepContext.Context.SendActivityAsync($"{bucket} ({bucketIdeas.Length + " " + (bucket.Length > 1 ? "ideas" : "idea")})");
                }

                int pageSize  = 6;
                int pageCount = (bucketIdeas.Length + pageSize - 1) / pageSize;
                for (int page = 0; page < pageCount; page++)
                {
                    var attachments = new List <Attachment>();
                    var pageIdeas   = bucketIdeas.Skip(pageSize * page).Take(pageSize).ToArray();
                    foreach (var idea in pageIdeas)
                    {
                        await ideaService.GetDetailsAsync(idea);

                        var url    = ideaService.GetIdeaUrl(tenantId, team.Id, plan.Id, idea.Id);
                        var owners = $"Owners: {string.Join(",", idea.Owners)}";
                        var text   = $"Start Date<br/>{idea.StartDate?.DateTime.ToShortDateString()}";
                        if (!string.IsNullOrEmpty(idea.Description))
                        {
                            text += $"<br/><br/>{idea.Description.Replace("\r\n", "<br/>").Replace("\n", "<br/>")}";
                        }
                        var viewAction = new CardAction(ActionTypes.OpenUrl, "View", value: url);
                        var heroCard   = new HeroCard(idea.Title, owners, text, buttons: new List <CardAction> {
                            viewAction
                        });
                        attachments.Add(heroCard.ToAttachment());
                    }

                    var message = MessageFactory.Carousel(attachments);
                    await stepContext.Context.SendActivityAsync(message);
                }
            }
            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }