diff --git a/JiraTimeBotForm/Configuration/Settings.cs b/JiraTimeBotForm/Configuration/Settings.cs index 9c609ed..5f96cba 100644 --- a/JiraTimeBotForm/Configuration/Settings.cs +++ b/JiraTimeBotForm/Configuration/Settings.cs @@ -8,6 +8,8 @@ namespace JiraTimeBotForm.Configuration public class Settings { public int MinuterPerWorkDay = 8 * 60; + public int RountToMinutes { get; set; } + public string JiraUrl = "https://myteam.aeroclub.ru"; public string RepositoryPath { get; set; } diff --git a/JiraTimeBotForm/DI/ContainerBuilder.cs b/JiraTimeBotForm/DI/ContainerBuilder.cs index a111c47..3ddb2b0 100644 --- a/JiraTimeBotForm/DI/ContainerBuilder.cs +++ b/JiraTimeBotForm/DI/ContainerBuilder.cs @@ -30,18 +30,20 @@ namespace JiraTimeBotForm.DI _builder.RegisterType().As().AsSelf(); _builder.RegisterType().As().AsSelf(); - //_builder.RegisterType().As().AsSelf(); + _builder.RegisterType().As().AsSelf(); + _builder.RegisterAggregateService(); _builder.RegisterType().As().AsSelf(); _builder.RegisterType().AsSelf().As(); _builder.RegisterType().AsSelf().As(); _builder.RegisterAggregateService(); + _builder.RegisterType().AsSelf().As(); _builder.RegisterType().AsSelf().AsImplementedInterfaces(); - _builder.Register(c => new Job(c.Resolve(), c.Resolve(), c.Resolve())).AsSelf(); + _builder.Register(c => new Job(c.Resolve(), c.Resolve(), c.Resolve())).AsSelf(); var container = _builder.Build(); return container; diff --git a/JiraTimeBotForm/JiraIntegration/JiraApi.cs b/JiraTimeBotForm/JiraIntegration/JiraApi.cs index c805c6e..004deb1 100644 --- a/JiraTimeBotForm/JiraIntegration/JiraApi.cs +++ b/JiraTimeBotForm/JiraIntegration/JiraApi.cs @@ -39,7 +39,10 @@ namespace JiraTimeBotForm.JiraIntegration var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword); date = date.GetValueOrDefault(DateTime.Now.Date); - var jql = $"status changed by '{settings.JiraUserName}' during (\"{date.Value:yyyy-MM-dd}\",\"{date.Value.AddDays(1):yyyy-MM-dd}\")"; + var userName = settings.JiraUserName; + //userName = "Zoya.Aleksandridi"; + + var jql = $"status changed by '{userName}' during (\"{date.Value:yyyy-MM-dd}\",\"{date.Value.AddDays(1):yyyy-MM-dd}\")"; var affectedIssues = jira.Issues.GetIssuesFromJqlAsync(jql, 50, 0, cancellationToken).Result.ToList(); return affectedIssues; } diff --git a/JiraTimeBotForm/JiraTimeBotForm.csproj b/JiraTimeBotForm/JiraTimeBotForm.csproj index a880d78..3eb2929 100644 --- a/JiraTimeBotForm/JiraTimeBotForm.csproj +++ b/JiraTimeBotForm/JiraTimeBotForm.csproj @@ -87,6 +87,7 @@ + @@ -109,7 +110,7 @@ - + diff --git a/JiraTimeBotForm/Job.cs b/JiraTimeBotForm/Job.cs index 285a474..9905c00 100644 --- a/JiraTimeBotForm/Job.cs +++ b/JiraTimeBotForm/Job.cs @@ -14,13 +14,13 @@ namespace JiraTimeBotForm { class Job { - private readonly IMercurialLog _mercurialLog; + private readonly IAllMercurialProviders _mercurialProviders; private readonly ITaskTimeCalculator _taskTimeDiscoverer; private readonly ILog _log; - public Job(IMercurialLog mercurialLog, ITaskTimeCalculator taskTimeDiscoverer, ILog log) + public Job(IAllMercurialProviders mercurialProviders, ITaskTimeCalculator taskTimeDiscoverer, ILog log) { - _mercurialLog = mercurialLog; + _mercurialProviders = mercurialProviders; _taskTimeDiscoverer = taskTimeDiscoverer; _log = log; } @@ -44,7 +44,13 @@ namespace JiraTimeBotForm { DateTime date = DateTime.Now.Date.AddDays(daysDiff); - List commits = _mercurialLog.GetMercurialLog(settings, date, cancellationToken); + IMercurialLog mercurial = _mercurialProviders.MercurialLog; + if (string.IsNullOrEmpty(settings.RepositoryPath)) + { + _log.Info("Путь до репозитория пуст, использую Jira как источник информации."); + mercurial = _mercurialProviders.JiraCommitEmulator; + } + List commits = mercurial.GetMercurialLog(settings, date, cancellationToken); List taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken); if (cancellationToken.IsCancellationRequested) diff --git a/JiraTimeBotForm/Mercurial/IAllMercurialProviders.cs b/JiraTimeBotForm/Mercurial/IAllMercurialProviders.cs new file mode 100644 index 0000000..eba0aff --- /dev/null +++ b/JiraTimeBotForm/Mercurial/IAllMercurialProviders.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JiraTimeBotForm.JiraIntegration; + +namespace JiraTimeBotForm.Mercurial +{ + public interface IAllMercurialProviders + { + MercurialLog MercurialLog { get; } + JiraCommitEmulator JiraCommitEmulator { get; } + } +} diff --git a/JiraTimeBotForm/Mercurial/MercurialLog.cs b/JiraTimeBotForm/Mercurial/MercurialLog.cs index d8a7f47..6676784 100644 --- a/JiraTimeBotForm/Mercurial/MercurialLog.cs +++ b/JiraTimeBotForm/Mercurial/MercurialLog.cs @@ -26,6 +26,12 @@ namespace JiraTimeBotForm.Mercurial public List GetMercurialLog(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken)) { + if (string.IsNullOrEmpty(settings.RepositoryPath) || !Directory.Exists(settings.RepositoryPath)) + { + _log.Error("Папка с репо не сушествует."); + return new List(); + } + date = date.GetValueOrDefault(DateTime.Now.Date); var workTasks = new List(); diff --git a/JiraTimeBotForm/TaskTime/TaskTimeDiscoverer.cs b/JiraTimeBotForm/TaskTime/TaskTimeByCommitsCalculator.cs similarity index 97% rename from JiraTimeBotForm/TaskTime/TaskTimeDiscoverer.cs rename to JiraTimeBotForm/TaskTime/TaskTimeByCommitsCalculator.cs index dab92a1..5498711 100644 --- a/JiraTimeBotForm/TaskTime/TaskTimeDiscoverer.cs +++ b/JiraTimeBotForm/TaskTime/TaskTimeByCommitsCalculator.cs @@ -35,7 +35,7 @@ namespace JiraTimeBotForm.TaskTime } int currentTaskCommits = taskGroup.Count(); - int currentTaskTime = (int)RoundTo(settings.MinuterPerWorkDay / totalCommitsCount * currentTaskCommits); + int currentTaskTime = (int)RoundTo(settings.MinuterPerWorkDay / totalCommitsCount * currentTaskCommits, settings.RountToMinutes); remainMinutes = remainMinutes - currentTaskTime; var orderedTasks = taskGroup.OrderBy(f => f.Time).ToArray(); diff --git a/JiraTimeBotForm/UI/frmMain.Designer.cs b/JiraTimeBotForm/UI/frmMain.Designer.cs index cf48f66..1ff3aed 100644 --- a/JiraTimeBotForm/UI/frmMain.Designer.cs +++ b/JiraTimeBotForm/UI/frmMain.Designer.cs @@ -49,19 +49,21 @@ this.btnMeeting = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button(); this.chkAddComments = new System.Windows.Forms.CheckBox(); + this.label5 = new System.Windows.Forms.Label(); + this.txtRoundTo = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // actTime // this.actTime.Format = System.Windows.Forms.DateTimePickerFormat.Time; - this.actTime.Location = new System.Drawing.Point(94, 120); + this.actTime.Location = new System.Drawing.Point(100, 147); this.actTime.Name = "actTime"; this.actTime.Size = new System.Drawing.Size(100, 20); this.actTime.TabIndex = 0; // // txtJiraLogin // - this.txtJiraLogin.Location = new System.Drawing.Point(94, 42); + this.txtJiraLogin.Location = new System.Drawing.Point(100, 42); this.txtJiraLogin.Name = "txtJiraLogin"; this.txtJiraLogin.Size = new System.Drawing.Size(100, 20); this.txtJiraLogin.TabIndex = 1; @@ -69,7 +71,7 @@ // lbl1 // this.lbl1.AutoSize = true; - this.lbl1.Location = new System.Drawing.Point(28, 45); + this.lbl1.Location = new System.Drawing.Point(34, 45); this.lbl1.Name = "lbl1"; this.lbl1.Size = new System.Drawing.Size(60, 13); this.lbl1.TabIndex = 2; @@ -78,7 +80,7 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(21, 71); + this.label1.Location = new System.Drawing.Point(27, 71); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(67, 13); this.label1.TabIndex = 4; @@ -86,7 +88,7 @@ // // txtJiraPassword // - this.txtJiraPassword.Location = new System.Drawing.Point(94, 68); + this.txtJiraPassword.Location = new System.Drawing.Point(100, 68); this.txtJiraPassword.Name = "txtJiraPassword"; this.txtJiraPassword.PasswordChar = '*'; this.txtJiraPassword.Size = new System.Drawing.Size(100, 20); @@ -95,7 +97,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(6, 97); + this.label2.Location = new System.Drawing.Point(12, 98); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(82, 13); this.label2.TabIndex = 6; @@ -103,7 +105,7 @@ // // txtMercurialEmail // - this.txtMercurialEmail.Location = new System.Drawing.Point(94, 94); + this.txtMercurialEmail.Location = new System.Drawing.Point(100, 95); this.txtMercurialEmail.Name = "txtMercurialEmail"; this.txtMercurialEmail.Size = new System.Drawing.Size(100, 20); this.txtMercurialEmail.TabIndex = 5; @@ -111,15 +113,15 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(45, 126); + this.label3.Location = new System.Drawing.Point(7, 151); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(43, 13); + this.label3.Size = new System.Drawing.Size(87, 13); this.label3.TabIndex = 7; - this.label3.Text = "Время:"; + this.label3.Text = "Время запуска:"; // // btnSave // - this.btnSave.Location = new System.Drawing.Point(82, 169); + this.btnSave.Location = new System.Drawing.Point(78, 196); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.TabIndex = 8; @@ -130,7 +132,7 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(12, 19); + this.label4.Location = new System.Drawing.Point(18, 19); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(76, 13); this.label4.TabIndex = 10; @@ -138,7 +140,7 @@ // // txtRepoPath // - this.txtRepoPath.Location = new System.Drawing.Point(94, 16); + this.txtRepoPath.Location = new System.Drawing.Point(100, 16); this.txtRepoPath.Name = "txtRepoPath"; this.txtRepoPath.Size = new System.Drawing.Size(100, 20); this.txtRepoPath.TabIndex = 9; @@ -150,12 +152,12 @@ this.txtLog.Name = "txtLog"; this.txtLog.ReadOnly = true; this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.txtLog.Size = new System.Drawing.Size(510, 264); + this.txtLog.Size = new System.Drawing.Size(510, 294); this.txtLog.TabIndex = 11; // // btnStart // - this.btnStart.Location = new System.Drawing.Point(9, 224); + this.btnStart.Location = new System.Drawing.Point(9, 254); this.btnStart.Name = "btnStart"; this.btnStart.Size = new System.Drawing.Size(114, 23); this.btnStart.TabIndex = 12; @@ -177,7 +179,7 @@ // txtDummyMode // this.txtDummyMode.AutoSize = true; - this.txtDummyMode.Location = new System.Drawing.Point(9, 201); + this.txtDummyMode.Location = new System.Drawing.Point(9, 231); this.txtDummyMode.Name = "txtDummyMode"; this.txtDummyMode.Size = new System.Drawing.Size(114, 17); this.txtDummyMode.TabIndex = 13; @@ -186,7 +188,7 @@ // // btnMeeting // - this.btnMeeting.Location = new System.Drawing.Point(142, 224); + this.btnMeeting.Location = new System.Drawing.Point(142, 254); this.btnMeeting.Name = "btnMeeting"; this.btnMeeting.Size = new System.Drawing.Size(70, 23); this.btnMeeting.TabIndex = 14; @@ -197,7 +199,7 @@ // btnCancel // this.btnCancel.Enabled = false; - this.btnCancel.Location = new System.Drawing.Point(9, 256); + this.btnCancel.Location = new System.Drawing.Point(9, 286); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(203, 23); this.btnCancel.TabIndex = 15; @@ -208,18 +210,37 @@ // chkAddComments // this.chkAddComments.AutoSize = true; - this.chkAddComments.Location = new System.Drawing.Point(61, 146); + this.chkAddComments.Location = new System.Drawing.Point(45, 175); this.chkAddComments.Name = "chkAddComments"; this.chkAddComments.Size = new System.Drawing.Size(133, 17); this.chkAddComments.TabIndex = 16; this.chkAddComments.Text = "Добавлять описание"; this.chkAddComments.UseVisualStyleBackColor = true; // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(-2, 124); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(96, 13); + this.label5.TabIndex = 18; + this.label5.Text = "Округл. времени:"; + // + // txtRoundTo + // + this.txtRoundTo.Location = new System.Drawing.Point(100, 121); + this.txtRoundTo.Name = "txtRoundTo"; + this.txtRoundTo.Size = new System.Drawing.Size(100, 20); + this.txtRoundTo.TabIndex = 17; + this.txtRoundTo.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress); + // // frmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(740, 292); + this.ClientSize = new System.Drawing.Size(740, 318); + this.Controls.Add(this.label5); + this.Controls.Add(this.txtRoundTo); this.Controls.Add(this.chkAddComments); this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnMeeting); @@ -270,6 +291,8 @@ private System.Windows.Forms.Button btnMeeting; private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.CheckBox chkAddComments; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txtRoundTo; } } diff --git a/JiraTimeBotForm/UI/frmMain.cs b/JiraTimeBotForm/UI/frmMain.cs index 936631f..e7da90e 100644 --- a/JiraTimeBotForm/UI/frmMain.cs +++ b/JiraTimeBotForm/UI/frmMain.cs @@ -59,6 +59,11 @@ namespace JiraTimeBotForm.UI public Settings ReadSettingsAndLock() { + if (!int.TryParse(txtRoundTo.Text, out var roundTo)) + { + roundTo = 15; + } + var settings = new Settings { JiraUserName = txtJiraLogin.Text, @@ -68,6 +73,7 @@ namespace JiraTimeBotForm.UI RepositoryPath = txtRepoPath.Text, DummyMode = txtDummyMode.Checked, AddCommentsToWorklog = chkAddComments.Checked, + RountToMinutes = roundTo }; LockUnlock(false); @@ -119,18 +125,13 @@ namespace JiraTimeBotForm.UI actTime.Text = settings.ActivationTime.ToString("hh\\:mm\\:ss"); txtDummyMode.Checked = settings.DummyMode; chkAddComments.Checked = settings.AddCommentsToWorklog; + txtRoundTo.Text = settings.RountToMinutes.ToString(); } private async void btnStart_Click(object sender, EventArgs e) { var settings = ReadSettingsAndLock(); - if (!Directory.Exists(settings.RepositoryPath)) - { - MessageBox.Show("Папка с репо не сушествует.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - using (_tokenSource = GetTokenSource()) { await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, _tokenSource.Token); @@ -208,5 +209,10 @@ namespace JiraTimeBotForm.UI { _tokenSource.Cancel(); } + + private void textBox1_KeyPress(object sender, KeyPressEventArgs e) + { + e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar); + } } }