public void Should_deserialize_reduced_config() { var expected = new DiagnosticConfig(); expected.Job.Type = typeof(DiagnosticJob).FullName; var actual = reader.FromJson(ConfigWriter.ToReducedJson(expected)); actual.Should().NotBeNull(); actual.Job.Type.Should().Be(typeof(DiagnosticJob).FullName); }
public void Should_serialize_reduced_config() { var config = new Config() { Job = new JobConfig() { Type = "SomeType" } }; ConfigWriter.ToReducedJson(config).Replace("\r", "").Replace("\n", "").Should().Be("{ \"job\": \"SomeType\"}"); }
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)}"); } }
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(); } } }