202 lines
No EOL
6.5 KiB
C#
202 lines
No EOL
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JD.Asset.Types.Map;
|
|
using TeaBox.AssetValidation;
|
|
using TeaBox.Core.Helpers;
|
|
using TeaBox.LD;
|
|
using TeaBox.Macros;
|
|
using TeaBox.Razor;
|
|
using TeaBox.Shotgun;
|
|
using Ubisoft;
|
|
|
|
namespace TeaBox.MapValidation
|
|
{
|
|
/// <summary>
|
|
/// Shows the current status of all maps Grouped according to their Batches
|
|
/// </summary>
|
|
[Module(Icon = "news"), Category("(Advanced)"), DisplayName(@"Digest")]
|
|
public class MapValidationDigest
|
|
{
|
|
#region Macros
|
|
|
|
[Macro(Icon = "news")]
|
|
[DisplayName("Map Digest for skuscene")]
|
|
public void GenerateForSkuScene(IExecutionContext context, string skuScene)
|
|
{
|
|
GenerateBatchDigest(context, SkuScene.MaplistFromSkuScene(skuScene));
|
|
}
|
|
|
|
[Macro(Icon = "news")]
|
|
[DisplayName("Map Digest")]
|
|
public void GenerateBatchDigest(IExecutionContext context, MapList maps)
|
|
{
|
|
if (maps == null || maps.Count == 0)
|
|
{
|
|
GetCurrentJdMapsFromShotgun();
|
|
RemoveMapsWithNoBatches();
|
|
}
|
|
else
|
|
{
|
|
GetShotgunMapsForSelectedMaps(maps);
|
|
}
|
|
ComputeModel(context);
|
|
CreateSummary();
|
|
SortBatches();
|
|
|
|
var cshtml = LocatorService.LocateFileFromScripts("MapValidationDigest.cshtml");
|
|
var report = new RazorReport(cshtml, ReportPath, this, Title);
|
|
|
|
report.GenerateAndOpen(context);
|
|
}
|
|
|
|
private void SortBatches()
|
|
{
|
|
List<BatchReport> sortedBatches;
|
|
|
|
if (BatchReportList.TrueForAll(x => x.Batch.BatchNumber != null))
|
|
{
|
|
sortedBatches = (from batchReport in BatchReportList orderby batchReport.Batch.BatchNumber.Value descending select batchReport).ToList();
|
|
}
|
|
else
|
|
{
|
|
sortedBatches = (from batchReport in BatchReportList orderby batchReport.Batch.Name descending select batchReport).ToList();
|
|
}
|
|
|
|
BatchReportList = sortedBatches;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Variables
|
|
|
|
public List<BatchReport> BatchReportList = new List<BatchReport>();
|
|
private int _mapCount;
|
|
private int _failedMapCount;
|
|
private IEnumerable<ShotgunMap> _mapsToValidate;
|
|
private List<ShotgunBatch> _batches;
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public string ReportPath
|
|
{
|
|
get
|
|
{
|
|
var reportPath = Path.Combine(UAFConstants.GenericNas, "DB", "Digest",
|
|
"BatchStatus_" + DateTime.Today.ToString("yyyy_MM_dd", CultureInfo.InvariantCulture) +
|
|
"_digest.html");
|
|
return reportPath;
|
|
}
|
|
}
|
|
|
|
public string Title
|
|
{
|
|
get { return "Map Digest"; }
|
|
}
|
|
|
|
public string Summary { get { return string.Format("{0} maps, {1} failure", _mapCount, _failedMapCount); } }
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private void GetCurrentJdMapsFromShotgun()
|
|
{
|
|
var shotgunClient = ShotgunClientExtensions.DefaultClient();
|
|
var opus = shotgunClient.FindOne<ShotgunJdOpus>(new { Name = UAFConstants.GameName });
|
|
_mapsToValidate = shotgunClient.ListAll<ShotgunMap>(new { JdOpus = opus.ToPartialEntity() });
|
|
}
|
|
|
|
private void GetShotgunMapsForSelectedMaps(IEnumerable<Map> maps)
|
|
{
|
|
var shotgunClient = ShotgunClientExtensions.DefaultClient();
|
|
_mapsToValidate = shotgunClient.ListAll<ShotgunMap>(
|
|
new { Name__in = maps.Select(m => m.Name).ToArray<object>() }
|
|
);
|
|
}
|
|
|
|
|
|
private void RemoveMapsWithNoBatches()
|
|
{
|
|
var mapsWithValidBatches = _mapsToValidate.Where(x => x.MapBatch != null);
|
|
_mapsToValidate = mapsWithValidBatches;
|
|
}
|
|
|
|
private void ComputeModel(IExecutionContext context)
|
|
{
|
|
FillBatchList();
|
|
foreach (var batch in _batches)
|
|
{
|
|
var batchReport = new BatchReport { Batch = batch, };
|
|
batchReport.GenerateBatchReport(context, batch.MapList);
|
|
BatchReportList.Add(batchReport);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Only the maps that are present in the _mapsToValidate are loaded in the batches.
|
|
/// </summary>
|
|
private void FillBatchList()
|
|
{
|
|
var validChildBatches = _mapsToValidate.Select(shotgunMap => shotgunMap.MapBatch)
|
|
.NotNulls()
|
|
.DistinctBy(x => x.Name);
|
|
|
|
var sgClient = ShotgunClientExtensions.DefaultClient();
|
|
_batches = validChildBatches.Select(x => sgClient.GetComplete<ShotgunBatch>(x)).ToList();
|
|
|
|
foreach (var shotgunMap in _mapsToValidate)
|
|
{
|
|
if (shotgunMap.MapBatch == null)
|
|
{
|
|
var defaultBatch = _batches.FirstOrDefault(x => x.Name == ShotgunBatch.DefaultBatchName);
|
|
if (defaultBatch == null)
|
|
{
|
|
defaultBatch = ShotgunBatch.DefaultBatch();
|
|
_batches.Add(defaultBatch);
|
|
}
|
|
defaultBatch.LoadMapFromDisk(shotgunMap.Map);
|
|
}
|
|
else
|
|
{
|
|
_batches.First(x => x.Name == shotgunMap.MapBatch.Name).LoadMapFromDisk(shotgunMap.Map);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CreateSummary()
|
|
{
|
|
foreach (var batchReport in BatchReportList)
|
|
{
|
|
_mapCount += batchReport.MapReports.Count;
|
|
_failedMapCount += batchReport.MapDigest.FailedReports.Count();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// This class hold the validation reports for a batch, which comprises of all the maps in the batch.
|
|
/// </summary>
|
|
public class BatchReport
|
|
{
|
|
private readonly AssetValidator<Map> _mapValidator = new AssetValidator<Map>();
|
|
|
|
public ShotgunBatch Batch { get; set; }
|
|
|
|
public AssetValidator<Map> MapDigest => _mapValidator;
|
|
|
|
public List<AssetReport<Map>> MapReports => _mapValidator.AssetReports;
|
|
|
|
public void GenerateBatchReport(IExecutionContext context, MapList mapList)
|
|
{
|
|
_mapValidator.RunValidations(context, mapList, tryToFix: false);
|
|
}
|
|
}
|
|
} |