Добавлена возможность менять режим работы."

This commit is contained in:
Danil Kislov
2019-03-18 13:47:27 +03:00
parent e8213d940f
commit 1b123cd1a0
6 changed files with 57 additions and 22 deletions
+9 -2
View File
@@ -20,6 +20,7 @@ namespace JiraTimeBotForm.Configuration
public string JiraPassword { get; set; } public string JiraPassword { get; set; }
public TimeSpan ActivationTime { get; set; } public TimeSpan ActivationTime { get; set; }
public bool AddCommentsToWorklog { get; set; } public bool AddCommentsToWorklog { get; set; }
public WorkType WorkType { get; set; }
public static Settings LoadAndCheck(Action settingsSource, Action<string> errorMessageReporter) public static Settings LoadAndCheck(Action settingsSource, Action<string> errorMessageReporter)
{ {
@@ -72,9 +73,9 @@ namespace JiraTimeBotForm.Configuration
errors.Add("Укажите UserName от Jira"); errors.Add("Укажите UserName от Jira");
} }
if (string.IsNullOrEmpty(settings.RepositoryPath) || !Directory.Exists(settings.RepositoryPath)) if (settings.WorkType == WorkType.Mercurial && (string.IsNullOrEmpty(settings.RepositoryPath) || !Directory.Exists(settings.RepositoryPath)))
{ {
errors.Add("Укажите RepositoryPath"); errors.Add("Укажите верный RepositoryPath");
} }
var hasErrors = errors.Any(); var hasErrors = errors.Any();
@@ -128,4 +129,10 @@ namespace JiraTimeBotForm.Configuration
private static string _settingsFileName = "settings.json"; private static string _settingsFileName = "settings.json";
} }
public enum WorkType
{
Mercurial = 0,
JiraLogs = 1,
}
} }
+1 -1
View File
@@ -42,7 +42,7 @@ namespace JiraTimeBotForm.JiraIntegration
var userName = settings.JiraUserName; var userName = settings.JiraUserName;
//userName = "Zoya.Aleksandridi"; //userName = "Zoya.Aleksandridi";
var jql = $"status changed by '{userName}' during (\"{date.Value:yyyy-MM-dd}\",\"{date.Value.AddDays(1):yyyy-MM-dd}\")"; var jql = $"status changed by '{userName}' during (\"{date.Value:yyyy-MM-dd}\",\"{date.Value:yyyy-MM-dd}\")";
var affectedIssues = jira.Issues.GetIssuesFromJqlAsync(jql, 50, 0, cancellationToken).Result.ToList(); var affectedIssues = jira.Issues.GetIssuesFromJqlAsync(jql, 50, 0, cancellationToken).Result.ToList();
return affectedIssues; return affectedIssues;
} }
+2 -2
View File
@@ -45,9 +45,9 @@ namespace JiraTimeBotForm
DateTime date = DateTime.Now.Date.AddDays(daysDiff); DateTime date = DateTime.Now.Date.AddDays(daysDiff);
IMercurialLog mercurial = _mercurialProviders.MercurialLog; IMercurialLog mercurial = _mercurialProviders.MercurialLog;
if (string.IsNullOrEmpty(settings.RepositoryPath)) if (settings.WorkType == WorkType.JiraLogs)
{ {
_log.Info("Путь до репозитория пуст, использую Jira как источник информации."); _log.Info("Использую Jira как источник информации.");
mercurial = _mercurialProviders.JiraCommitEmulator; mercurial = _mercurialProviders.JiraCommitEmulator;
} }
List<MercurialCommitItem> commits = mercurial.GetMercurialLog(settings, date, cancellationToken); List<MercurialCommitItem> commits = mercurial.GetMercurialLog(settings, date, cancellationToken);
+1 -1
View File
@@ -93,7 +93,7 @@ namespace JiraTimeBotForm.UI
_settings = Settings.LoadAndCheck(_settingsWindowShow, _settingsErrorReporter); _settings = Settings.LoadAndCheck(_settingsWindowShow, _settingsErrorReporter);
tmrStart.Enabled = true; tmrStart.Enabled = true;
_log.Info($"Загружен бот для {_settings.JiraUserName}, работаем в {_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)
+41 -15
View File
@@ -42,12 +42,14 @@
this.actTime = new System.Windows.Forms.DateTimePicker(); this.actTime = new System.Windows.Forms.DateTimePicker();
this.chkAddComments = new System.Windows.Forms.CheckBox(); this.chkAddComments = new System.Windows.Forms.CheckBox();
this.btnSave = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button();
this.cboWorkType = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.SuspendLayout(); this.SuspendLayout();
// //
// label5 // label5
// //
this.label5.AutoSize = true; this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(7, 120); this.label5.Location = new System.Drawing.Point(7, 153);
this.label5.Name = "label5"; this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(100, 13); this.label5.Size = new System.Drawing.Size(100, 13);
this.label5.TabIndex = 28; this.label5.TabIndex = 28;
@@ -55,7 +57,7 @@
// //
// txtRoundTo // txtRoundTo
// //
this.txtRoundTo.Location = new System.Drawing.Point(109, 117); this.txtRoundTo.Location = new System.Drawing.Point(109, 150);
this.txtRoundTo.Name = "txtRoundTo"; this.txtRoundTo.Name = "txtRoundTo";
this.txtRoundTo.Size = new System.Drawing.Size(100, 20); this.txtRoundTo.Size = new System.Drawing.Size(100, 20);
this.txtRoundTo.TabIndex = 27; this.txtRoundTo.TabIndex = 27;
@@ -64,7 +66,7 @@
// label4 // label4
// //
this.label4.AutoSize = true; this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(27, 15); this.label4.Location = new System.Drawing.Point(27, 48);
this.label4.Name = "label4"; this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(76, 13); this.label4.Size = new System.Drawing.Size(76, 13);
this.label4.TabIndex = 26; this.label4.TabIndex = 26;
@@ -72,7 +74,7 @@
// //
// txtRepoPath // txtRepoPath
// //
this.txtRepoPath.Location = new System.Drawing.Point(109, 12); this.txtRepoPath.Location = new System.Drawing.Point(109, 45);
this.txtRepoPath.Name = "txtRepoPath"; this.txtRepoPath.Name = "txtRepoPath";
this.txtRepoPath.Size = new System.Drawing.Size(100, 20); this.txtRepoPath.Size = new System.Drawing.Size(100, 20);
this.txtRepoPath.TabIndex = 25; this.txtRepoPath.TabIndex = 25;
@@ -80,7 +82,7 @@
// label2 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(21, 94); this.label2.Location = new System.Drawing.Point(21, 127);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(82, 13); this.label2.Size = new System.Drawing.Size(82, 13);
this.label2.TabIndex = 24; this.label2.TabIndex = 24;
@@ -88,7 +90,7 @@
// //
// txtMercurialEmail // txtMercurialEmail
// //
this.txtMercurialEmail.Location = new System.Drawing.Point(109, 91); this.txtMercurialEmail.Location = new System.Drawing.Point(109, 124);
this.txtMercurialEmail.Name = "txtMercurialEmail"; this.txtMercurialEmail.Name = "txtMercurialEmail";
this.txtMercurialEmail.Size = new System.Drawing.Size(100, 20); this.txtMercurialEmail.Size = new System.Drawing.Size(100, 20);
this.txtMercurialEmail.TabIndex = 23; this.txtMercurialEmail.TabIndex = 23;
@@ -96,7 +98,7 @@
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(36, 67); this.label1.Location = new System.Drawing.Point(36, 100);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 13); this.label1.Size = new System.Drawing.Size(71, 13);
this.label1.TabIndex = 22; this.label1.TabIndex = 22;
@@ -104,7 +106,7 @@
// //
// txtJiraPassword // txtJiraPassword
// //
this.txtJiraPassword.Location = new System.Drawing.Point(109, 64); this.txtJiraPassword.Location = new System.Drawing.Point(109, 97);
this.txtJiraPassword.Name = "txtJiraPassword"; this.txtJiraPassword.Name = "txtJiraPassword";
this.txtJiraPassword.PasswordChar = '*'; this.txtJiraPassword.PasswordChar = '*';
this.txtJiraPassword.Size = new System.Drawing.Size(100, 20); this.txtJiraPassword.Size = new System.Drawing.Size(100, 20);
@@ -113,7 +115,7 @@
// lbl1 // lbl1
// //
this.lbl1.AutoSize = true; this.lbl1.AutoSize = true;
this.lbl1.Location = new System.Drawing.Point(43, 41); this.lbl1.Location = new System.Drawing.Point(43, 74);
this.lbl1.Name = "lbl1"; this.lbl1.Name = "lbl1";
this.lbl1.Size = new System.Drawing.Size(64, 13); this.lbl1.Size = new System.Drawing.Size(64, 13);
this.lbl1.TabIndex = 20; this.lbl1.TabIndex = 20;
@@ -121,7 +123,7 @@
// //
// txtJiraLogin // txtJiraLogin
// //
this.txtJiraLogin.Location = new System.Drawing.Point(109, 38); this.txtJiraLogin.Location = new System.Drawing.Point(109, 71);
this.txtJiraLogin.Name = "txtJiraLogin"; this.txtJiraLogin.Name = "txtJiraLogin";
this.txtJiraLogin.Size = new System.Drawing.Size(100, 20); this.txtJiraLogin.Size = new System.Drawing.Size(100, 20);
this.txtJiraLogin.TabIndex = 19; this.txtJiraLogin.TabIndex = 19;
@@ -129,7 +131,7 @@
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(16, 147); this.label3.Location = new System.Drawing.Point(16, 180);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(91, 13); this.label3.Size = new System.Drawing.Size(91, 13);
this.label3.TabIndex = 30; this.label3.TabIndex = 30;
@@ -138,7 +140,7 @@
// actTime // actTime
// //
this.actTime.Format = System.Windows.Forms.DateTimePickerFormat.Time; this.actTime.Format = System.Windows.Forms.DateTimePickerFormat.Time;
this.actTime.Location = new System.Drawing.Point(109, 143); this.actTime.Location = new System.Drawing.Point(109, 176);
this.actTime.Name = "actTime"; this.actTime.Name = "actTime";
this.actTime.Size = new System.Drawing.Size(100, 20); this.actTime.Size = new System.Drawing.Size(100, 20);
this.actTime.TabIndex = 29; this.actTime.TabIndex = 29;
@@ -146,7 +148,7 @@
// chkAddComments // chkAddComments
// //
this.chkAddComments.AutoSize = true; this.chkAddComments.AutoSize = true;
this.chkAddComments.Location = new System.Drawing.Point(39, 169); this.chkAddComments.Location = new System.Drawing.Point(39, 202);
this.chkAddComments.Name = "chkAddComments"; this.chkAddComments.Name = "chkAddComments";
this.chkAddComments.Size = new System.Drawing.Size(133, 17); this.chkAddComments.Size = new System.Drawing.Size(133, 17);
this.chkAddComments.TabIndex = 31; this.chkAddComments.TabIndex = 31;
@@ -155,7 +157,7 @@
// //
// btnSave // btnSave
// //
this.btnSave.Location = new System.Drawing.Point(61, 203); this.btnSave.Location = new System.Drawing.Point(61, 236);
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;
@@ -163,11 +165,33 @@
this.btnSave.UseVisualStyleBackColor = true; this.btnSave.UseVisualStyleBackColor = true;
this.btnSave.Click += new System.EventHandler(this.btnSave_Click); this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
// //
// cboWorkType
//
this.cboWorkType.FormattingEnabled = true;
this.cboWorkType.Items.AddRange(new object[] {
"Mercurial",
"Jira Updates"});
this.cboWorkType.Location = new System.Drawing.Point(109, 18);
this.cboWorkType.Name = "cboWorkType";
this.cboWorkType.Size = new System.Drawing.Size(99, 21);
this.cboWorkType.TabIndex = 34;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(27, 21);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(75, 13);
this.label6.TabIndex = 35;
this.label6.Text = "Работаем на:";
//
// 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(220, 238); this.ClientSize = new System.Drawing.Size(220, 268);
this.Controls.Add(this.label6);
this.Controls.Add(this.cboWorkType);
this.Controls.Add(this.btnSave); this.Controls.Add(this.btnSave);
this.Controls.Add(this.chkAddComments); this.Controls.Add(this.chkAddComments);
this.Controls.Add(this.label3); this.Controls.Add(this.label3);
@@ -209,5 +233,7 @@
private System.Windows.Forms.DateTimePicker actTime; private System.Windows.Forms.DateTimePicker actTime;
private System.Windows.Forms.CheckBox chkAddComments; private System.Windows.Forms.CheckBox chkAddComments;
private System.Windows.Forms.Button btnSave; private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.ComboBox cboWorkType;
private System.Windows.Forms.Label label6;
} }
} }
+3 -1
View File
@@ -30,6 +30,7 @@ namespace JiraTimeBotForm.UI
//txtDummyMode.Checked = settings.DummyMode; //txtDummyMode.Checked = settings.DummyMode;
chkAddComments.Checked = settings.AddCommentsToWorklog; chkAddComments.Checked = settings.AddCommentsToWorklog;
txtRoundTo.Text = settings.RountToMinutes.ToString(); txtRoundTo.Text = settings.RountToMinutes.ToString();
cboWorkType.SelectedIndex = (int) settings.WorkType;
} }
public Settings ReadSettingsAndLock() public Settings ReadSettingsAndLock()
@@ -48,7 +49,8 @@ namespace JiraTimeBotForm.UI
RepositoryPath = txtRepoPath.Text, RepositoryPath = txtRepoPath.Text,
//DummyMode = txtDummyMode.Checked, //DummyMode = txtDummyMode.Checked,
AddCommentsToWorklog = chkAddComments.Checked, AddCommentsToWorklog = chkAddComments.Checked,
RountToMinutes = roundTo RountToMinutes = roundTo,
WorkType = (WorkType) cboWorkType.SelectedIndex
}; };
//LockUnlock(false); //LockUnlock(false);