//----------------------------------------------------------------//

        public async Task <OkObjectResult> CreateOrUpdate(String s_time, Int64 chatId, String name)
        {
            TimeSpan time;

            if (TimeSpan.TryParse(s_time, out time))
            {
                await _provider.GetService <ICaseService>().CreateDailyCaseAsync(time, name, chatId);

                return(Ok(CaseMessages.CaseAdded(ScheduleType.Daily, name, s_time)));
            }
            else
            {
                return(Ok(GeneralMessage.TIME_INCORRECT_FORMAT));
            }
        }
예제 #2
0
        public async Task CreateSpecificDayCase_Correct()
        {
            //arrange
            String s_dateTime = "22-01-2018 17:30";
            String nameCase   = "specific_case_test";
            String command    = String.Join(StringConstants.SPACE, TelegramCommandConstants.CREATE_SPECIFIC_DATE_CASE, nameCase, s_dateTime);

            Message expectedMessage = new Message()
            {
                Text = CaseMessages.CaseAdded(ScheduleType.ConcretyDate, nameCase, s_dateTime)
            };

            ServiceProviderMock.TryAddServiceMock <ICaseService>(new CaseServiceMock().SetupConcretyDateCase(String.Empty));

            await TestTelegramCommand(command, expectedMessage);
        }
        public async Task CreateDailyCase_Correct()
        {
            //arrange
            String time     = "18:30";
            String nameCase = "daily_case_test";
            String command  = String.Join(StringConstants.SPACE, TelegramCommandConstants.CREATE_DAILY_CASE, nameCase, time);

            //Response message
            Message expectedMessage = new Message()
            {
                Text = CaseMessages.CaseAdded(ScheduleType.Daily, nameCase, time)
            };

            //Mocks
            ServiceProviderMock.TryAddServiceMock <ICaseService>(new CaseServiceMock().SetupDailyCase(String.Empty));

            await TestTelegramCommand(command, expectedMessage);
        }
        //----------------------------------------------------------------//

        public override async Task <String> CreateCase(IList <String> commandArgs, Int64 chatId, TimeSpan timeSpan)
        {
            String errorMsg = String.Empty;

            String[]      s_days = commandArgs[3].Split(StringConstants.COMA_SPACE);
            List <String> notParsed;

            List <DayOfWeek> dayOfWeeks = s_days.AddRange((String str, out DayOfWeek day) => Enum.TryParse(str, out day), out notParsed);

            if (notParsed != null && notParsed.Count > 0)
            {
                errorMsg = CaseMessages.DayOfWeekNotParsed(notParsed);
            }
            else if (dayOfWeeks.Count > 0)
            {
                errorMsg = await _caseService.CreateWeeklyCaseAsync(dayOfWeeks, timeSpan, GetNameCase(commandArgs), chatId);
            }

            return(errorMsg);
        }
        public async Task CreateWeeklyCase_Correct()
        {
            //arrange
            String time     = "05:30";
            String nameCase = "week_case_test";

            String[] daysOfWeek = new String[] { nameof(DayOfWeek.Monday), nameof(DayOfWeek.Tuesday), nameof(DayOfWeek.Monday) };
            String   s_days     = String.Join(StringConstants.SPACE, daysOfWeek);
            String   command    = String.Join(StringConstants.SPACE, TelegramCommandConstants.CREATE_WEEKLY_CASE, nameCase, s_days, time);

            //Response message
            Message expectedMessage = new Message()
            {
                Text = CaseMessages.CaseAdded(ScheduleType.Weekly, nameCase, time)
            };

            //Mocks
            ServiceProviderMock.TryAddServiceMock <ICaseService>(new CaseServiceMock().SetupWeeklyCase(String.Empty));

            await TestTelegramCommand(command, expectedMessage);
        }
예제 #6
0
        //----------------------------------------------------------------//

        public async Task <ProcessResult> TryGenerateOrUpdateSequence(ISession session, String nameCase, String[] userNames)
        {
            String result = null;
            IEnumerable <UserCaseSequencer> sequencers = null;

            ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session);
            Case       @case     = await caseQuery.GetCaseByNameAsync(nameCase);

            if (@case != null)
            {
                IUserQuery userQuery            = QueryFactory.CreateQuery <IUserQuery>(session);
                IEnumerable <ControlUser> users = await userQuery.GetItemsAsync(userNames);

                if (users.Count() == userNames.Length)
                {
                    ICommand <UserCaseSequencer, UserCaseSequencerId> sequencerCommand = CommandFactory.CreateCommand <ICommand <UserCaseSequencer, UserCaseSequencerId> >(session);
                    ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session);
                    IQuery <UserCaseSequencer, UserCaseSequencerId> sequencerQuery = QueryFactory.CreateQuery <IQuery <UserCaseSequencer, UserCaseSequencerId> >(session);

                    sequencers = users.Select((u, i) => new UserCaseSequencer(@case, u, i));
                    sequencers = await sequencerCommand.SaveOrUpdateCollectionAsync(sequencerQuery, sequencers);

                    @case.NextUserId = sequencers.OrderBy(i => i.Sequence).First().Id.UserId;
                    await caseCommand.UpdateAsync(@case);
                }
                else
                {
                    result = UserMessages.UsersNotExist(GetNotExistUsers(users, userNames));
                }
            }
            else
            {
                result = CaseMessages.CaseNotExist(nameCase);
            }

            return(String.IsNullOrEmpty(result)
                   ? new ProcessResult(SequeceMessages.CaseSequenceGenerated(nameCase, sequencers), true)
                   : new ProcessResult(result, false));
        }
예제 #7
0
        //----------------------------------------------------------------//

        public async override Task <Message> ExecuteAsync(Message message)
        {
            Task   t_reinitNotifacationList = Task.CompletedTask;
            String resultMsg = null;

            String[] values = GetCommandGroups(message.Text);

            if (values.Length > 0)
            {
                String s_time   = GetTime(values);
                String nameCase = GetNameCase(values);

                if (TimeSpan.TryParse(s_time, out TimeSpan timeSpan))
                {
                    resultMsg = await CreateCase(values, message.Chat.Id, timeSpan);

                    if (String.IsNullOrEmpty(resultMsg))
                    {
                        resultMsg = CaseMessages.CaseAdded(scheduleType, nameCase, s_time);
                        t_reinitNotifacationList = Provider.GetService <INotificationService>().ReinitNotificationList();
                    }
                }
                else
                {
                    resultMsg = GeneralMessage.TIME_INCORRECT_FORMAT;
                }
            }
            else
            {
                resultMsg = GeneralMessage.COMMAND_NOT_MATCH_PATTERN;
            }

            Task <Message> t_sendMessage = BotClient.SendTextMessageAsync(message.Chat.Id, resultMsg, replyToMessageId: message.MessageId);

            return(await t_sendMessage);
        }