mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Prevent duplication of ErrorManager and TraceSettings handlers
This commit is contained in:
@@ -1,17 +1,76 @@
|
||||
using Microsoft.Iris.Asm;
|
||||
using Microsoft.Iris.Debug;
|
||||
using Microsoft.Iris.Markup;
|
||||
using Microsoft.Iris.Session;
|
||||
using System.Collections;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace UIX.Test.Fixtures;
|
||||
|
||||
public class MarkupSystemFixture : IDisposable
|
||||
{
|
||||
private ITestOutputHelper? _output;
|
||||
private static bool _handlersInitialized = false;
|
||||
|
||||
public MarkupSystemFixture()
|
||||
{
|
||||
string zuneDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Zune");
|
||||
if (Directory.Exists(zuneDirectory))
|
||||
{
|
||||
// Zune is installed, attempt to copy the required UIX dependencies
|
||||
var workingDirectory = Environment.CurrentDirectory;
|
||||
IEnumerable<string> irisDependencies = ["UIXRender.dll", "UIXControls.dll"];
|
||||
|
||||
foreach (string irisDependency in irisDependencies)
|
||||
{
|
||||
var dstFilePath = Path.Combine(workingDirectory, irisDependency);
|
||||
if (Path.Exists(dstFilePath))
|
||||
continue;
|
||||
|
||||
var srcFilePath = Path.Combine(zuneDirectory, irisDependency);
|
||||
if (!Path.Exists(srcFilePath))
|
||||
continue;
|
||||
|
||||
File.Copy(srcFilePath, dstFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
MarkupSystem.Startup(true);
|
||||
Assembler.RegisterLoader();
|
||||
}
|
||||
|
||||
public void Dispose() => MarkupSystem.Shutdown();
|
||||
public void SetupDebug(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
|
||||
if (!_handlersInitialized)
|
||||
{
|
||||
_handlersInitialized = true;
|
||||
ErrorManager.OnErrors += PrintMarkupErrors;
|
||||
TraceSettings.Current.OnWriteLine += PrintLine;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
MarkupSystem.Shutdown();
|
||||
ErrorManager.OnErrors -= PrintMarkupErrors;
|
||||
TraceSettings.Current.OnWriteLine -= PrintLine;
|
||||
}
|
||||
|
||||
private void PrintMarkupErrors(IList errors)
|
||||
{
|
||||
if (_output is null)
|
||||
return;
|
||||
|
||||
foreach (ErrorRecord error in errors)
|
||||
{
|
||||
var errorTypeText = error.Warning ? "Warning" : "Error";
|
||||
_output.WriteLine($"{errorTypeText} at (L{error.Line}, C{error.Column}): {error.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void PrintLine(string line) => _output?.WriteLine(line);
|
||||
}
|
||||
|
||||
[CollectionDefinition("MarkupSystem")]
|
||||
|
||||
Reference in New Issue
Block a user