Немного desktop чудес и async
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading;
|
||||
using JiraTimeBotForm.Configuration;
|
||||
using Mercurial;
|
||||
|
||||
@@ -17,28 +17,37 @@ namespace JiraTimeBotForm.TaskTime
|
||||
_log = log;
|
||||
}
|
||||
|
||||
public List<TaskTimeItem> GetTaskTimes(Settings settings, DateTime? date = null)
|
||||
public List<TaskTimeItem> GetTaskTimes(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (date == null)
|
||||
{
|
||||
date = DateTime.Now.Date;
|
||||
}
|
||||
date = date.Value.Date;
|
||||
var workTimeItems = new List<TaskTimeItem>();
|
||||
|
||||
date = date.GetValueOrDefault(DateTime.Now.Date);
|
||||
|
||||
var workTasks = new List<string>();
|
||||
|
||||
List<string> workTasks = new List<string>();
|
||||
foreach (var repoDirectory in Directory.GetDirectories(settings.RepositoryPath))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
//var project = new DirectoryInfo(repoDirectory).Name;
|
||||
if (!Directory.Exists(Path.Combine(repoDirectory, ".hg")))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Application.DoEvents();
|
||||
|
||||
var repo = new Repository(repoDirectory);
|
||||
var log = repo.Log(new LogCommand {Date = date, Users = { settings.MercurialAuthorEmail } });
|
||||
var logCommand = new LogCommand
|
||||
{
|
||||
Date = date,
|
||||
Users = { settings.MercurialAuthorEmail }
|
||||
};
|
||||
|
||||
var log = repo.Log(logCommand);
|
||||
|
||||
foreach (var changeset in log)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (!changeset.Branch.Contains("-"))
|
||||
{
|
||||
continue;
|
||||
@@ -51,23 +60,23 @@ namespace JiraTimeBotForm.TaskTime
|
||||
|
||||
workTasks.Add(changeset.Branch);
|
||||
_log?.Trace($" - Найден changeset: {changeset.Timestamp} - {changeset.Branch} - {changeset.AuthorEmailAddress}");
|
||||
Application.DoEvents();
|
||||
}
|
||||
}
|
||||
|
||||
//Нам нужно раскидать 480 минут в день.
|
||||
var workTimeItems = new List<TaskTimeItem>();
|
||||
foreach (var taskGroup in workTasks.GroupBy(f=>f))
|
||||
foreach (var taskGroup in workTasks.GroupBy(f => f))
|
||||
{
|
||||
var minutesPerTime = settings.MinuterPerWorkDay / workTasks.Count;
|
||||
var minutesForCurrentTaskGroup = minutesPerTime * taskGroup.Count();
|
||||
|
||||
workTimeItems.Add(new TaskTimeItem
|
||||
var taskTimeItem = new TaskTimeItem
|
||||
{
|
||||
Branch = taskGroup.Key,
|
||||
Time = TimeSpan.FromMinutes(minutesForCurrentTaskGroup),
|
||||
Commits = taskGroup.Count(),
|
||||
});
|
||||
};
|
||||
|
||||
workTimeItems.Add(taskTimeItem);
|
||||
}
|
||||
|
||||
return workTimeItems;
|
||||
|
||||
Reference in New Issue
Block a user