Еще рефакторинга

This commit is contained in:
Danil Kislov
2019-03-15 18:02:06 +03:00
parent d56094febb
commit e906e4edc3
8 changed files with 58 additions and 22 deletions
@@ -6,11 +6,11 @@ namespace JiraTimeBotForm.Configuration
{ {
public class PasswordEncryptionClass public class PasswordEncryptionClass
{ {
private byte[] GetEntropy(string EntropyString) private byte[] GetEntropy(string entropyString)
{ {
MD5 md5 = MD5.Create(); MD5 md5 = MD5.Create();
return md5.ComputeHash(Encoding.UTF8.GetBytes(EntropyString)); return md5.ComputeHash(Encoding.UTF8.GetBytes(entropyString));
} }
public string Encrypt(string username, string password, string address) public string Encrypt(string username, string password, string address)
+4 -2
View File
@@ -32,11 +32,13 @@ namespace JiraTimeBotForm.DI
_builder.RegisterType<MeetingProcessor>().AsSelf().As<ITasksProcessor>(); _builder.RegisterType<MeetingProcessor>().AsSelf().As<ITasksProcessor>();
_builder.RegisterAggregateService<ITasksProcessors>(); _builder.RegisterAggregateService<ITasksProcessors>();
_builder.Register(c => new JiraApi(c.Resolve<ILog>())).AsSelf().AsImplementedInterfaces(); _builder.RegisterType<JiraDescriptionSource>().AsSelf().As<IJiraDescriptionSource>();
_builder.RegisterType<JiraApi>().AsSelf().AsImplementedInterfaces();
_builder.Register(c => new Job(c.Resolve<IMercurialLog>(), c.Resolve<ITaskTimeDiscoverer>(), c.Resolve<ILog>())).AsSelf(); _builder.Register(c => new Job(c.Resolve<IMercurialLog>(), c.Resolve<ITaskTimeDiscoverer>(), c.Resolve<ILog>())).AsSelf();
return _builder.Build(); var container = _builder.Build();
return container;
} }
} }
} }
@@ -0,0 +1,11 @@
using System.Text;
using System.Threading.Tasks;
using JiraTimeBotForm.TaskTime;
namespace JiraTimeBotForm.JiraIntegration
{
public interface IJiraDescriptionSource
{
string GetDescription(TaskTimeItem item, bool addCommentsToWorklog);
}
}
+5 -13
View File
@@ -10,16 +10,12 @@ namespace JiraTimeBotForm.JiraIntegration
public class JiraApi public class JiraApi
{ {
private readonly ILog _log; private readonly ILog _log;
private readonly IJiraDescriptionSource _descriptionSource;
private readonly List<string> _dummyComments = new List<string> public JiraApi(ILog log, IJiraDescriptionSource descriptionSource)
{
"Написание кода", "написание кода", "программирование", "реализация задачи", "кодинг", "код + тесты",
"кодинг", "написание кода и тестов"
};
public JiraApi(ILog log = null)
{ {
_log = log; _log = log;
_descriptionSource = descriptionSource;
} }
public string GetTaskName(string branch, Settings settings) public string GetTaskName(string branch, Settings settings)
@@ -46,7 +42,7 @@ namespace JiraTimeBotForm.JiraIntegration
} }
date = date.Value.Date; date = date.Value.Date;
foreach (var taskTimeItem in taskTimeItems) foreach (TaskTimeItem taskTimeItem in taskTimeItems)
{ {
Issue issue = null; Issue issue = null;
try try
@@ -92,11 +88,7 @@ namespace JiraTimeBotForm.JiraIntegration
{ {
var timeSpentJira = $"{taskTimeItem.Time.TotalMinutes}m"; var timeSpentJira = $"{taskTimeItem.Time.TotalMinutes}m";
var comment = _dummyComments.OrderBy(f=>Guid.NewGuid()).FirstOrDefault(); var comment = _descriptionSource.GetDescription(taskTimeItem, addCommentsToWorklog);
if (addCommentsToWorklog)
{
comment = taskTimeItem.Description;
}
Worklog workLogToAdd = new Worklog(timeSpentJira, date.Value, comment); Worklog workLogToAdd = new Worklog(timeSpentJira, date.Value, comment);
if (!dummy) if (!dummy)
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JiraTimeBotForm.TaskTime;
namespace JiraTimeBotForm.JiraIntegration
{
public class JiraDescriptionSource : IJiraDescriptionSource
{
private readonly List<string> _dummyComments = new List<string>
{
"Написание кода", "написание кода", "программирование", "реализация задачи", "кодинг", "код + тесты",
"кодинг", "написание кода и тестов"
};
public string GetDescription(TaskTimeItem taskTimeItem, bool addCommentsToWorklog)
{
var comment = _dummyComments.OrderBy(f=>Guid.NewGuid()).FirstOrDefault();
if (addCommentsToWorklog)
{
comment = taskTimeItem.Description;
}
return comment;
}
}
}
+2
View File
@@ -82,6 +82,8 @@
<ItemGroup> <ItemGroup>
<Compile Include="DI\ContainerBuilder.cs" /> <Compile Include="DI\ContainerBuilder.cs" />
<Compile Include="Extensions\Extensions.cs" /> <Compile Include="Extensions\Extensions.cs" />
<Compile Include="JiraIntegration\IJiraDescriptionSource.cs" />
<Compile Include="JiraIntegration\JiraDescriptionSource.cs" />
<Compile Include="Job.cs" /> <Compile Include="Job.cs" />
<Compile Include="Logger.cs" /> <Compile Include="Logger.cs" />
<Compile Include="Configuration\Settings.cs" /> <Compile Include="Configuration\Settings.cs" />
@@ -56,11 +56,16 @@ namespace JiraTimeBotForm.TaskTime
workTimeItems.Add(taskTimeItem); workTimeItems.Add(taskTimeItem);
} }
if (!workTimeItems.Any())
{
return new List<TaskTimeItem>();
}
if (remainMinutes != 0) if (remainMinutes != 0)
{ {
_log.Trace($"Погрешность распределения времени: {remainMinutes}. Добавляю к первой задаче."); _log.Trace($"Погрешность распределения времени: {remainMinutes}. Добавляю к первой задаче.");
} }
//если переборщили или не достаточно добавили до 8 часов - скореектируем остаток в первой задаче (она самая трудозатратная). //если переборщили или не достаточно добавили до 8 часов - скореектируем остаток в первой задаче (она самая трудозатратная).
workTimeItems.First().Time += TimeSpan.FromMinutes(remainMinutes); workTimeItems.First().Time += TimeSpan.FromMinutes(remainMinutes);
-3
View File
@@ -7,11 +7,8 @@ using System.Windows.Forms;
using Autofac; using Autofac;
using JiraTimeBotForm.Configuration; using JiraTimeBotForm.Configuration;
using JiraTimeBotForm.DI; using JiraTimeBotForm.DI;
using JiraTimeBotForm.Mercurial;
using JiraTimeBotForm.TasksProcessors; using JiraTimeBotForm.TasksProcessors;
using JiraTimeBotForm.TaskTime;
using JiraTimeBotForm.UI; using JiraTimeBotForm.UI;
using Newtonsoft.Json;
// This is the code for your desktop app. // This is the code for your desktop app.
// Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.