// Copyright Epic Games, Inc. All Rights Reserved.
using EpicGames.Core;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Xml;
namespace AutomationTool.Tasks
{
///
/// Parameters for a .
///
public class HordeCreateReportTaskParameters
{
///
/// Name for the report
///
[TaskParameter]
public string Name;
///
/// Where to display the report
///
[TaskParameter]
public string Scope;
///
/// Where to show the report
///
[TaskParameter]
public string Placement;
///
/// Text to be displayed
///
[TaskParameter]
public string Text;
}
///
/// Creates a Horde report file, which will be displayed on the dashboard with any job running this task.
///
[TaskElement("Horde-CreateReport", typeof(HordeCreateReportTaskParameters))]
public class HordeCreateReportTask : BgTaskImpl
{
///
/// Parameters for this task.
///
HordeCreateReportTaskParameters Parameters;
///
/// Constructor.
///
/// Parameters for this task.
public HordeCreateReportTask(HordeCreateReportTaskParameters InParameters)
{
Parameters = InParameters;
}
///
/// Execute the task.
///
/// Information about the current job.
/// Set of build products produced by this node.
/// Mapping from tag names to the set of files they include.
public override async Task ExecuteAsync(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet)
{
FileReference ReportTextFile = FileReference.Combine(new DirectoryReference(CommandUtils.CmdEnv.LogFolder), $"{Parameters.Name}.md");
await FileReference.WriteAllTextAsync(ReportTextFile, Parameters.Text);
FileReference ReportJsonFile = FileReference.Combine(new DirectoryReference(CommandUtils.CmdEnv.LogFolder), $"{Parameters.Name}.report.json");
using (FileStream ReportJsonStream = FileReference.Open(ReportJsonFile, FileMode.Create, FileAccess.Write, FileShare.Read))
{
using (Utf8JsonWriter Writer = new Utf8JsonWriter(ReportJsonStream))
{
Writer.WriteStartObject();
Writer.WriteString("scope", Parameters.Scope);
Writer.WriteString("name", Parameters.Name);
Writer.WriteString("placement", Parameters.Placement);
Writer.WriteString("fileName", ReportTextFile.GetFileName());
Writer.WriteEndObject();
}
}
Logger.LogInformation("Written report to {TextFile} and {JsonFile}: \"{Text}\"", ReportTextFile, ReportJsonFile, Parameters.Text);
}
///
/// Output this task out to an XML writer.
///
public override void Write(XmlWriter Writer)
{
Write(Writer, Parameters);
}
///
/// Find all the tags which are used as inputs to this task
///
/// The tag names which are read by this task
public override IEnumerable FindConsumedTagNames() => Enumerable.Empty();
///
/// Find all the tags which are modified by this task
///
/// The tag names which are modified by this task
public override IEnumerable FindProducedTagNames() => Enumerable.Empty();
}
}