예제 #1
0
        private async Task GatherInfoStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var state   = dialogContext.Context.GetConversationState <BotState>();
            var context = dialogContext.Context;

            state.Name = (result as TextResult).Value;

            var teacher = new Student(context.Activity.From.Id,
                                      state.Name,
                                      Constants.TeachersGroupName,
                                      new List <string>(),
                                      new StudentChannelInfo
            {
                ToId           = context.Activity.From.Id,
                ToName         = context.Activity.From.Name,
                FromId         = context.Activity.Recipient.Id,
                FromName       = context.Activity.Recipient.Name,
                ServiceUrl     = context.Activity.ServiceUrl,
                ChannelId      = context.Activity.ChannelId,
                ConversationId = context.Activity.Conversation.Id
            },
                                      true);

            state.RegistrationComplete = true;
            state.Id = teacher.Id;

            await DatabaseProvider.AddStudent(teacher);

            await dialogContext.Context.SendActivity("Вы зарегистрированны.");

            await dialogContext.End();
        }
예제 #2
0
        private async Task GatherStudentInfo(DialogContext dialogContext)
        {
            var context = dialogContext.Context;
            var state = context.GetConversationState<BotState>();

            var studentChannelInfo = new StudentChannelInfo
            {
                ToId = context.Activity.Recipient.Id,
                ToName = context.Activity.Recipient.Name,
                ServiceUrl = context.Activity.ServiceUrl,
                ChannelId = context.Activity.ChannelId,
                ConversationId = context.Activity.Conversation.Id
            };

            var student = new Student(context.Activity.From.Id,
                                      state.Name,
                                      state.Group,
                                      state.ImgUrls,
                                      studentChannelInfo);
            var students = DatabaseProvider.GetAllStudents().ToArray();
            if (students.Length > 0 && students[0].Visits.Count > 0)
            {
                student.Visits = new List<VisitInfo>(students[0].Visits);
                foreach (var visit in student.Visits)
                {
                    visit.Visited = false;
                }
            }

            await DatabaseProvider.AddStudent(student);

            var imgUrlsSas = from imgUrl in state.ImgUrls
                             select StorageProvider.GetCorrectUri(new Uri(imgUrl)).ToString();
            await CognitiveServiceProvider.AddPerson(student.Id, imgUrlsSas);
            await CognitiveServiceProvider.TrainGroup();

            state.RegistrationComplete = true;
            state.Id = student.Id;
        }