public static void CopyWorkLogs(List <Worklog> worklogList, JiraRestApi targetJiraRestApi, string targetTicket) { Console.WriteLine("***** Daily worklogs *****"); foreach (Worklog oneWorklog in worklogList) { Console.WriteLine("-----------"); Console.WriteLine("| targetTicket: " + targetTicket); Console.WriteLine("| key: " + oneWorklog.key); Console.WriteLine("| comment: " + oneWorklog.comment); Console.WriteLine("| timeSpentSeconds: " + Utils.ConvertSecondsToWorklogFormat(oneWorklog.timeSpentSeconds)); Console.WriteLine("| dateStarted: " + string.Format("{0}{1:zz}00", oneWorklog.dateStarted, DateTime.Now)); string details = string.Format("{0}: {1}", oneWorklog.key, oneWorklog.comment); targetJiraRestApi.AddWorklog(targetTicket, details, Utils.ConvertSecondsToWorklogFormat(oneWorklog.timeSpentSeconds), string.Format("{0}{1:zz}00", oneWorklog.dateStarted, DateTime.Now) ); Console.WriteLine("-----------"); } Console.WriteLine("**************************"); }
static void Main(string[] args) { restClientsInit(); string command = ""; while (true) { Console.WriteLine("- Enter 'exit' to exit"); Console.WriteLine("- Enter 'addlogs' to copy logs from .txt file to client's Jira"); Console.WriteLine("- Enter a specific period in YYYY-MM-D:YYYY-MM-D format " + "to copy worklogs:"); command = Utils.GetConsoleValue(); if (Utils.IsDateFormatCorrect(command)) { string[] dateItems = command.Split(':'); switch (Utils.CompareTwoDates(dateItems[0], dateItems[1])) { case 0: case -1: Console.WriteLine("Copying..."); Console.WriteLine(" "); Dictionary <string, List <Worklog> > worklogsListForPeriod = u4iJiraRestApi.GetWorklogsListForPeriod(dateItems[0], dateItems[1]); foreach (KeyValuePair <string, List <Worklog> > listlogsForOneDay in worklogsListForPeriod) { JiraRestApi.CopyWorkLogs(listlogsForOneDay.Value, ainJiraRestApi, TARGET_TICKET); } Console.WriteLine( String.Format("Copying successfully completed! (for '{0}' - '{1}' dates)", dateItems[0], dateItems[1])); break; default: Console.WriteLine("'{0}' {1} '{2}'. Worklogs were not copied!", dateItems[0], "is later than", dateItems[1]); break; } } else if (command.Equals("exit")) { break; } else if (command.Equals("addlogs")) { foreach (var worklog in Utils.GetWorkloglistFromTxtFile()) { string date = Utils.GetCurrentDateAndTime(); u4iJiraRestApi.AddWorklog(worklog.key, worklog.comment, worklog.timeSpentSeconds, date); Console.WriteLine("| Adding worklog in U4I jira ...: " + worklog.key + " " + worklog.timeSpentSeconds + " " + worklog.comment + " " + date); } Console.WriteLine("*** Worklogs adding is completed ***"); } else { Console.WriteLine(String.Format("'{0}' - unsupported command", command)); } Console.ReadKey(); } }