コード例 #1
0
        private void MainMenuProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (request.IsBackward)
            {
                usersDailyTasks[userId] = null;
            }
            else if (!usersDailyTasks.ContainsKey(userId) || usersDailyTasks[userId] == null)
            {
                var datesCount   = GetUsersDateTimesCount(userId);
                var dates        = GetUsersDateTimes(userId, datesCount);
                var tasksOnDates = dates
                                   .Select(d =>
                {
                    var tasksCount = GetUsersTasksCountByDate(userId, d);
                    return(Tuple.Create(d, GetAllTasksOnDate(userId, d, tasksCount)));
                })
                                   .ToList();
                usersDailyTasks[userId]     = new DailyTasks(tasksOnDates);
                mainMenu.Options[0].Options = usersDailyTasks[userId]
                                              .GetAllDateTimes()
                                              .Select(d => new ThemeListsMenu()
                {
                    MenuName      = d.ToString(),
                    MenuType      = MenuType.Menu,
                    Options       = null,
                    PreviousMenu  = mainMenu.Options[0],
                    ProcessData   = ChooseTaskNumberProcessData,
                    RequestFormat = ExpectingRequestFormat.Number
                })
                                              .ToList();
            }
        }
コード例 #2
0
        private void AddNewTaskProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (!request.IsBackward)
            {
                if (request.Number == 2)
                {
                    var dates = usersDailyTasks[userId].GetAllDateTimes();
                    currentMenu.Options[1].Options = dates
                                                     .Select(d => new ThemeListsMenu()
                    {
                        MenuName = d.ToString(),
                        MenuType = MenuType.RequestForData,
                        Options  = new List <ThemeListsMenu> {
                            currentMenu
                        },
                        PreviousMenu  = currentMenu,
                        ProcessData   = AddNewTaskOnExistingDateProcessName,
                        RequestFormat = ExpectingRequestFormat.Text
                    })
                                                     .ToList();
                }
            }
        }
コード例 #3
0
        private void AddNewTaskOnExistingDateProcessName(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (!request.IsBackward)
            {
                if (usersDailyTasks[userId].GetAllTasksOnDate(usersCurrentDateTimes[userId]).Contains(request.Text))
                {
                    currentMenu.MenuName = "Такое дело уже существует, введите другое";
                    currentMenu.Options  = new List <ThemeListsMenu>()
                    {
                        currentMenu
                    };
                }
                else
                {
                    currentMenu.MenuName = "Введите название дела";
                    currentMenu.Options  = new List <ThemeListsMenu>()
                    {
                        currentMenu.PreviousMenu
                    };
                    usersDailyTasks[userId].AddNewTask(usersCurrentDateTimes[userId], request.Text);
                    SaveTasksOnDate(userId, usersCurrentDateTimes[userId], usersDailyTasks[userId].GetAllTasksOnDate(usersCurrentDateTimes[userId]));
                }
            }
            else
            {
                currentMenu.MenuName = "Введите название дела";
                currentMenu.Options  = new List <ThemeListsMenu>()
                {
                    currentMenu.PreviousMenu
                };
            }
        }
コード例 #4
0
        private void AddNewDateProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (!request.IsBackward)
            {
                var inputedDay = request.DateTime;
                var newDate    = new DateTime(inputedDay.Year, inputedDay.Month, inputedDay.Day);
                if (usersDailyTasks[userId].GetAllDateTimes().Contains(newDate))
                {
                    currentMenu.MenuName = "Такая дата уже существует";
                    currentMenu.Options  = new List <ThemeListsMenu> {
                        currentMenu
                    };
                }
                else
                {
                    currentMenu.MenuName = "Добавить новую дату";
                    currentMenu.Options  = new List <ThemeListsMenu> {
                        currentMenu.PreviousMenu
                    };
                    usersDailyTasks[userId].AddNewDate(newDate);
                    SaveDates(userId, usersDailyTasks[userId].GetAllDateTimes());
                }
            }
            else
            {
                currentMenu.MenuName = "Добавить новую дату";
                currentMenu.Options  = new List <ThemeListsMenu> {
                    currentMenu.PreviousMenu
                };
            }
        }
コード例 #5
0
        public Answer GetAnswer(UiRequest request, State userState)
        {
            if (!alarmMenuForUser.ContainsKey(userState.UserId))
            {
                alarmForUser[userState.UserId]     = GetAlarm(userState);
                alarmMenuForUser[userState.UserId] = alarmMenu.Root;
                return(alarmMenuForUser[userState.UserId].GetAnswer(userState, alarmForUser[userState.UserId].GetAllAlarms()));
            }

            if (request.IsBackward)
            {
                alarmMenuForUser[userState.UserId] = alarmMenuForUser[userState.UserId].ToBack;
                if (alarmMenuForUser[userState.UserId] == null)
                {
                    RewriteAlarmItems(userState);
                    alarmMenuForUser.Remove(userState.UserId);
                    alarmForUser.Remove(userState.UserId);
                    return(Answer.BackWardAnswer(userState.UserId));
                }

                return(alarmMenuForUser[userState.UserId].GetAnswer(userState, alarmForUser[userState.UserId].GetAllAlarms()));
            }

            alarmMenuForUser[userState.UserId].Action_(userState, request);
            return(alarmMenuForUser[userState.UserId].GetAnswer(userState, alarmForUser[userState.UserId].GetAllAlarms()));


            throw new NotImplementedException();
        }
コード例 #6
0
 private void ChooseTaskNumberProcessData(ThemeListsMenu currentMenu, UiRequest request)
 {
     if (!request.IsBackward)
     {
         usersCurrentTaskNumbers[request.UserId] = request.Number;
     }
 }
コード例 #7
0
        private void AddNewTaskOnExistingDateProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (!request.IsBackward)
            {
                usersCurrentDateTimes[userId] = usersDailyTasks[userId].GetAllDateTimes()[request.Number - 1];
            }
        }
コード例 #8
0
 private void ListItemProcessData(ThemeListsMenu currentMenu, UiRequest request)
 {
     if (request.Number == 1)
     {
         usersLists[request.UserId].DeleteTask(usersCurrentListItems[request.UserId] - 1);
         SaveAllTasks(request.UserId, usersLists[request.UserId].GetAllTasksTuples().ToList());
         mainMenu.Options[0].Options[usersCurrentListItems[request.UserId] - 1].Options[0] = mainMenu;
     }
 }
コード例 #9
0
        private void TaskNameChangeProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (!request.IsBackward)
            {
                var date = usersCurrentDateTimes[userId];
                usersDailyTasks[userId].ChangeTaskName(date, usersCurrentTaskNumbers[userId] - 1, request.Text);
                SaveTasksOnDate(userId, date, usersDailyTasks[userId].GetAllTasksOnDate(date));
            }
        }
コード例 #10
0
        private void MenuProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (request.IsBackward)
            {
                if (usersLists.ContainsKey(userId))
                {
                    if (usersLists[userId] != null)
                    {
                        SaveAllTasks(userId, usersLists[userId].GetAllTasksTuples().ToList());
                    }
                }
                usersLists[userId] = null;
            }
            else
            {
                usersLists[userId] = new DeadlineTasks(GetAllTasks(userId).ToArray());
                var tasks        = usersLists[userId].GetAllTasks();
                var tasksOptions = tasks
                                   .Select(t => new ThemeListsMenu()
                {
                    MenuName = "Дело сделано!",
                    MenuType = MenuType.Menu,
                    Options  = new List <ThemeListsMenu>
                    {
                    },
                    PreviousMenu  = null,
                    ProcessData   = null,
                    RequestFormat = ExpectingRequestFormat.Number
                })
                                   .ToList();
                mainMenu.Options[0].Options = tasks
                                              .Select((task, i) =>
                {
                    var itemMenu = new ThemeListsMenu
                    {
                        MenuName = task,
                        MenuType = MenuType.Menu,
                        Options  = new List <ThemeListsMenu> {
                            tasksOptions[i]
                        },
                        PreviousMenu  = mainMenu.Options[0],
                        ProcessData   = ListItemProcessData,
                        RequestFormat = ExpectingRequestFormat.Number
                    };
                    tasksOptions[i].PreviousMenu = itemMenu;
                    return(itemMenu);
                })
                                              .ToList();
            }
        }
コード例 #11
0
 public ThemeListsMenu GetNextMenu(UiRequest request)
 {
     ProcessData?.Invoke(this, request);
     if (request.IsBackward)
     {
         return(PreviousMenu);
     }
     if (MenuType == MenuType.Menu)
     {
         return(Options[request.Number - 1]);
     }
     return(Options[0]);
 }
コード例 #12
0
        private void TaskNumberProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (!request.IsBackward)
            {
                if (request.Number == 1)
                {
                    var date = usersCurrentDateTimes[userId];
                    usersDailyTasks[userId].DeleteTask(date, usersCurrentTaskNumbers[userId] - 1);
                    SaveTasksOnDate(userId, date, usersDailyTasks[userId].GetAllTasksOnDate(date));
                    currentMenu.Options[0] = mainMenu;
                }
            }
        }
コード例 #13
0
        public Answer GetAnswer(UiRequest request, State userState)
        {
            var userId = userState.UserId;

            if (!usersMenu.ContainsKey(userId) || request.IsShowThisItem)
            {
                usersMenu[userId] = initialMenu;
                return(initialMenu.GetAnswer(userId));
            }
            usersMenu[userId] = usersMenu[userId].GetNextMenu(request);
            if (usersMenu[userId] == null)
            {
                return(Answer.BackWardAnswer(userId));
            }
            return(usersMenu[userId].GetAnswer(userId));
        }
コード例 #14
0
        public void ProcessMessage(int userId, DateTime date, string text, int number, bool isBackward, bool isShowThisItem)
        {
            var request = new UiRequest()
            {
                DateTime       = date,
                IsBackward     = isBackward,
                IsShowThisItem = isShowThisItem,
                Number         = number,
                Text           = text,
                UserId         = userId
            };
            var userState = GetUserState(request.UserId);
            var answer    = GetAnswer(request, userState);

            OnReplyRequest?.Invoke(answer.UserId, answer.Headline, answer.Items, answer.Format);
        }
コード例 #15
0
        private void ChooseTaskToWatchProcessData(ThemeListsMenu currentMenu, UiRequest request)
        {
            var userId = request.UserId;

            if (!request.IsBackward)
            {
                usersCurrentDateTimes[userId] = usersDailyTasks[userId].GetAllDateTimes()[request.Number - 1];

                currentMenu.Options[request.Number - 1].Options = usersDailyTasks[userId]
                                                                  .GetAllTasksOnDate(usersCurrentDateTimes[userId])
                                                                  .Select(t => new ThemeListsMenu()
                {
                    MenuName = t,
                    MenuType = MenuType.Menu,
                    Options  = new List <ThemeListsMenu>
                    {
                        new ThemeListsMenu()
                        {
                            MenuName = "Дело сделано!",
                        },
                        new ThemeListsMenu()
                        {
                            MenuName = "Изменить название дела",
                            MenuType = MenuType.RequestForData,
                            Options  = new List <ThemeListsMenu> {
                                mainMenu
                            },
                            PreviousMenu  = currentMenu,
                            ProcessData   = TaskNameChangeProcessData,
                            RequestFormat = ExpectingRequestFormat.Text
                        }
                    },
                    PreviousMenu  = currentMenu.Options[request.Number - 1],
                    ProcessData   = TaskNumberProcessData,
                    RequestFormat = ExpectingRequestFormat.Number
                })
                                                                  .ToList();
            }
        }
コード例 #16
0
        private Answer GetAnswer(UiRequest request, State userState)
        {
            if (userState.GlobalState == GlobalStates.Organizer)
            {
                if (request.IsShowThisItem || request.IsBackward)
                {
                    return(OrganizerAnswer(userState));
                }

                userState.GlobalState  = (GlobalStates)request.Number;
                request.IsShowThisItem = true;
            }

            var answer = items[userState.GlobalState].GetAnswer(request, userState);

            if (answer.IsBackward)
            {
                userState.GlobalState = GlobalStates.Organizer;
                answer = OrganizerAnswer(userState);
            }
            SaveUserState(userState);
            return(answer);
        }