Beispiel #1
0
        public async Task <ActiveTaskInfo> GetActiveWorkItems(VssConnection connection, string name, ILogger log)
        {
            var query = "Select [State], [Title] " +
                        "From WorkItems " +
                        "Where [Work Item Type] = 'Task' " +
                        $"And [Assigned To] = '{name}' " +
                        "And [State] = 'Active' " +
                        "Order By [State] Asc, [Changed Date] Desc";

            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 ActiveTaskInfo
                {
                    ActiveTaskCount = queryResult.WorkItems.Count(),
                    User            = name
                };
                log.LogInformation($"Query Result: HasActiveTask is '{result.HasActiveTasks}', ActiveTaskCount is '{result.ActiveTaskCount}'");

                return(result);
            }
            catch (Exception ex)
            {
                log.LogError($"Exception occured {ex}");
                throw;
            }
        }
        private async Task CreateAlertIfNeeded(Subscriber subscriber, ActiveTaskInfo activeTaskInfo, ILogger log)
        {
            var now = DateTime.UtcNow.TimeOfDay;

            if (now > subscriber.StartWorkingHoursUtc && now < subscriber.EndWorkingHoursUtc && IsWeekDay())
            {
                log.LogInformation($"It's working hours for {subscriber.Name}");
                if (!activeTaskInfo.HasActiveTasks)
                {
                    log.LogWarning($"No active tasks during working hours.");
                    await _notifier.NoActiveTasksDuringWorkingHours(subscriber);
                }
            }
            else
            {
                log.LogInformation($"It's not working hours for {subscriber.Name}");
                if (activeTaskInfo.HasActiveTasks)
                {
                    log.LogWarning($"There is an active task outside of working hours.");
                    await _notifier.ActiveTaskOutsideOfWorkingHours(subscriber);
                }
            }

            if (activeTaskInfo.ActiveTaskCount > 1)
            {
                log.LogWarning(
                    $"{activeTaskInfo.ActiveTaskCount} active tasks at the same time.");
                await _notifier.MoreThanSingleTaskIsActive(subscriber);
            }
        }