Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
290cf03c4b | ||
|
|
eff1bff375 | ||
|
|
d8a47b7cd3 | ||
|
|
95ce2792d9 | ||
|
|
325e7a30f5 | ||
|
|
9f95e918f7 | ||
|
|
813c59cccc | ||
|
|
5c01943fc6 | ||
|
|
abd89dd41e | ||
|
|
5979878e3f | ||
|
|
5fd2a74111 | ||
|
|
777ecf32e4 |
+1
-1
@@ -1 +1 @@
|
|||||||
1.0.80
|
1.0.87
|
||||||
|
|||||||
@@ -8,8 +8,10 @@
|
|||||||
# Настройки
|
# Настройки
|
||||||
- Режим работы:
|
- Режим работы:
|
||||||
- Mercurial - по коммитам в Mercurial, можем определять множественные коммиты в одну задачу (ветку) и пропорционально списывать время.
|
- Mercurial - по коммитам в Mercurial, можем определять множественные коммиты в одну задачу (ветку) и пропорционально списывать время.
|
||||||
|
- Git - по коммитам в Git.
|
||||||
- Jira - выполняем JQL и равномерно распределяем время.
|
- Jira - выполняем JQL и равномерно распределяем время.
|
||||||
- Путь до репо (Режим Mercurial) - путь до папки, в которую клонируются исходники.
|
- Путь до репо (Режим Mercurial, Git) - путь до папки, в которую клонируются исходники.
|
||||||
|
- Jira URL - адрес Jira-сервреа.
|
||||||
- Логин Jira - Логин в Jira (от этого пользователя будем выполнять запросы и вносить время).
|
- Логин Jira - Логин в Jira (от этого пользователя будем выполнять запросы и вносить время).
|
||||||
- Пароль Jira - шифруется через DPAPI.
|
- Пароль Jira - шифруется через DPAPI.
|
||||||
- Mercurial Name (Режим Mercurial) - обязателен к указанию для режима Mercurial - имя пользователя Mercurial, от которого проходят коммиты (именно UserName, не E-Mail).
|
- Mercurial Name (Режим Mercurial) - обязателен к указанию для режима Mercurial - имя пользователя Mercurial, от которого проходят коммиты (именно UserName, не E-Mail).
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<SolutionConfiguration>
|
||||||
|
<Settings>
|
||||||
|
<AllowParallelTestExecution>True</AllowParallelTestExecution>
|
||||||
|
<SolutionConfigured>True</SolutionConfigured>
|
||||||
|
</Settings>
|
||||||
|
</SolutionConfiguration>
|
||||||
@@ -14,6 +14,7 @@ namespace JiraTimeBot.Configuration
|
|||||||
|
|
||||||
public string JiraUrl { get; set; }
|
public string JiraUrl { get; set; }
|
||||||
public bool PullBeforeProcess { get; set; }
|
public bool PullBeforeProcess { get; set; }
|
||||||
|
public bool RemoveManuallyAddedWorklogs { get; set; }
|
||||||
public string RepositoryPath { get; set; }
|
public string RepositoryPath { get; set; }
|
||||||
public string MercurialAuthorEmail { get; set; }
|
public string MercurialAuthorEmail { get; set; }
|
||||||
public string JiraUserName { get; set; }
|
public string JiraUserName { get; set; }
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ namespace JiraTimeBot.DI
|
|||||||
|
|
||||||
_builder.RegisterType<JiraHistory>().AsSelf().As<IJiraHistory>();
|
_builder.RegisterType<JiraHistory>().AsSelf().As<IJiraHistory>();
|
||||||
|
|
||||||
_builder.Register(c => new Job(c.Resolve<IAllRepositoryProviders>(), c.Resolve<ITaskTimeCalculator>(), c.Resolve<ILog>())).AsSelf();
|
_builder.Register(c => new Job(c.Resolve<IAllRepositoryProviders>(), c.Resolve<ITaskTimeCalculator>(),
|
||||||
|
c.Resolve<IJiraApi>(), c.Resolve<ILog>())).AsSelf();
|
||||||
|
|
||||||
_builder.RegisterType<AutoStartUp>().AsSelf().AsImplementedInterfaces();
|
_builder.RegisterType<AutoStartUp>().AsSelf().AsImplementedInterfaces();
|
||||||
_builder.RegisterType<frmSettings>().AsSelf().AsImplementedInterfaces();
|
_builder.RegisterType<frmSettings>().AsSelf().AsImplementedInterfaces();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace JiraTimeBot.JiraIntegration
|
|||||||
string GetTaskName(string branch, Settings settings);
|
string GetTaskName(string branch, Settings settings);
|
||||||
List<Issue> GetWorkloggedIssuesByDate(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default);
|
List<Issue> GetWorkloggedIssuesByDate(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default);
|
||||||
void SetTodayWorklog(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, bool addCommentsToWorklog = false, CancellationToken cancellationToken = default);
|
void SetTodayWorklog(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, bool addCommentsToWorklog = false, CancellationToken cancellationToken = default);
|
||||||
|
List<Worklog> GetManuallyWorklogged(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JiraApi : IJiraApi
|
public class JiraApi : IJiraApi
|
||||||
@@ -77,6 +78,28 @@ namespace JiraTimeBot.JiraIntegration
|
|||||||
return GetIssuesByJQL(jql, settings, date, cancellationToken);
|
return GetIssuesByJQL(jql, settings, date, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Worklog> GetManuallyWorklogged(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var result = new List<Worklog>();
|
||||||
|
var alreadyLoggedToday = GetWorkloggedIssuesByDate(settings, date);
|
||||||
|
foreach (var issue in alreadyLoggedToday)
|
||||||
|
{
|
||||||
|
if (!taskTimeItems.Any(f => f.Branch.Equals(issue.Key.Value, StringComparison.InvariantCulture)))
|
||||||
|
{
|
||||||
|
var workLogs = issue.GetWorklogsAsync(cancellationToken).Result;
|
||||||
|
var userWorklogs = workLogs.Where(w =>
|
||||||
|
w.StartDate.GetValueOrDefault().Date == date && w.Author.Equals(settings.JiraUserName,
|
||||||
|
StringComparison.InvariantCultureIgnoreCase)).ToList();
|
||||||
|
foreach (var userWorklog in userWorklogs)
|
||||||
|
{
|
||||||
|
result.Add(userWorklog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private void RemoveWorklogsAddedByUser(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, CancellationToken cancellationToken = default)
|
private void RemoveWorklogsAddedByUser(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var alreadyLoggedToday = GetWorkloggedIssuesByDate(settings, date);
|
var alreadyLoggedToday = GetWorkloggedIssuesByDate(settings, date);
|
||||||
@@ -106,8 +129,11 @@ namespace JiraTimeBot.JiraIntegration
|
|||||||
date = date.GetValueOrDefault(DateTime.Now.Date).Date;
|
date = date.GetValueOrDefault(DateTime.Now.Date).Date;
|
||||||
var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword);
|
var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword);
|
||||||
|
|
||||||
//Удаляем добавленные вручную пользователем данные.
|
if (settings.RemoveManuallyAddedWorklogs)
|
||||||
RemoveWorklogsAddedByUser(taskTimeItems, settings, date, dummy, cancellationToken);
|
{
|
||||||
|
//Удаляем добавленные вручную пользователем данные.
|
||||||
|
RemoveWorklogsAddedByUser(taskTimeItems, settings, date, dummy, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (TaskTimeItem taskTimeItem in taskTimeItems)
|
foreach (TaskTimeItem taskTimeItem in taskTimeItems)
|
||||||
{
|
{
|
||||||
@@ -155,7 +181,7 @@ namespace JiraTimeBot.JiraIntegration
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
issue.DeleteWorklogAsync(workLog, WorklogStrategy.RetainRemainingEstimate, token: cancellationToken);
|
issue.DeleteWorklogAsync(workLog, WorklogStrategy.AutoAdjustRemainingEstimate, token: cancellationToken);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -181,7 +207,7 @@ namespace JiraTimeBot.JiraIntegration
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
workLogToAdd = issue.AddWorklogAsync(workLogToAdd, WorklogStrategy.RetainRemainingEstimate, token: cancellationToken).Result;
|
workLogToAdd = issue.AddWorklogAsync(workLogToAdd, WorklogStrategy.AutoAdjustRemainingEstimate, token: cancellationToken).Result;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -121,7 +121,7 @@
|
|||||||
<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" />
|
||||||
<Compile Include="JiraIntegration\JiraCommitEmulator.cs" />
|
<Compile Include="RepositoryProviders\JiraCommitEmulator.cs" />
|
||||||
<Compile Include="RepositoryProviders\GitLog.cs" />
|
<Compile Include="RepositoryProviders\GitLog.cs" />
|
||||||
<Compile Include="RepositoryProviders\Interfaces\IAllVcsProviders.cs" />
|
<Compile Include="RepositoryProviders\Interfaces\IAllVcsProviders.cs" />
|
||||||
<Compile Include="RepositoryProviders\Modifiers\ITechnicalInfoSkipper.cs" />
|
<Compile Include="RepositoryProviders\Modifiers\ITechnicalInfoSkipper.cs" />
|
||||||
|
|||||||
+25
-5
@@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using JiraTimeBot.JiraIntegration;
|
||||||
|
|
||||||
namespace JiraTimeBot
|
namespace JiraTimeBot
|
||||||
{
|
{
|
||||||
@@ -15,12 +16,14 @@ namespace JiraTimeBot
|
|||||||
{
|
{
|
||||||
private readonly IAllRepositoryProviders _mercurialProviders;
|
private readonly IAllRepositoryProviders _mercurialProviders;
|
||||||
private readonly ITaskTimeCalculator _taskTimeDiscoverer;
|
private readonly ITaskTimeCalculator _taskTimeDiscoverer;
|
||||||
|
private readonly IJiraApi _jiraApi;
|
||||||
private readonly ILog _log;
|
private readonly ILog _log;
|
||||||
|
|
||||||
public Job(IAllRepositoryProviders mercurialProviders, ITaskTimeCalculator taskTimeDiscoverer, ILog log)
|
public Job(IAllRepositoryProviders mercurialProviders, ITaskTimeCalculator taskTimeDiscoverer, IJiraApi jiraApi, ILog log)
|
||||||
{
|
{
|
||||||
_mercurialProviders = mercurialProviders;
|
_mercurialProviders = mercurialProviders;
|
||||||
_taskTimeDiscoverer = taskTimeDiscoverer;
|
_taskTimeDiscoverer = taskTimeDiscoverer;
|
||||||
|
_jiraApi = jiraApi;
|
||||||
_log = log;
|
_log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,22 +75,23 @@ namespace JiraTimeBot
|
|||||||
|
|
||||||
private bool SetTaskTimesForDateImpl(DateTime setForDate, DateTime realDate, Settings settings, ITasksProcessor tasksProcessor, bool dummyMode, CancellationToken cancellationToken)
|
private bool SetTaskTimesForDateImpl(DateTime setForDate, DateTime realDate, Settings settings, ITasksProcessor tasksProcessor, bool dummyMode, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
IRepositoryLog mercurial = _mercurialProviders.MercurialLog;
|
IRepositoryLog repository = _mercurialProviders.MercurialLog;
|
||||||
if (settings.WorkType == WorkType.JiraLogs)
|
if (settings.WorkType == WorkType.JiraLogs)
|
||||||
{
|
{
|
||||||
_log.Info("Использую Jira как источник информации.");
|
_log.Info("Использую Jira как источник информации.");
|
||||||
mercurial = _mercurialProviders.JiraCommitEmulator;
|
repository = _mercurialProviders.JiraCommitEmulator;
|
||||||
}
|
}
|
||||||
else if (settings.WorkType == WorkType.GitLogs)
|
else if (settings.WorkType == WorkType.GitLogs)
|
||||||
{
|
{
|
||||||
_log.Info("Использую Git как источник информации.");
|
_log.Info("Использую Git как источник информации.");
|
||||||
mercurial = _mercurialProviders.GitLog;
|
repository = _mercurialProviders.GitLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TaskTimeItem> taskTimes;
|
List<TaskTimeItem> taskTimes;
|
||||||
if (!(tasksProcessor is MeetingProcessor))
|
if (!(tasksProcessor is MeetingProcessor))
|
||||||
{
|
{
|
||||||
List<TaskTimeItem> commits = mercurial.GetRepositoryLog(settings, realDate, cancellationToken);
|
List<TaskTimeItem> commits = repository.GetRepositoryLog(settings, realDate, cancellationToken);
|
||||||
|
ModifyWorktimeByManualLogs(setForDate, settings, cancellationToken, commits);
|
||||||
taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken);
|
taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -111,5 +115,21 @@ namespace JiraTimeBot
|
|||||||
_log.Info("Готово.");
|
_log.Info("Готово.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ModifyWorktimeByManualLogs(DateTime setForDate, Settings settings, CancellationToken cancellationToken,
|
||||||
|
List<TaskTimeItem> commits)
|
||||||
|
{
|
||||||
|
if (settings.RemoveManuallyAddedWorklogs)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//если не удаляем добавленное вручную, то посчитаем сколько там надобавляли и отнимем от рабочего дня
|
||||||
|
var manuallyWorklogged = _jiraApi.GetManuallyWorklogged(commits, settings, setForDate, cancellationToken);
|
||||||
|
if (manuallyWorklogged.Any() && manuallyWorklogged.Sum(f => f.TimeSpentInSeconds) < settings.MinuterPerWorkDay)
|
||||||
|
{
|
||||||
|
settings.MinuterPerWorkDay = (int) (settings.MinuterPerWorkDay - manuallyWorklogged.Sum(f => f.TimeSpentInSeconds));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("JiraTimeBot")]
|
[assembly: AssemblyTitle("JiraTimeBot")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("JiraTimeBot")]
|
[assembly: AssemblyProduct("JiraTimeBot")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
// to COM components. If you need to access a type in this assembly from
|
// to COM components. If you need to access a type in this assembly from
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")]
|
[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")]
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
//
|
//
|
||||||
// Major Version
|
// Major Version
|
||||||
// Minor Version
|
// Minor Version
|
||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.0.80")]
|
[assembly: AssemblyVersion("1.0.87")]
|
||||||
[assembly: AssemblyFileVersion("1.0.80")]
|
[assembly: AssemblyFileVersion("1.0.87")]
|
||||||
[assembly: AssemblyInformationalVersion("1.0.80")]
|
[assembly: AssemblyInformationalVersion("1.0.87")]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace JiraTimeBot.RepositoryProviders
|
namespace JiraTimeBot.RepositoryProviders
|
||||||
@@ -35,7 +36,7 @@ namespace JiraTimeBot.RepositoryProviders
|
|||||||
date = date.GetValueOrDefault(DateTime.Now.Date);
|
date = date.GetValueOrDefault(DateTime.Now.Date);
|
||||||
|
|
||||||
var workTasks = new List<TaskTimeItem>();
|
var workTasks = new List<TaskTimeItem>();
|
||||||
foreach (var repoDirectory in Directory.GetDirectories(settings.RepositoryPath))
|
foreach (var repoDirectory in Directory.GetDirectories(settings.RepositoryPath, ".git", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
@@ -43,16 +44,15 @@ namespace JiraTimeBot.RepositoryProviders
|
|||||||
}
|
}
|
||||||
|
|
||||||
//var project = new DirectoryInfo(repoDirectory).Name;
|
//var project = new DirectoryInfo(repoDirectory).Name;
|
||||||
if (!Directory.Exists(Path.Combine(repoDirectory, ".git")))
|
var repoRootDirectory = repoDirectory.Replace(".git", "");
|
||||||
|
var directoryInfo = new DirectoryInfo(repoRootDirectory);
|
||||||
|
if (!directoryInfo.Exists)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var directoryInfo = new DirectoryInfo(repoDirectory);
|
|
||||||
|
|
||||||
|
|
||||||
var repo = new LibGit2Sharp.Repository(repoDirectory);
|
|
||||||
|
|
||||||
|
var repo = new LibGit2Sharp.Repository(repoRootDirectory);
|
||||||
if (settings.PullBeforeProcess)
|
if (settings.PullBeforeProcess)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -78,7 +78,11 @@ namespace JiraTimeBot.RepositoryProviders
|
|||||||
var reflog = repo.Refs.Log(repo.Refs.Head);
|
var reflog = repo.Refs.Log(repo.Refs.Head);
|
||||||
foreach (var reflogItem in reflog)
|
foreach (var reflogItem in reflog)
|
||||||
{
|
{
|
||||||
if (reflogItem.Committer.When.Date != date.Value.Date || reflogItem.Committer.Email != settings.MercurialAuthorEmail)
|
|
||||||
|
var dateMatch = date.Value.Date == reflogItem.Committer.When.Date;
|
||||||
|
var userMatch = reflogItem.Committer.Email.Equals(settings.MercurialAuthorEmail, StringComparison.CurrentCultureIgnoreCase);
|
||||||
|
|
||||||
|
if (!dateMatch || !userMatch)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -101,13 +105,20 @@ namespace JiraTimeBot.RepositoryProviders
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var branch = ListBranchesContaininingCommit(repo, commit.Sha).Select(f => f.FriendlyName)
|
var regex = new Regex("[a-zA-Z0-9]{1,4}-[0-9]{1,6}");
|
||||||
.Where(f => f.Contains("-") && !f.Contains("/")).Distinct().FirstOrDefault();
|
var branch = ListBranchesContaininingCommit(repo, commit.Sha)
|
||||||
|
.Select(f => f.FriendlyName)
|
||||||
|
.FirstOrDefault(f => regex.IsMatch(f));
|
||||||
|
|
||||||
|
|
||||||
|
//.Where(f => f.Contains("-") && !f.Contains("/")).Distinct().FirstOrDefault();
|
||||||
if (branch == null)
|
if (branch == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
branch = regex.Match(branch).Value;
|
||||||
|
|
||||||
var commitMessage = commit.MessageShort;
|
var commitMessage = commit.MessageShort;
|
||||||
commitMessage = _technicalInfoSkipper.StripBranchPrefix(branch, commitMessage);
|
commitMessage = _technicalInfoSkipper.StripBranchPrefix(branch, commitMessage);
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -1,14 +1,14 @@
|
|||||||
using Atlassian.Jira;
|
using System;
|
||||||
using JiraTimeBot.Configuration;
|
|
||||||
using JiraTimeBot.RepositoryProviders.Interfaces;
|
|
||||||
using JiraTimeBot.TaskTime.Objects;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Atlassian.Jira;
|
||||||
|
using JiraTimeBot.Configuration;
|
||||||
|
using JiraTimeBot.JiraIntegration;
|
||||||
|
using JiraTimeBot.RepositoryProviders.Interfaces;
|
||||||
|
using JiraTimeBot.TaskTime.Objects;
|
||||||
|
|
||||||
|
namespace JiraTimeBot.RepositoryProviders
|
||||||
namespace JiraTimeBot.JiraIntegration
|
|
||||||
{
|
{
|
||||||
public class JiraCommitEmulator : IRepositoryLog
|
public class JiraCommitEmulator : IRepositoryLog
|
||||||
{
|
{
|
||||||
@@ -7,8 +7,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.ServiceModel.Channels;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace JiraTimeBot.RepositoryProviders
|
namespace JiraTimeBot.RepositoryProviders
|
||||||
{
|
{
|
||||||
@@ -72,49 +74,58 @@ namespace JiraTimeBot.RepositoryProviders
|
|||||||
AdditionalArguments = { "--encoding=utf-8" },
|
AdditionalArguments = { "--encoding=utf-8" },
|
||||||
};
|
};
|
||||||
|
|
||||||
var log = repo.Log(logCommand);
|
try
|
||||||
|
|
||||||
foreach (var changeset in log)
|
|
||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
var log = repo.Log(logCommand);
|
||||||
{
|
|
||||||
return new List<TaskTimeItem>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var commitMessage = FixEncoding(changeset.CommitMessage);
|
foreach (var changeset in log)
|
||||||
if (_commitSkipper.IsNeedToSkip(changeset.Branch, commitMessage))
|
|
||||||
{
|
{
|
||||||
continue;
|
if (cancellationToken.IsCancellationRequested)
|
||||||
}
|
|
||||||
commitMessage = _technicalInfoSkipper.StripTechnicalInfo(commitMessage);
|
|
||||||
|
|
||||||
var task = new TaskTimeItem(changeset.Branch,
|
|
||||||
commitMessage,
|
|
||||||
directoryInfo.Name,
|
|
||||||
changeset.Timestamp,
|
|
||||||
TimeSpan.Zero,
|
|
||||||
1,
|
|
||||||
changeset.PathActions.Count,
|
|
||||||
"",
|
|
||||||
GetCommitType(changeset.Branch));
|
|
||||||
|
|
||||||
if (task.Type == CommitType.Release && task.Description.StartsWith("Merge with", StringComparison.CurrentCultureIgnoreCase))
|
|
||||||
{
|
|
||||||
var description = task.Description;
|
|
||||||
if (description.Contains("\n"))
|
|
||||||
{
|
{
|
||||||
description = description.Split('\n')[0];
|
return new List<TaskTimeItem>();
|
||||||
}
|
}
|
||||||
var branch = description.Replace("Merge with", "").Replace(" ", "");
|
|
||||||
var release = task.Branch.Replace("release", "");
|
|
||||||
|
|
||||||
task.Branch = branch;
|
var commitMessage = FixEncoding(changeset.CommitMessage);
|
||||||
task.Description = $"Подготовка и публикация версии {task.Project} {release}.";
|
if (_commitSkipper.IsNeedToSkip(changeset.Branch, commitMessage))
|
||||||
task.ReleaseVersion = release;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
commitMessage = _technicalInfoSkipper.StripTechnicalInfo(commitMessage);
|
||||||
|
|
||||||
|
var task = new TaskTimeItem(changeset.Branch,
|
||||||
|
commitMessage,
|
||||||
|
directoryInfo.Name,
|
||||||
|
changeset.Timestamp,
|
||||||
|
TimeSpan.Zero,
|
||||||
|
1,
|
||||||
|
changeset.PathActions.Count,
|
||||||
|
"",
|
||||||
|
GetCommitType(changeset.Branch));
|
||||||
|
|
||||||
|
if (task.Type == CommitType.Release && task.Description.StartsWith("Merge with", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
var description = task.Description;
|
||||||
|
if (description.Contains("\n"))
|
||||||
|
{
|
||||||
|
description = description.Split('\n')[0];
|
||||||
|
}
|
||||||
|
var branch = description.Replace("Merge with", "").Replace(" ", "");
|
||||||
|
var release = task.Branch.Replace("release", "");
|
||||||
|
|
||||||
|
task.Branch = branch;
|
||||||
|
task.Description = $"Подготовка и публикация версии {task.Project} {release}.";
|
||||||
|
task.ReleaseVersion = release;
|
||||||
|
}
|
||||||
|
workTasks.Add(task);
|
||||||
|
_log?.Trace($" - Найден changeset: {changeset.Timestamp} - {changeset.Branch} - {changeset.AuthorEmailAddress} - {commitMessage}");
|
||||||
}
|
}
|
||||||
workTasks.Add(task);
|
|
||||||
_log?.Trace($" - Найден changeset: {changeset.Timestamp} - {changeset.Branch} - {changeset.AuthorEmailAddress} - {commitMessage}");
|
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Oops something went wrong in repo {repoDirectory}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!workTasks.Any())
|
if (!workTasks.Any())
|
||||||
{
|
{
|
||||||
|
|||||||
Generated
+1
@@ -81,6 +81,7 @@
|
|||||||
this.tlpControls.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
|
this.tlpControls.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
|
||||||
this.tlpControls.Size = new System.Drawing.Size(759, 416);
|
this.tlpControls.Size = new System.Drawing.Size(759, 416);
|
||||||
this.tlpControls.TabIndex = 19;
|
this.tlpControls.TabIndex = 19;
|
||||||
|
this.tlpControls.Paint += new System.Windows.Forms.PaintEventHandler(this.tlpControls_Paint);
|
||||||
//
|
//
|
||||||
// txtLog
|
// txtLog
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace JiraTimeBot.UI
|
|||||||
this.WindowState = FormWindowState.Normal;
|
this.WindowState = FormWindowState.Normal;
|
||||||
_trayIcon.Hide();
|
_trayIcon.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
base.WndProc(ref message);
|
base.WndProc(ref message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,14 +66,16 @@ namespace JiraTimeBot.UI
|
|||||||
_log = _container.Resolve<ILog>();
|
_log = _container.Resolve<ILog>();
|
||||||
_tasksProcessors = _container.Resolve<IAllTasksProcessors>();
|
_tasksProcessors = _container.Resolve<IAllTasksProcessors>();
|
||||||
|
|
||||||
_controls = new Control[] { txtDummyMode, btnStart, btnMeeting, btnSettings, dteForDay, btnDoForDate };
|
_controls = new Control[] {txtDummyMode, btnStart, btnMeeting, btnSettings, dteForDay, btnDoForDate};
|
||||||
|
|
||||||
_settingsWindowShow = () =>
|
_settingsWindowShow = () =>
|
||||||
{
|
{
|
||||||
var frmSettings = new frmSettings(_container.Resolve<AutoStartUp>());
|
var frmSettings = new frmSettings(_container.Resolve<AutoStartUp>());
|
||||||
frmSettings.ShowDialog(this);
|
frmSettings.ShowDialog(this);
|
||||||
};
|
};
|
||||||
_settingsErrorReporter = msg => MessageBox.Show(msg, "Загрузка настроек", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ;
|
_settingsErrorReporter = msg =>
|
||||||
|
MessageBox.Show(msg, "Загрузка настроек", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
|
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
@@ -121,7 +124,8 @@ namespace JiraTimeBot.UI
|
|||||||
private void PrintStartMessage()
|
private void PrintStartMessage()
|
||||||
{
|
{
|
||||||
_settings = Settings.LoadAndCheck(_settingsWindowShow, _settingsErrorReporter);
|
_settings = Settings.LoadAndCheck(_settingsWindowShow, _settingsErrorReporter);
|
||||||
_log.Info($"Загружен бот для {_settings.JiraUserName}, Режим: {_settings.WorkType.ToString()}, работаем в {_settings.RepositoryPath}");
|
_log.Info(
|
||||||
|
$"Загружен бот для {_settings.JiraUserName}, Режим: {_settings.WorkType.ToString()}, работаем в {_settings.RepositoryPath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void btnStart_Click(object sender, EventArgs e)
|
private async void btnStart_Click(object sender, EventArgs e)
|
||||||
@@ -130,7 +134,8 @@ namespace JiraTimeBot.UI
|
|||||||
|
|
||||||
using (_tokenSource = GetTokenSource())
|
using (_tokenSource = GetTokenSource())
|
||||||
{
|
{
|
||||||
await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, _tokenSource.Token);
|
await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked,
|
||||||
|
_tokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
LockUnlock(true);
|
LockUnlock(true);
|
||||||
@@ -176,7 +181,8 @@ namespace JiraTimeBot.UI
|
|||||||
|
|
||||||
using (var tokenSource = GetTokenSource())
|
using (var tokenSource = GetTokenSource())
|
||||||
{
|
{
|
||||||
await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, tokenSource.Token);
|
await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked,
|
||||||
|
tokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
LockUnlock(true);
|
LockUnlock(true);
|
||||||
@@ -189,7 +195,8 @@ namespace JiraTimeBot.UI
|
|||||||
|
|
||||||
using (_tokenSource = GetTokenSource())
|
using (_tokenSource = GetTokenSource())
|
||||||
{
|
{
|
||||||
await _job.DoTheJob(settings, _tasksProcessors.MeetingProcessor, txtDummyMode.Checked, _tokenSource.Token);
|
await _job.DoTheJob(settings, _tasksProcessors.MeetingProcessor, txtDummyMode.Checked,
|
||||||
|
_tokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
LockUnlock(true);
|
LockUnlock(true);
|
||||||
@@ -244,11 +251,15 @@ namespace JiraTimeBot.UI
|
|||||||
|
|
||||||
using (_tokenSource = GetTokenSource())
|
using (_tokenSource = GetTokenSource())
|
||||||
{
|
{
|
||||||
await _job.SetTaskTimesForDate(dteForDay.Value, dteForDay.Value, settings, _tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, _tokenSource.Token);
|
await _job.SetTaskTimesForDate(dteForDay.Value, dteForDay.Value, settings,
|
||||||
|
_tasksProcessors.WorkLogTasksProcessor, txtDummyMode.Checked, _tokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
LockUnlock(true);
|
LockUnlock(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tlpControls_Paint(object sender, PaintEventArgs e)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+16
-3
@@ -56,6 +56,7 @@
|
|||||||
this.label4 = new System.Windows.Forms.Label();
|
this.label4 = new System.Windows.Forms.Label();
|
||||||
this.lblJiraUrl = new System.Windows.Forms.Label();
|
this.lblJiraUrl = new System.Windows.Forms.Label();
|
||||||
this.txtJiraUrl = new System.Windows.Forms.TextBox();
|
this.txtJiraUrl = new System.Windows.Forms.TextBox();
|
||||||
|
this.chkRemoveManuallyAddedWorklogs = new System.Windows.Forms.CheckBox();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// label5
|
// label5
|
||||||
@@ -154,7 +155,7 @@
|
|||||||
//
|
//
|
||||||
// btnSave
|
// btnSave
|
||||||
//
|
//
|
||||||
this.btnSave.Location = new System.Drawing.Point(86, 412);
|
this.btnSave.Location = new System.Drawing.Point(86, 432);
|
||||||
this.btnSave.Name = "btnSave";
|
this.btnSave.Name = "btnSave";
|
||||||
this.btnSave.Size = new System.Drawing.Size(75, 23);
|
this.btnSave.Size = new System.Drawing.Size(75, 23);
|
||||||
this.btnSave.TabIndex = 32;
|
this.btnSave.TabIndex = 32;
|
||||||
@@ -262,7 +263,7 @@
|
|||||||
// chkPullBeforeProcess
|
// chkPullBeforeProcess
|
||||||
//
|
//
|
||||||
this.chkPullBeforeProcess.AutoSize = true;
|
this.chkPullBeforeProcess.AutoSize = true;
|
||||||
this.chkPullBeforeProcess.Location = new System.Drawing.Point(65, 389);
|
this.chkPullBeforeProcess.Location = new System.Drawing.Point(65, 409);
|
||||||
this.chkPullBeforeProcess.Name = "chkPullBeforeProcess";
|
this.chkPullBeforeProcess.Name = "chkPullBeforeProcess";
|
||||||
this.chkPullBeforeProcess.Size = new System.Drawing.Size(83, 17);
|
this.chkPullBeforeProcess.Size = new System.Drawing.Size(83, 17);
|
||||||
this.chkPullBeforeProcess.TabIndex = 45;
|
this.chkPullBeforeProcess.TabIndex = 45;
|
||||||
@@ -303,11 +304,22 @@
|
|||||||
this.txtJiraUrl.Size = new System.Drawing.Size(100, 20);
|
this.txtJiraUrl.Size = new System.Drawing.Size(100, 20);
|
||||||
this.txtJiraUrl.TabIndex = 46;
|
this.txtJiraUrl.TabIndex = 46;
|
||||||
//
|
//
|
||||||
|
// chkRemoveManuallyAddedWorklogs
|
||||||
|
//
|
||||||
|
this.chkRemoveManuallyAddedWorklogs.AutoSize = true;
|
||||||
|
this.chkRemoveManuallyAddedWorklogs.Location = new System.Drawing.Point(65, 387);
|
||||||
|
this.chkRemoveManuallyAddedWorklogs.Name = "chkRemoveManuallyAddedWorklogs";
|
||||||
|
this.chkRemoveManuallyAddedWorklogs.Size = new System.Drawing.Size(157, 17);
|
||||||
|
this.chkRemoveManuallyAddedWorklogs.TabIndex = 48;
|
||||||
|
this.chkRemoveManuallyAddedWorklogs.Text = "Удалять \"ручные записи\"";
|
||||||
|
this.chkRemoveManuallyAddedWorklogs.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// frmSettings
|
// frmSettings
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(243, 442);
|
this.ClientSize = new System.Drawing.Size(243, 467);
|
||||||
|
this.Controls.Add(this.chkRemoveManuallyAddedWorklogs);
|
||||||
this.Controls.Add(this.lblJiraUrl);
|
this.Controls.Add(this.lblJiraUrl);
|
||||||
this.Controls.Add(this.txtJiraUrl);
|
this.Controls.Add(this.txtJiraUrl);
|
||||||
this.Controls.Add(this.chkPullBeforeProcess);
|
this.Controls.Add(this.chkPullBeforeProcess);
|
||||||
@@ -377,5 +389,6 @@
|
|||||||
private System.Windows.Forms.Label label4;
|
private System.Windows.Forms.Label label4;
|
||||||
private System.Windows.Forms.Label lblJiraUrl;
|
private System.Windows.Forms.Label lblJiraUrl;
|
||||||
private System.Windows.Forms.TextBox txtJiraUrl;
|
private System.Windows.Forms.TextBox txtJiraUrl;
|
||||||
|
private System.Windows.Forms.CheckBox chkRemoveManuallyAddedWorklogs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,7 @@ namespace JiraTimeBot.UI
|
|||||||
txtWorkDayDuration.Text = settings.MinuterPerWorkDay.ToString();
|
txtWorkDayDuration.Text = settings.MinuterPerWorkDay.ToString();
|
||||||
txtRandomMinutes.Text = settings.RandomWorkMinutes.ToString();
|
txtRandomMinutes.Text = settings.RandomWorkMinutes.ToString();
|
||||||
chkPullBeforeProcess.Checked = settings.PullBeforeProcess;
|
chkPullBeforeProcess.Checked = settings.PullBeforeProcess;
|
||||||
|
chkRemoveManuallyAddedWorklogs.Checked = settings.RemoveManuallyAddedWorklogs;
|
||||||
|
|
||||||
cboWorkType_SelectedIndexChanged(null, null);
|
cboWorkType_SelectedIndexChanged(null, null);
|
||||||
}
|
}
|
||||||
@@ -76,7 +77,8 @@ namespace JiraTimeBot.UI
|
|||||||
TimeControlTask = txtTimeControlTask.Text,
|
TimeControlTask = txtTimeControlTask.Text,
|
||||||
MinuterPerWorkDay = minuterPerWorkDay,
|
MinuterPerWorkDay = minuterPerWorkDay,
|
||||||
RandomWorkMinutes = randomWorkMinutes,
|
RandomWorkMinutes = randomWorkMinutes,
|
||||||
PullBeforeProcess = chkPullBeforeProcess.Checked
|
PullBeforeProcess = chkPullBeforeProcess.Checked,
|
||||||
|
RemoveManuallyAddedWorklogs = chkRemoveManuallyAddedWorklogs.Checked
|
||||||
};
|
};
|
||||||
|
|
||||||
//LockUnlock(false);
|
//LockUnlock(false);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace JiraTimeBot.Update
|
namespace JiraTimeBot.Update
|
||||||
@@ -12,6 +13,7 @@ namespace JiraTimeBot.Update
|
|||||||
public class Updater : IUpdater
|
public class Updater : IUpdater
|
||||||
{
|
{
|
||||||
private readonly ILog _log;
|
private readonly ILog _log;
|
||||||
|
private double _downloadPercent = 0;
|
||||||
|
|
||||||
public Updater(ILog log)
|
public Updater(ILog log)
|
||||||
{
|
{
|
||||||
@@ -90,45 +92,34 @@ namespace JiraTimeBot.Update
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_log.Info($"Устанавливаю обновление до версии {gitVersion}.");
|
_log.Info($"Устанавливаю обновление до версии {gitVersion}.");
|
||||||
//Rename he executing file
|
|
||||||
System.IO.FileInfo appFile =
|
var appFile = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||||
new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
||||||
var bkpDir = Path.Combine(appFile.DirectoryName, "bkp");
|
var bkpDir = Path.Combine(appFile.DirectoryName, "bkp");
|
||||||
if (!Directory.Exists(bkpDir))
|
|
||||||
|
if (Directory.Exists(bkpDir))
|
||||||
|
Directory.Delete(bkpDir, true);
|
||||||
|
_log.Info($"Создаю директорию {bkpDir}.");
|
||||||
|
Directory.CreateDirectory(bkpDir);
|
||||||
|
|
||||||
|
//забэкапим все папки
|
||||||
|
foreach (var dir in Directory.GetDirectories(appFile.DirectoryName).Where(f=>!f.EndsWith("bkp")))
|
||||||
{
|
{
|
||||||
_log.Info($"Создаю директорию {bkpDir}.");
|
var dirName = new DirectoryInfo(dir);
|
||||||
Directory.CreateDirectory(bkpDir);
|
var bkpDirPath = Path.Combine(bkpDir, dirName.Name);
|
||||||
|
if (Directory.Exists(bkpDirPath))
|
||||||
|
Directory.Delete(bkpDirPath, true);
|
||||||
|
Directory.Move(dir, bkpDirPath);
|
||||||
|
}
|
||||||
|
//и файлы
|
||||||
|
foreach (var file in Directory.GetFiles(appFile.DirectoryName).Where(f=>!f.EndsWith("update.zip")))
|
||||||
|
{
|
||||||
|
File.Move(file, Path.Combine(bkpDir, new FileInfo(file).Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//распакуем архив
|
||||||
using (ZipArchive archive = ZipFile.OpenRead(Path.Combine(appFile.DirectoryName, updateFile)))
|
using (ZipArchive archive = ZipFile.OpenRead(Path.Combine(appFile.DirectoryName, updateFile)))
|
||||||
{
|
{
|
||||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
archive.ExtractToDirectory(appFile.DirectoryName);
|
||||||
{
|
|
||||||
var zipEntryPath = Path.Combine(appFile.DirectoryName, entry.FullName);
|
|
||||||
if (entry.FullName.EndsWith("/"))
|
|
||||||
{
|
|
||||||
var bkpEntryPath = Path.Combine(bkpDir, entry.FullName);
|
|
||||||
bkpEntryPath = bkpEntryPath.TrimEnd('/');
|
|
||||||
if (!Directory.Exists(bkpEntryPath))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(bkpEntryPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (File.Exists(zipEntryPath))
|
|
||||||
{
|
|
||||||
System.IO.FileInfo zipEntryFile = new System.IO.FileInfo(zipEntryPath);
|
|
||||||
if (File.Exists(bkpDir + "\\" + zipEntryFile.Name))
|
|
||||||
{
|
|
||||||
File.Delete(bkpDir + "\\" + zipEntryFile.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.IO.File.Move(zipEntryFile.FullName, bkpDir + "\\" + zipEntryFile.Name);
|
|
||||||
}
|
|
||||||
entry.ExtractToFile(zipEntryPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_log.Info("Обновление установлено. Перезапустите программу для применения изменений.");
|
_log.Info("Обновление установлено. Перезапустите программу для применения изменений.");
|
||||||
@@ -164,7 +155,11 @@ namespace JiraTimeBot.Update
|
|||||||
{
|
{
|
||||||
client.Headers.Add("User-Agent",
|
client.Headers.Add("User-Agent",
|
||||||
"Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0");
|
"Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0");
|
||||||
client.DownloadFile(url, to);
|
client.DownloadProgressChanged += ClientOnDownloadProgressChanged;
|
||||||
|
client.DownloadFileAsync(new Uri(url), to);
|
||||||
|
|
||||||
|
while (client.IsBusy) { Application.DoEvents(); }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,6 +169,16 @@ namespace JiraTimeBot.Update
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ClientOnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var percent = Math.Truncate(e.BytesReceived / (double)e.TotalBytesToReceive * 100);
|
||||||
|
if (Math.Abs(_downloadPercent - percent) >= 10)
|
||||||
|
{
|
||||||
|
_log.Info($"Downloaded: {percent}%");
|
||||||
|
_downloadPercent = percent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string Get(string uri)
|
private string Get(string uri)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user