Example #1
0
        void WritePlainText(TextWriter writer, string clientVersion)
        {
            writer.WriteLine($"Client Version: v{clientVersion}");
            writer.WriteLine();

            foreach (var job in cache.Jobs.OrderBy(i => i.JobType.FullName))
            {
                writer.WriteLine(ConsoleFormat.DoubleLine);
                writer.WriteLine($"Job:\t{job.JobType.FullName} [{job.JobType.Assembly.GetName().Name}]");
                writer.WriteLine($"Config:\t{job.ConfigType.FullName} [{job.ConfigType.Assembly.GetName().Name}]");
                writer.WriteLine(ConsoleFormat.DoubleLine);
                writer.WriteLine();

                if (job.IsValid)
                {
                    writer.WriteLine(verbose ? ConfigWriter.ToJson(cache.GetDefaultConfig(job)) : ConfigWriter.ToReducedJson(cache.GetDefaultConfig(job)));
                    writer.WriteLine();
                }
                else
                {
                    writer.WriteLine($"Error Loading Job: {job.Errors.ToString()}");
                    writer.WriteLine();
                }
            }
        }
Example #2
0
        public async Task RunAsync(CancellationToken cancel)
        {
            TextWriter writer = null;
            JobInfo    job;

            try
            {
                job = cache.Get(jobType);
            }
            catch (TypeNotFoundException)
            {
                Console.WriteLine($"Could not find the job type '{jobType}'.");
                return;
            }

            var config = cache.GetDefaultConfig(job);

            try
            {
                if (filePath == null)
                {
                    writer = Console.Out;
                }
                else
                {
                    // If path is an existing directory, such as ".", add a file name
                    if (Directory.Exists(filePath))
                    {
                        filePath = Path.Combine(filePath, job.JobType.Name + ".json");
                    }

                    writer = new StreamWriter(File.Open(filePath, FileMode.Create));
                }

                await writer.WriteAsync(verbose?ConfigWriter.ToJson(config) : ConfigWriter.ToReducedJson(config));
            }
            finally
            {
                if (filePath != null && writer != null)
                {
                    await writer.FlushAsync();

                    writer.Dispose();
                }
            }

            if (filePath != null)
            {
                Console.WriteLine($"Default config for {job.JobType.FullName} saved to {Path.GetFullPath(filePath)}");
            }
        }
Example #3
0
        public void Should_deserialize_full_config()
        {
            var expected = new DiagnosticConfig();

            expected.Job.Package = "Runly.Debug";
            expected.Job.Version = "0.1.0";
            expected.Job.Type    = typeof(DiagnosticJob).FullName;

            var actual = reader.FromJson(ConfigWriter.ToJson(expected));

            actual.Job.Should().NotBeNull();
            actual.Job.Package.Should().Be("Runly.Debug");
            actual.Job.Version.Should().Be("0.1.0");
            actual.Job.Type.Should().Be(typeof(DiagnosticJob).FullName);
        }
Example #4
0
        public void Should_serialize_full_config()
        {
            var expected = new DiagnosticConfig();

            expected.Job.Package = "Runly.Debug";
            expected.Job.Version = "0.1.0";
            expected.Job.Type    = typeof(DiagnosticJob).FullName;

            var actual = JObject.Parse(ConfigWriter.ToJson(expected));

            actual["job"].Should().NotBeNull();
            actual["job"]["package"].ToString().Should().Be("Runly.Debug");
            actual["job"]["version"].ToString().Should().Be("0.1.0");
            actual["job"]["type"].ToString().Should().Be(typeof(DiagnosticJob).FullName);
        }
Example #5
0
 /// <summary>
 /// Enqueues a new run with the <paramref name="config"/> in the <paramref name="organization"/> and <paramref name="environment"/>.
 /// </summary>
 /// <param name="client">The API client to use.</param>
 /// <param name="organization">The organization in which the <paramref name="environment"/> can be found.</param>
 /// <param name="environment">The environment to enqueue a new run in.</param>
 /// <param name="config">The <see cref="Config"/> for the new run.</param>
 /// <returns>A newly enqueued <see cref="Run"/>.</returns>
 public static Task <Run> Enqueue(this IRunClient client, string organization, string environment, Config config) =>
 client.Enqueue(organization, environment, ConfigWriter.ToJson(config));