Exemple #1
0
        public void PrintCurrentState(bool waitForCompletion = true)
        {
            var startTime   = Task.StartTime ?? DateTimeOffset.Now;
            var taskRepo    = WebClient.GetWebClientRef().GetOctopusRepository().Tasks;
            var webPageLink = ConfigurationManager.AppSettings["OctoBaseUrl"] + Task.Link("Web");

            Console.WriteLine($"{Task.Name} Will Start at {startTime}");
            Console.WriteLine($"Task Link: {webPageLink}");
            if (!waitForCompletion)
            {
                Console.WriteLine("Not Wait for Completion, Start Next Task");
                Console.WriteLine("----------------------------------------");
                return;
            }
            ;

            taskRepo.WaitForCompletion(Task);

            Task = taskRepo.Refresh(Task);
            var endTime = DateTimeOffset.Now;

            switch (Task.State)
            {
            case TaskState.Success:
                Console.WriteLine("Task is finished successfully at {0}, taking {1}", endTime.LocalDateTime,
                                  endTime - startTime);
                break;

            case TaskState.Failed:
                Console.WriteLine("Task failed at {0}, taking {1}", endTime.LocalDateTime,
                                  endTime - startTime);
                Console.WriteLine(Task.ErrorMessage);
                break;

            case TaskState.Canceled:
                Console.WriteLine("Task got canceled at {0}, taking {1}", endTime.LocalDateTime,
                                  endTime - startTime);
                break;
            }
            Console.WriteLine("----------------------------------------");
        }