예제 #1
0
        public async Task <ActiveTasksInfo> GetActiveWorkItems(VssConnection connection, string name, ILogger log)
        {
            var query = _queryBuilder.GetActiveWorkItemsQuery(name);

            var wiql = new Wiql {
                Query = query
            };

            var client = connection.GetClient <WorkItemTrackingHttpClient>();

            try
            {
                log.LogInformation($"Executing query {query}");
                var queryResult = await client.QueryByWiqlAsync(wiql);

                var result = new ActiveTasksInfo
                {
                    ActiveTaskCount = queryResult.WorkItems.Count(),
                    User            = name,
                    TasksInfo       = queryResult.WorkItems.Select(i => new TaskInfo {
                        Id = i.Id
                    }).ToList()
                };
                log.LogInformation($"Query Result: HasActiveTask is '{result.HasActiveTasks}', ActiveTaskCount is '{result.ActiveTaskCount}'");

                return(result);
            }
            catch (Exception ex)
            {
                log.LogError($"Exception occured {ex}");
                throw;
            }
        }
예제 #2
0
        private List <string> GetTasksLinks(ActiveTasksInfo activeTasksInfo)
        {
            var tasks = activeTasksInfo.TasksInfo.Select(taskInfo =>
                                                         $"{GetSingleTaskLink(taskInfo)}{Environment.NewLine}")
                        .ToList();

            return(tasks);
        }
예제 #3
0
        public async Task ActiveTaskOutsideOfWorkingHours(Subscriber subscriber, ActiveTasksInfo activeTasksInfo)
        {
            var tasks = GetTasksLinks(activeTasksInfo);
            var text  = $"Active task outside of working hours. Doing some overtime, hah?{Environment.NewLine}" +
                        $"Tasks: {string.Join(Environment.NewLine, tasks)}";

            await _bot.SendTextMessageAsync(subscriber.TelegramId, text, ParseMode.Html);
        }
예제 #4
0
        private async Task CreateAlertIfNeeded(Subscriber subscriber, ActiveTasksInfo activeTasksInfo, ILogger log)
        {
            if (subscriber.SnoozeAlertsUntil.GetValueOrDefault(DateTime.MinValue) > DateTime.UtcNow)
            {
                log.LogInformation($"Alert checks snoozed for subscriber {subscriber.Email} til {subscriber.SnoozeAlertsUntil:G}");
                return;
            }

            var now = DateTime.UtcNow.TimeOfDay;

            if (now > subscriber.StartWorkingHoursUtc && now < subscriber.EndWorkingHoursUtc &&
                IsWeekDay())
            {
                log.LogInformation($"It's working hours for {subscriber.Email}");
                if (!activeTasksInfo.HasActiveTasks)
                {
                    log.LogInformation($"No active tasks during working hours.");
                    if (DateTime.UtcNow - subscriber.LastNoActiveTasksAlert >= PauseBetweenAlerts)
                    {
                        subscriber.LastNoActiveTasksAlert = DateTime.UtcNow;
                        await _notifier.NoActiveTasksDuringWorkingHours(subscriber);
                    }
                }
            }
            else
            {
                log.LogInformation($"It's not working hours for {subscriber.Email}");
                if (activeTasksInfo.HasActiveTasks &&
                    DateTime.UtcNow - subscriber.LastActiveTaskOutsideOfWorkingHoursAlert >= PauseBetweenAlerts)
                {
                    log.LogWarning($"There is an active task outside of working hours.");
                    subscriber.LastActiveTaskOutsideOfWorkingHoursAlert = DateTime.UtcNow;
                    await _notifier.ActiveTaskOutsideOfWorkingHours(subscriber, activeTasksInfo);
                }
            }

            if (activeTasksInfo.ActiveTaskCount > 1 &&
                DateTime.UtcNow - subscriber.LastMoreThanSingleTaskIsActiveAlert >= PauseBetweenAlerts)
            {
                log.LogInformation(
                    $"{activeTasksInfo.ActiveTaskCount} active tasks at the same time.");
                subscriber.LastMoreThanSingleTaskIsActiveAlert = DateTime.UtcNow;
                await _notifier.MoreThanSingleTaskIsActive(subscriber);
            }

            await _dbAccessor.AddOrUpdateSubscriber(subscriber);
        }
예제 #5
0
        public async Task ActiveTasks(Subscriber subscriber, ActiveTasksInfo activeTasksInfo)
        {
            var text = $"{subscriber.Email} has {activeTasksInfo.ActiveTaskCount} active task{(activeTasksInfo.ActiveTaskCount > 1 || activeTasksInfo.ActiveTaskCount == 0 ? "s" : string.Empty)}.{Environment.NewLine}";

            if (activeTasksInfo.ActiveTaskCount != 0)
            {
                var nextLine = false;
                foreach (var taskInfo in activeTasksInfo.TasksInfo)
                {
                    if (nextLine)
                    {
                        text += Environment.NewLine;
                    }
                    else
                    {
                        nextLine = true;
                    }
                    text += $"{GetSingleTaskLink(taskInfo)} (Active: {taskInfo.ActiveTime:0.##} hs)";
                }
            }

            await _bot.SendTextMessageAsync(subscriber.TelegramId, text, ParseMode.Html);
        }