Example #1
0
        static void Main(string[] args)
        {
            if (args.Length < 0)
            {
                // click once argument data
                args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
            }

            var reset = false;

            if (args.Length <= 0)
            {
                System.Console.Write("R for RESET, Any other key to READ A FILE... ");
                var keyInfo = System.Console.ReadKey(true);
                reset = keyInfo.Key == ConsoleKey.R;
                System.Console.WriteLine();
            }

            if (reset || (args.Length > 0 && args[0] == "RESET"))
            {
                ResetSettings();
            }
            else
            {
                var connection = Authenticate();

                Interaction.Notice("USER: "******"HOST: " + Properties.Settings.Default.Host + ":" + Properties.Settings.Default.Port);

                FileInfo inputFile = null;
                if (args.Length >= 1)
                {
                    inputFile = new FileInfo(args[0]);
                }
                else
                {
                    var inputFileName = Interaction.GetText("Please enter InputFile");
                    inputFile = new FileInfo(inputFileName);
                    inputFile.Refresh();
                }

                var namePart    = Path.Combine(Path.GetDirectoryName(inputFile.FullName), Path.GetFileNameWithoutExtension(inputFile.FullName));
                var logfileName = namePart + ".log";

                Interaction.Notice("LOG : " + logfileName);

                var compositionCatalog   = new DirectoryCatalog("./Plugins", "*.dll");
                var compositionContainer = new CompositionContainer(compositionCatalog);

                var dayFilters = compositionContainer.GetExports <ITrakkrDayFilter>();
                var logFilters = compositionContainer.GetExports <ITrakkrLogFilter>();

                bool failure;
                do
                {
                    var entries = ParseEvents(inputFile);

                    entries = entries
                              .GroupBy(e => e.Timestamp.Date)
                              .SelectMany(dateGroup =>
                    {
                        var result = dateGroup.AsEnumerable();

                        foreach (var dayFilter in dayFilters)
                        {
                            result = dayFilter.Value.Filter(result, dateGroup.Key);
                        }

                        return(result);
                    });

                    foreach (var logFilter in logFilters)
                    {
                        entries = logFilter.Value.Filter(entries);
                    }

                    var logger = new FileAppendLogger(logfileName, $"Updating Workitems : {DateTime.Now:O}");

                    failure = !UpdateWorkItems(connection, entries, logger);
                }while (failure && Interaction.Confirm("Retry?"));

                if (failure)
                {
                    // do not show message when retry was declined
                    return;
                }

                Interaction.Acknowledge("Done (press any key).");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args.Length < 0)
            {
                // click once argument data
                args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
            }

            var reset = false;
            if (args.Length <= 0)
            {
                System.Console.Write("R for RESET, Any other key to READ A FILE... ");
                var keyInfo = System.Console.ReadKey(true);
                reset = keyInfo.Key == ConsoleKey.R;
                System.Console.WriteLine();
            }

            if (reset || (args.Length > 0 && args[0] == "RESET"))
            {
                ResetSettings();
            }
            else
            {
                var connection = Authenticate();

                Interaction.Notice("USER: "******"HOST: " + Properties.Settings.Default.Host + ":" + Properties.Settings.Default.Port);

                FileInfo inputFile = null;
                if (args.Length >= 1)
                {
                    inputFile = new FileInfo(args[0]);
                }
                else
                {
                    var inputFileName = Interaction.GetText("Please enter InputFile");
                    inputFile = new FileInfo(inputFileName);
                    inputFile.Refresh();
                }

                var namePart = Path.Combine(Path.GetDirectoryName(inputFile.FullName), Path.GetFileNameWithoutExtension(inputFile.FullName));
                var logfileName = namePart + ".log";

                Interaction.Notice("LOG : " + logfileName);

                bool failure;
                do
                {
                    var entries = ParseEvents(inputFile);

                    var logger = new FileAppendLogger(logfileName,
                        $"Updating Workitems : {DateTime.Now.ToString("O")}");

                    failure = !UpdateWorkItems(connection, entries, logger);
                }
                while (failure && Interaction.Confirm("Retry?"));

                if (failure)
                {
                    // do not show message when retry was declined
                    return;
                }

                Interaction.Acknowledge("Done (press any key).");
            }
        }
Example #3
0
        private static bool UpdateWorkItems(IConnection connection, IEnumerable <IEntry <ShortTrackingFormatPayload> > entries, FileAppendLogger logger)
        {
            var issueManagement = new IssueManagement(connection);

            var errors   = !RequiredPreconditionsFulfilled(entries, issueManagement);
            var warnings = !OptionalPreconditionsFulfilled(entries);

            if (errors)
            {
                if (warnings)
                {
                    Interaction.Acknowledge("There have been errors and warnings. Cannot store entries.");
                    return(false);
                }

                Interaction.Acknowledge("There have been errors. Cannot store entries.");
                return(false);
            }

            if (warnings && !Interaction.Confirm("There have been warnings. Continue?"))
            {
                return(false);
            }

            PrintEntryList(entries, issueManagement);

            if (!Interaction.Confirm("Please review the entries. Continue?"))
            {
                return(false);
            }

            foreach (var trakkrEntry in entries)
            {
                var minutes = (int)Math.Round(trakkrEntry.Duration.TotalMinutes);
                System.Console.Write($"Saving: {trakkrEntry.Timestamp.ToShortDateString()} : {trakkrEntry.Payload.Query} ... : {minutes} Minutes ({trakkrEntry.Payload.Descrition}) ... ");

                var doc = "<workItem>"
                          + $"<date>{UnixTime.GetUnixTimestampMilliseconds(trakkrEntry.Timestamp)}</date>"
                          + $"<duration>{minutes}</duration>"
                          + $"<description>{HttpUtility.HtmlEncode(trakkrEntry.Payload.Descrition)}</description>"
                          + "</workItem>";

                var response = connection.PostXml($"issue/{trakkrEntry.Payload.Query}/timetracking/workitem", doc);
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    logger.Log($"Ticket {trakkrEntry.Payload.Query} ({trakkrEntry.Payload.Descrition}) : {minutes}m : {response.Location}");
                    System.Console.Write("SAVED!");
                }
                else
                {
                    System.Console.Write($"ERROR! Response Code: {response.StatusCode}");
                    logger.Log($"Ticket {trakkrEntry.Payload.Query} ({trakkrEntry.Payload.Descrition})" +
                               $" : {minutes}m" +
                               $" : ERROR! Response Code: {response.StatusCode}");
                }

                //POST http://localhost:8081/rest/issue/HBR-63/timetracking/workitem

                System.Console.WriteLine();

                //https://confluence.jetbrains.com/display/YTD6/Get+Available+Work+Items+of+Issue

                // get all workitems
                // GET /rest/issue/{issue}/timetracking/workitem/
                //var result = connection.Get<object>($"issue/{trakkrEntry.Mark}/timetracking/workitem/");

                // add a workitem
                //connection.Post($"issue/{trakkrEntry.Mark}/timetracking/workitem", "<xml/>");
                //POST http://localhost:8081/rest/issue/HBR-63/timetracking/workitem
            }

            return(true);
        }
Example #4
0
        private static bool UpdateWorkItems(IConnection connection, IEnumerable<IEntry<ShortTrackingFormatPayload>> entries, FileAppendLogger logger)
        {
            var issueManagement = new IssueManagement(connection);

            var errors = !RequiredPreconditionsFulfilled(entries, issueManagement);
            var warnings = !OptionalPreconditionsFulfilled(entries);

            if (errors)
            {
                if (warnings)
                {
                    Interaction.Acknowledge("There have been errors and warnings. Cannot store entries.");
                    return false;
                }

                Interaction.Acknowledge("There have been errors. Cannot store entries.");
                return false;
            }

            if (warnings && !Interaction.Confirm("There have been warnings. Continue?"))
            {
                return false;
            }

            PrintEntryList(entries, issueManagement);

            if (!Interaction.Confirm("Please review the entries. Continue?"))
            {
                return false;
            }

            foreach (var trakkrEntry in entries)
            {
                var minutes = (int)Math.Round(trakkrEntry.Duration.TotalMinutes);
                System.Console.Write($"Saving: {trakkrEntry.Timestamp.ToShortDateString()} : {trakkrEntry.Payload.Query} ... : {minutes} Minutes ({trakkrEntry.Payload.Descrition}) ... ");

                var doc = "<workItem>"
                          + $"<date>{UnixTime.GetUnixTimestampMilliseconds(trakkrEntry.Timestamp)}</date>"
                          + $"<duration>{minutes}</duration>"
                          + $"<description>{HttpUtility.HtmlEncode(trakkrEntry.Payload.Descrition)}</description>"
                          + "</workItem>";

                var response = connection.PostXml($"issue/{trakkrEntry.Payload.Query}/timetracking/workitem", doc);
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    logger.Log($"Ticket {trakkrEntry.Payload.Query} ({trakkrEntry.Payload.Descrition}) : {minutes}m : {response.Location}");
                    System.Console.Write("SAVED!");
                }
                else
                {
                    System.Console.Write($"ERROR! Response Code: {response.StatusCode}");
                    logger.Log($"Ticket {trakkrEntry.Payload.Query} ({trakkrEntry.Payload.Descrition})" +
                               $" : {minutes}m" +
                               $" : ERROR! Response Code: {response.StatusCode}");
                }

                //POST http://localhost:8081/rest/issue/HBR-63/timetracking/workitem

                System.Console.WriteLine();

                //https://confluence.jetbrains.com/display/YTD6/Get+Available+Work+Items+of+Issue

                // get all workitems
                // GET /rest/issue/{issue}/timetracking/workitem/
                //var result = connection.Get<object>($"issue/{trakkrEntry.Mark}/timetracking/workitem/");

                // add a workitem
                //connection.Post($"issue/{trakkrEntry.Mark}/timetracking/workitem", "<xml/>");
                //POST http://localhost:8081/rest/issue/HBR-63/timetracking/workitem
            }

            return true;
        }