public void Clear()
 {
     CurrentContactName = string.Empty;
     ContactsNameList.Clear();
     Contacts.Clear();
     ConfirmContactsNameIndex = 0;
     ShowContactsIndex        = 0;
     UnconfirmedContact.Clear();
     ConfirmedContact = new CustomizedPerson();
 }
 public void Clear()
 {
     User                      = new User();
     Title                     = null;
     Content                   = null;
     StartDate                 = new List <DateTime>();
     StartDateString           = null;
     StartTime                 = new List <DateTime>();
     StartTimeString           = null;
     StartDateTime             = null;
     EndDate                   = new List <DateTime>();
     EndTime                   = new List <DateTime>();
     EndDateTime               = null;
     OriginalStartDate         = new List <DateTime>();
     OriginalStartTime         = new List <DateTime>();
     OriginalEndDate           = new List <DateTime>();
     OriginalEndTime           = new List <DateTime>();
     NewStartDate              = new List <DateTime>();
     NewStartTime              = new List <DateTime>();
     NewEndDate                = new List <DateTime>();
     NewEndTime                = new List <DateTime>();
     OrderReference            = null;
     Location                  = null;
     Attendees                 = new List <EventModel.Attendee>();
     APIToken                  = null;
     Events                    = new List <EventModel>();
     NewStartDateTime          = null;
     EventSource               = EventSource.Other;
     AttendeesNameList         = new List <string>();
     CurrentAttendeeName       = string.Empty;
     ConfirmAttendeesNameIndex = 0;
     DialogName                = string.Empty;
     ShowAttendeesIndex        = 0;
     ShowEventIndex            = 0;
     SummaryEvents             = null;
     FocusEvents               = new List <EventModel>();
     Duration                  = 0;
     MoveTimeSpan              = 0;
     AskParameterContent       = string.Empty;
     RecurrencePattern         = string.Empty;
     CreateHasDetail           = false;
     NewEventStatus            = EventStatus.None;
     RecreateState             = null;
     FirstRetryInFindContact   = true;
     UnconfirmedPerson         = new List <CustomizedPerson>();
     ConfirmedPerson           = new CustomizedPerson();
     FirstEnterFindContact     = true;
     IsActionFromSummary       = false;
     ConfirmedMeeting          = new List <EventModel>();
     TotalConflictCount        = 0;
     FilterMeetingKeyWord      = null;
     UserSelectIndex           = -1;
 }
Example #3
0
 public CalendarSkillState()
 {
     User                      = new User();
     UserInfo                  = new UserInformation();
     Title                     = null;
     Content                   = null;
     StartDate                 = new List <DateTime>();
     StartDateString           = null;
     StartTime                 = new List <DateTime>();
     StartTimeString           = null;
     StartDateTime             = null;
     EndDate                   = new List <DateTime>();
     EndTime                   = new List <DateTime>();
     EndDateTime               = null;
     OriginalStartDate         = new List <DateTime>();
     OriginalStartTime         = new List <DateTime>();
     OriginalEndDate           = new List <DateTime>();
     OriginalEndTime           = new List <DateTime>();
     NewStartDate              = new List <DateTime>();
     NewStartTime              = new List <DateTime>();
     NewEndDate                = new List <DateTime>();
     NewEndTime                = new List <DateTime>();
     Location                  = null;
     Attendees                 = new List <EventModel.Attendee>();
     APIToken                  = null;
     Events                    = new List <EventModel>();
     NewStartDateTime          = null;
     EventSource               = EventSource.Other;
     AttendeesNameList         = new List <string>();
     CurrentAttendeeName       = string.Empty;
     ConfirmAttendeesNameIndex = 0;
     DialogName                = string.Empty;
     ShowAttendeesIndex        = 0;
     ShowEventIndex            = 0;
     SummaryEvents             = null;
     ReadOutEvents             = new List <EventModel>();
     Duration                  = 0;
     MoveTimeSpan              = 0;
     AskParameterContent       = string.Empty;
     RecurrencePattern         = string.Empty;
     CreateHasDetail           = false;
     RecreateState             = null;
     NewEventStatus            = EventStatus.None;
     FirstRetryInFindContact   = true;
     UnconfirmedPerson         = new List <CustomizedPerson>();
     ConfirmedPerson           = new CustomizedPerson();
     FirstEnterFindContact     = true;
     IsActionFromSummary       = false;
     ConfirmedMeeting          = new List <EventModel>();
 }
Example #4
0
        private async Task <PromptOptions> GenerateOptionsForEmail(WaterfallStepContext sc, CustomizedPerson confirmedPerson, ITurnContext context, bool isSinglePage = true)
        {
            var state = await Accessor.GetAsync(context);

            var pageIndex = state.ShowAttendeesIndex;
            var pageSize  = 3;
            var skip      = pageSize * pageIndex;
            var emailList = confirmedPerson.Emails.ToList();

            // Go back to the last page when reaching the end.
            if (skip >= emailList.Count && pageIndex > 0)
            {
                state.ShowAttendeesIndex--;
                pageIndex = state.ShowAttendeesIndex;
                skip      = pageSize * pageIndex;
                await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.AlreadyLastPage));
            }

            var options = new PromptOptions
            {
                Choices = new List <Choice>(),
                Prompt  = ResponseManager.GetResponse(FindContactResponses.ConfirmMultiplContactEmailSinglePage, new StringDictionary()
                {
                    { "UserName", confirmedPerson.DisplayName }
                })
            };

            if (!isSinglePage)
            {
                options.Prompt = ResponseManager.GetResponse(FindContactResponses.ConfirmMultiplContactEmailMultiPage, new StringDictionary()
                {
                    { "UserName", confirmedPerson.DisplayName }
                });
            }

            for (var i = 0; i < emailList.Count; i++)
            {
                var user        = confirmedPerson;
                var mailAddress = emailList[i].Address ?? user.UserPrincipalName;

                var choice = new Choice()
                {
                    Value    = $"{user.DisplayName}: {mailAddress}",
                    Synonyms = new List <string> {
                        (options.Choices.Count + 1).ToString(), user.DisplayName, user.DisplayName.ToLower(), mailAddress
                    },
                };
                var userName = user.UserPrincipalName?.Split("@").FirstOrDefault() ?? user.UserPrincipalName;
                if (!string.IsNullOrEmpty(userName))
                {
                    choice.Synonyms.Add(userName);
                    choice.Synonyms.Add(userName.ToLower());
                }

                if (skip <= 0)
                {
                    if (options.Choices.Count >= pageSize)
                    {
                        options.Prompt.Speak = SpeakHelper.ToSpeechSelectionDetailString(options, Common.ConfigData.GetInstance().MaxDisplaySize);
                        options.Prompt.Text += "\r\n" + GetSelectPromptEmailString(options, true);
                        options.RetryPrompt  = ResponseManager.GetResponse(CalendarSharedResponses.DidntUnderstandMessage);
                        return(options);
                    }

                    options.Choices.Add(choice);
                }
                else
                {
                    skip--;
                }
            }

            options.Prompt.Speak = SpeakHelper.ToSpeechSelectionDetailString(options, Common.ConfigData.GetInstance().MaxDisplaySize);
            options.Prompt.Text += "\r\n" + GetSelectPromptEmailString(options, true);
            options.RetryPrompt  = ResponseManager.GetResponse(CalendarSharedResponses.DidntUnderstandMessage);
            return(options);
        }
Example #5
0
        public async Task <DialogTurnResult> AfterUpdateUserName(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var userInput = sc.Result as string;
                var state     = await Accessor.GetAsync(sc.Context);

                var options = (UpdateUserNameDialogOptions)sc.Options;

                if (string.IsNullOrEmpty(userInput) && options.Reason != UpdateUserNameDialogOptions.UpdateReason.Initialize)
                {
                    await sc.Context.SendActivityAsync(ResponseManager.GetResponse(FindContactResponses.UserNotFoundAgain, new StringDictionary()
                    {
                        { "source", state.EventSource == EventSource.Microsoft ? "Outlook Calendar" : "Google Calendar" }
                    }));

                    return(await sc.EndDialogAsync());
                }

                string currentRecipientName = string.IsNullOrEmpty(userInput) ? state.CurrentAttendeeName : userInput;
                state.CurrentAttendeeName = currentRecipientName;

                // if it's an email, add to attendee and kepp the state.ConfirmedPerson null
                if (!string.IsNullOrEmpty(currentRecipientName) && IsEmail(currentRecipientName))
                {
                    var attendee = new EventModel.Attendee
                    {
                        DisplayName = currentRecipientName,
                        Address     = currentRecipientName
                    };
                    if (state.Attendees.All(r => r.Address != attendee.Address))
                    {
                        state.Attendees.Add(attendee);
                    }

                    state.CurrentAttendeeName = string.Empty;
                    state.ConfirmedPerson     = null;
                    return(await sc.EndDialogAsync());
                }

                List <CustomizedPerson> unionList = new List <CustomizedPerson>();

                if (CreateEventWhiteList.GetMyself(currentRecipientName))
                {
                    var me = await GetMe(sc);

                    unionList.Add(new CustomizedPerson(me));
                }
                else
                {
                    var originPersonList = await GetPeopleWorkWithAsync(sc, currentRecipientName);

                    var originContactList = await GetContactsAsync(sc, currentRecipientName);

                    originPersonList.AddRange(originContactList);

                    var originUserList = new List <PersonModel>();
                    try
                    {
                        originUserList = await GetUserAsync(sc, currentRecipientName);
                    }
                    catch
                    {
                        // do nothing when get user failed. because can not use token to ensure user use a work account.
                    }

                    (var personList, var userList) = FormatRecipientList(originPersonList, originUserList);

                    // people you work with has the distinct email address has the highest priority
                    if (personList.Count == 1 && personList.First().Emails.Any() && personList.First().Emails.First() != null)
                    {
                        unionList.Add(new CustomizedPerson(personList.First()));
                    }
                    else
                    {
                        personList.AddRange(userList);

                        foreach (var person in personList)
                        {
                            if (unionList.Find(p => p.DisplayName == person.DisplayName) == null)
                            {
                                var personWithSameName = personList.FindAll(p => p.DisplayName == person.DisplayName);
                                if (personWithSameName.Count == 1)
                                {
                                    unionList.Add(new CustomizedPerson(personWithSameName.First()));
                                }
                                else
                                {
                                    var unionPerson  = new CustomizedPerson(personWithSameName.FirstOrDefault());
                                    var curEmailList = new List <ScoredEmailAddress>();
                                    foreach (var sameNamePerson in personWithSameName)
                                    {
                                        sameNamePerson.Emails.ToList().ForEach(e =>
                                        {
                                            if (!string.IsNullOrEmpty(e))
                                            {
                                                curEmailList.Add(new ScoredEmailAddress {
                                                    Address = e
                                                });
                                            }
                                        });
                                    }

                                    unionPerson.Emails = curEmailList;
                                    unionList.Add(unionPerson);
                                }
                            }
                        }
                    }
                }

                unionList.RemoveAll(person => !person.Emails.Exists(email => email.Address != null));
                unionList.RemoveAll(person => !person.Emails.Any());

                state.UnconfirmedPerson = unionList;

                if (unionList.Count == 0)
                {
                    return(await sc.ReplaceDialogAsync(Actions.UpdateName, new UpdateUserNameDialogOptions(UpdateUserNameDialogOptions.UpdateReason.NotFound)));
                }
                else
                if (unionList.Count == 1)
                {
                    state.ConfirmedPerson = unionList.First();
                    return(await sc.EndDialogAsync());
                }
                else
                {
                    return(await sc.ReplaceDialogAsync(Actions.SelectPerson, sc.Options, cancellationToken));
                }
            }
            catch (SkillException skillEx)
            {
                await HandleDialogExceptions(sc, skillEx);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
        private async Task <DialogTurnResult> GetUserFromUserNameAsync(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await Accessor.GetAsync(sc.Context, cancellationToken : cancellationToken);

                var options = (FindContactDialogOptions)sc.Options;
                var currentRecipientName = state.MeetingInfo.ContactInfor.CurrentContactName;

                // if it's an email
                if (!string.IsNullOrEmpty(currentRecipientName) && IsEmail(currentRecipientName))
                {
                    state.MeetingInfo.ContactInfor.CurrentContactName = string.Empty;
                    state.MeetingInfo.ContactInfor.ConfirmedContact   = new CustomizedPerson()
                    {
                        DisplayName = currentRecipientName,
                        Emails      = new List <ScoredEmailAddress>()
                        {
                            new ScoredEmailAddress()
                            {
                                Address = currentRecipientName
                            }
                        }
                    };
                    return(await sc.EndDialogAsync(cancellationToken : cancellationToken));
                }

                var unionList = new List <CustomizedPerson>();

                if (CreateEventWhiteList.GetMyself(currentRecipientName))
                {
                    var me = await GetMeAsync(sc.Context, cancellationToken);

                    unionList.Add(new CustomizedPerson(me));
                }
                else if (!string.IsNullOrEmpty(currentRecipientName) && state.MeetingInfo.ContactInfor.RelatedEntityInfoDict.ContainsKey(currentRecipientName))
                {
                    string pronounType  = state.MeetingInfo.ContactInfor.RelatedEntityInfoDict[currentRecipientName].PronounType;
                    string relationship = state.MeetingInfo.ContactInfor.RelatedEntityInfoDict[currentRecipientName].RelationshipName;
                    var    personList   = new List <PersonModel>();
                    if (pronounType == PronounType.FirstPerson)
                    {
                        if (Regex.IsMatch(relationship, CalendarCommonStrings.Manager, RegexOptions.IgnoreCase))
                        {
                            var person = await GetMyManagerAsync(sc, cancellationToken);

                            if (person != null)
                            {
                                personList.Add(person);
                            }
                        }
                    }
                    else if (pronounType == PronounType.ThirdPerson && state.MeetingInfo.ContactInfor.Contacts.Count > 0)
                    {
                        int    count   = state.MeetingInfo.ContactInfor.Contacts.Count;
                        string prename = state.MeetingInfo.ContactInfor.Contacts[count - 1].UserPrincipalName;
                        if (Regex.IsMatch(relationship, CalendarCommonStrings.Manager, RegexOptions.IgnoreCase))
                        {
                            var person = await GetManagerAsync(sc, prename, cancellationToken);

                            if (person != null)
                            {
                                personList.Add(person);
                            }
                        }
                    }

                    foreach (var person in personList)
                    {
                        unionList.Add(new CustomizedPerson(person));
                    }
                }
                else
                {
                    var originPersonList = await GetPeopleWorkWithAsync(sc, currentRecipientName, cancellationToken);

                    var originContactList = await GetContactsAsync(sc, currentRecipientName, cancellationToken);

                    originPersonList.AddRange(originContactList);

                    var originUserList = new List <PersonModel>();
                    try
                    {
                        originUserList = await GetUserAsync(sc, currentRecipientName, cancellationToken);
                    }
                    catch
                    {
                        // do nothing when get user failed. because can not use token to ensure user use a work account.
                    }

                    (var personList, var userList) = FormatRecipientList(originPersonList, originUserList);

                    // people you work with has the distinct email address has the highest priority
                    if (personList.Count == 1 && personList.First().Emails.Any() && personList.First().Emails.First() != null)
                    {
                        unionList.Add(new CustomizedPerson(personList.First()));
                    }
                    else
                    {
                        personList.AddRange(userList);

                        foreach (var person in personList)
                        {
                            if (unionList.Find(p => p.DisplayName == person.DisplayName) == null)
                            {
                                var personWithSameName = personList.FindAll(p => p.DisplayName == person.DisplayName);
                                if (personWithSameName.Count == 1)
                                {
                                    unionList.Add(new CustomizedPerson(personWithSameName.First()));
                                }
                                else
                                {
                                    var unionPerson  = new CustomizedPerson(personWithSameName.FirstOrDefault());
                                    var curEmailList = new List <ScoredEmailAddress>();
                                    foreach (var sameNamePerson in personWithSameName)
                                    {
                                        sameNamePerson.Emails.ToList().ForEach(e =>
                                        {
                                            if (!string.IsNullOrEmpty(e))
                                            {
                                                curEmailList.Add(new ScoredEmailAddress {
                                                    Address = e
                                                });
                                            }
                                        });
                                    }

                                    unionPerson.Emails = curEmailList;
                                    unionList.Add(unionPerson);
                                }
                            }
                        }
                    }
                }

                unionList.RemoveAll(person => !person.Emails.Exists(email => email.Address != null));
                unionList.RemoveAll(person => !person.Emails.Any());

                state.MeetingInfo.ContactInfor.UnconfirmedContact = unionList;

                if (unionList.Count == 0)
                {
                    if (!(options.UpdateUserNameReason == FindContactDialogOptions.UpdateUserNameReasonType.Initialize))
                    {
                        options.FirstRetry = false;
                    }

                    options.UpdateUserNameReason = FindContactDialogOptions.UpdateUserNameReasonType.NotFound;
                    return(await sc.ReplaceDialogAsync(Actions.UpdateName, options, cancellationToken));
                }

                return(await sc.EndDialogAsync(cancellationToken : cancellationToken));
            }
            catch (SkillException skillEx)
            {
                await HandleDialogExceptionsAsync(sc, skillEx, cancellationToken);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptionsAsync(sc, ex, cancellationToken);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }
Example #7
0
        public async Task <DialogTurnResult> ConfirmName(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var state = await Accessor.GetAsync(sc.Context);

                if ((state.AttendeesNameList == null) || (state.AttendeesNameList.Count == 0))
                {
                    return(await sc.BeginDialogAsync(Actions.UpdateName, new UpdateUserNameDialogOptions(UpdateUserNameDialogOptions.UpdateReason.NotFound)));
                }

                var unionList = new List <CustomizedPerson>();
                var emailList = new List <string>();

                if (state.FirstEnterFindContact)
                {
                    state.FirstEnterFindContact = false;
                    foreach (var name in state.AttendeesNameList)
                    {
                        if (IsEmail(name))
                        {
                            emailList.Add(name);
                        }
                    }

                    if (state.AttendeesNameList.Count > 1)
                    {
                        var nameString = await GetReadyToSendNameListStringAsync(sc);

                        await sc.Context.SendActivityAsync(sc.Context.Activity.CreateReply(FindContactResponses.BeforeSendingMessage, null, new StringDictionary()
                        {
                            { "NameList", nameString }
                        }));
                    }
                }

                if (emailList.Count > 0)
                {
                    foreach (var email in emailList)
                    {
                        var attendee = new EventModel.Attendee
                        {
                            DisplayName = email,
                            Address     = email
                        };
                        if (state.Attendees.All(r => r.Address != attendee.Address))
                        {
                            state.Attendees.Add(attendee);
                        }
                    }

                    state.AttendeesNameList.RemoveAll(n => IsEmail(n));

                    if (state.AttendeesNameList.Count > 0)
                    {
                        return(await sc.ReplaceDialogAsync(Actions.ConfirmName, options : sc.Options, cancellationToken : cancellationToken));
                    }
                    else
                    {
                        return(await sc.EndDialogAsync());
                    }
                }

                if (state.ConfirmAttendeesNameIndex < state.AttendeesNameList.Count)
                {
                    var currentRecipientName = state.AttendeesNameList[state.ConfirmAttendeesNameIndex];

                    if (CreateEventWhiteList.GetMyself().Contains(currentRecipientName))
                    {
                        var me = await GetMe(sc);

                        unionList.Add(new CustomizedPerson(me));
                    }
                    else
                    {
                        var originPersonList = await GetPeopleWorkWithAsync(sc, currentRecipientName);

                        var originContactList = await GetContactsAsync(sc, currentRecipientName);

                        originPersonList.AddRange(originContactList);

                        var originUserList = new List <PersonModel>();
                        try
                        {
                            originUserList = await GetUserAsync(sc, currentRecipientName);
                        }
                        catch
                        {
                            // do nothing when get user failed. because can not use token to ensure user use a work account.
                        }

                        (var personList, var userList) = FormatRecipientList(originPersonList, originUserList);

                        // people you work with has the distinct email address has the highest priority
                        if (personList.Count == 1 && personList.First().Emails.Count == 1)
                        {
                            state.ConfirmedPerson = new CustomizedPerson(personList.First());
                            var highestPriorityPerson = new CustomizedPerson(personList.First());
                            return(await sc.ReplaceDialogAsync(Actions.ConfirmEmail, highestPriorityPerson));
                        }

                        personList.AddRange(userList);

                        foreach (var person in personList)
                        {
                            if (unionList.Find(p => p.DisplayName == person.DisplayName) == null)
                            {
                                var personWithSameName = personList.FindAll(p => p.DisplayName == person.DisplayName);
                                if (personWithSameName.Count == 1)
                                {
                                    unionList.Add(new CustomizedPerson(personWithSameName.First()));
                                }
                                else
                                {
                                    var unionPerson  = new CustomizedPerson(personWithSameName.FirstOrDefault());
                                    var curEmailList = new List <ScoredEmailAddress>();
                                    foreach (var sameNamePerson in personWithSameName)
                                    {
                                        sameNamePerson.Emails.ToList().ForEach(e => curEmailList.Add(new ScoredEmailAddress {
                                            Address = e
                                        }));
                                    }

                                    unionPerson.Emails = curEmailList;
                                    unionList.Add(unionPerson);
                                }
                            }
                        }
                    }
                }
                else
                {
                    return(await sc.EndDialogAsync());
                }

                state.UnconfirmedPerson = unionList;

                if (unionList.Count == 0)
                {
                    return(await sc.BeginDialogAsync(Actions.UpdateName, new UpdateUserNameDialogOptions(UpdateUserNameDialogOptions.UpdateReason.NotFound)));
                }
                else if (unionList.Count == 1)
                {
                    state.ConfirmedPerson = unionList.First();
                    return(await sc.ReplaceDialogAsync(Actions.ConfirmEmail, unionList.First()));
                }
                else
                {
                    var nameString = string.Empty;
                    if (unionList.Count <= ConfigData.GetInstance().MaxDisplaySize)
                    {
                        return(await sc.PromptAsync(Actions.Choice, await GenerateOptionsForName(sc, unionList, sc.Context, true)));
                    }
                    else
                    {
                        return(await sc.PromptAsync(Actions.Choice, await GenerateOptionsForName(sc, unionList, sc.Context, false)));
                    }
                }
            }
            catch (SkillException skillEx)
            {
                await HandleDialogExceptions(sc, skillEx);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
            catch (Exception ex)
            {
                await HandleDialogExceptions(sc, ex);

                return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs));
            }
        }