Beispiel #1
0
        /// <summary>
        /// Prompts the user to chose an operation and routes it to the appropriate dialog
        /// </summary>
        /// <param name="context">IDialogContext</param>
        /// <returns>Task</returns>
        private async Task routeOperation(IDialogContext context)
        {
            //initialize a new operation on the context
            context.NewOperation();

            //check the entity type to determine the valid operations
            var entity = context.ConversationData.GetDialogEntity();
            List <QueryOperation> operations = QueryOperation.GetEntityResourceTypes(entity.entityType);

            //prepare the prompt
            string prompt = "What would like to lookup for you?";

            if (entity.entityType != EntityType.Me)
            {
                prompt = String.Format("What would like to lookup for {0}?", entity.text);
            }

            //add start over
            operations.Add(new Models.QueryOperation()
            {
                Text = "(Start over)", Type = Models.OperationType.StartOver
            });

            //let the user select an operation
            PromptDialog.Choice(context, async(IDialogContext opContext, IAwaitable <QueryOperation> opResult) =>
            {
                //check the operation selected and route appropriately
                var operation = await opResult;
                switch (operation.Type)
                {
                case OperationType.StartOver:
                    await this.MessageReceivedAsync(opContext, null);
                    break;

                case OperationType.Manager:
                    await opContext.Forward(new ResourceTypes.ManagerDialog(), OperationComplete, true, CancellationToken.None);
                    break;

                case OperationType.DirectReports:
                    await opContext.Forward(new ResourceTypes.DirectReportsDialog(), OperationComplete, true, CancellationToken.None);
                    break;

                case OperationType.Files:
                    await opContext.Forward(new ResourceTypes.FilesDialog(), OperationComplete, true, CancellationToken.None);
                    break;

                case OperationType.Members:
                    await opContext.Forward(new ResourceTypes.MembersDialog(), OperationComplete, true, CancellationToken.None);
                    break;

                case OperationType.Contacts:
                case OperationType.Conversations:
                case OperationType.Events:
                case OperationType.Groups:
                case OperationType.Mail:
                case OperationType.Notebooks:
                case OperationType.People:
                case OperationType.Photo:
                case OperationType.Plans:
                    await opContext.Forward(new PlanLookupDialog(), OnPlanLookupDialogResumeAsync, new Plan(), CancellationToken.None);
                    break;

                case OperationType.Tasks:
                    await opContext.Forward(new TasksDialog(), OperationComplete, true, CancellationToken.None);
                    break;

                case OperationType.TrendingAround:
                case OperationType.WorkingWith:
                    await opContext.PostAsync("Operation not yet implemented");
                    opContext.Wait(MessageReceivedAsync);
                    break;
                }
            }, operations, prompt);
        }