Revert "refactor(Dalamud): switch to file-scoped namespaces"

This reverts commit b5f34c3199.
This commit is contained in:
goat 2021-11-18 15:23:40 +01:00
parent d473826247
commit 1561fbac00
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
325 changed files with 45549 additions and 45209 deletions

View file

@ -11,245 +11,246 @@ using Dalamud.Logging.Internal;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
namespace Dalamud.Interface.Internal.Windows.SelfTest;
/// <summary>
/// Window for the Self-Test logic.
/// </summary>
internal class SelfTestWindow : Window
namespace Dalamud.Interface.Internal.Windows.SelfTest
{
private static readonly ModuleLog Log = new("AGING");
private readonly List<IAgingStep> steps =
new()
{
new LoginEventAgingStep(),
new WaitFramesAgingStep(1000),
new EnterTerritoryAgingStep(148, "Central Shroud"),
new ActorTableAgingStep(),
new FateTableAgingStep(),
new ConditionAgingStep(),
new ToastAgingStep(),
new TargetAgingStep(),
new KeyStateAgingStep(),
new GamepadStateAgingStep(),
new ChatAgingStep(),
new HoverAgingStep(),
new LuminaAgingStep<TerritoryType>(),
new PartyFinderAgingStep(),
new HandledExceptionAgingStep(),
new LogoutEventAgingStep(),
};
private readonly List<(SelfTestStepResult Result, TimeSpan? Duration)> stepResults = new();
private bool selfTestRunning = false;
private int currentStep = 0;
private DateTimeOffset lastTestStart;
/// <summary>
/// Initializes a new instance of the <see cref="SelfTestWindow"/> class.
/// Window for the Self-Test logic.
/// </summary>
public SelfTestWindow()
: base("Dalamud Self-Test", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
internal class SelfTestWindow : Window
{
this.Size = new Vector2(800, 800);
this.SizeCondition = ImGuiCond.FirstUseEver;
private static readonly ModuleLog Log = new("AGING");
this.RespectCloseHotkey = false;
}
/// <inheritdoc/>
public override void Draw()
{
if (this.selfTestRunning)
{
if (ImGuiComponents.IconButton(FontAwesomeIcon.Stop))
private readonly List<IAgingStep> steps =
new()
{
this.StopTests();
new LoginEventAgingStep(),
new WaitFramesAgingStep(1000),
new EnterTerritoryAgingStep(148, "Central Shroud"),
new ActorTableAgingStep(),
new FateTableAgingStep(),
new ConditionAgingStep(),
new ToastAgingStep(),
new TargetAgingStep(),
new KeyStateAgingStep(),
new GamepadStateAgingStep(),
new ChatAgingStep(),
new HoverAgingStep(),
new LuminaAgingStep<TerritoryType>(),
new PartyFinderAgingStep(),
new HandledExceptionAgingStep(),
new LogoutEventAgingStep(),
};
private readonly List<(SelfTestStepResult Result, TimeSpan? Duration)> stepResults = new();
private bool selfTestRunning = false;
private int currentStep = 0;
private DateTimeOffset lastTestStart;
/// <summary>
/// Initializes a new instance of the <see cref="SelfTestWindow"/> class.
/// </summary>
public SelfTestWindow()
: base("Dalamud Self-Test", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
{
this.Size = new Vector2(800, 800);
this.SizeCondition = ImGuiCond.FirstUseEver;
this.RespectCloseHotkey = false;
}
/// <inheritdoc/>
public override void Draw()
{
if (this.selfTestRunning)
{
if (ImGuiComponents.IconButton(FontAwesomeIcon.Stop))
{
this.StopTests();
}
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.StepForward))
{
this.stepResults.Add((SelfTestStepResult.NotRan, null));
this.currentStep++;
this.lastTestStart = DateTimeOffset.Now;
if (this.currentStep >= this.steps.Count)
{
this.StopTests();
}
}
}
else
{
if (ImGuiComponents.IconButton(FontAwesomeIcon.Play))
{
this.selfTestRunning = true;
this.currentStep = 0;
this.stepResults.Clear();
this.lastTestStart = DateTimeOffset.Now;
}
}
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.StepForward))
{
this.stepResults.Add((SelfTestStepResult.NotRan, null));
this.currentStep++;
this.lastTestStart = DateTimeOffset.Now;
ImGui.TextUnformatted($"Step: {this.currentStep} / {this.steps.Count}");
if (this.currentStep >= this.steps.Count)
ImGuiHelpers.ScaledDummy(10);
this.DrawResultTable();
ImGuiHelpers.ScaledDummy(10);
if (this.currentStep >= this.steps.Count)
{
if (this.selfTestRunning)
{
this.StopTests();
}
if (this.stepResults.Any(x => x.Result == SelfTestStepResult.Fail))
{
ImGui.TextColored(ImGuiColors.DalamudRed, "One or more checks failed!");
}
else
{
ImGui.TextColored(ImGuiColors.HealerGreen, "All checks passed!");
}
return;
}
}
else
{
if (ImGuiComponents.IconButton(FontAwesomeIcon.Play))
if (!this.selfTestRunning)
{
this.selfTestRunning = true;
this.currentStep = 0;
this.stepResults.Clear();
return;
}
ImGui.Separator();
var step = this.steps[this.currentStep];
ImGui.TextUnformatted($"Current: {step.Name}");
ImGuiHelpers.ScaledDummy(10);
SelfTestStepResult result;
try
{
result = step.RunStep();
}
catch (Exception ex)
{
Log.Error(ex, $"Step failed: {step.Name}");
result = SelfTestStepResult.Fail;
}
ImGui.Separator();
if (result != SelfTestStepResult.Waiting)
{
var duration = DateTimeOffset.Now - this.lastTestStart;
this.currentStep++;
this.stepResults.Add((result, duration));
this.lastTestStart = DateTimeOffset.Now;
}
}
ImGui.SameLine();
ImGui.TextUnformatted($"Step: {this.currentStep} / {this.steps.Count}");
ImGuiHelpers.ScaledDummy(10);
this.DrawResultTable();
ImGuiHelpers.ScaledDummy(10);
if (this.currentStep >= this.steps.Count)
private void DrawResultTable()
{
if (this.selfTestRunning)
if (ImGui.BeginTable("agingResultTable", 4, ImGuiTableFlags.Borders))
{
this.StopTests();
}
ImGui.TableSetupColumn("###index", ImGuiTableColumnFlags.WidthFixed, 12f);
ImGui.TableSetupColumn("Name");
ImGui.TableSetupColumn("Result", ImGuiTableColumnFlags.WidthFixed, 40f);
ImGui.TableSetupColumn("Duration", ImGuiTableColumnFlags.WidthFixed, 90f);
if (this.stepResults.Any(x => x.Result == SelfTestStepResult.Fail))
{
ImGui.TextColored(ImGuiColors.DalamudRed, "One or more checks failed!");
}
else
{
ImGui.TextColored(ImGuiColors.HealerGreen, "All checks passed!");
}
ImGui.TableHeadersRow();
return;
}
if (!this.selfTestRunning)
{
return;
}
ImGui.Separator();
var step = this.steps[this.currentStep];
ImGui.TextUnformatted($"Current: {step.Name}");
ImGuiHelpers.ScaledDummy(10);
SelfTestStepResult result;
try
{
result = step.RunStep();
}
catch (Exception ex)
{
Log.Error(ex, $"Step failed: {step.Name}");
result = SelfTestStepResult.Fail;
}
ImGui.Separator();
if (result != SelfTestStepResult.Waiting)
{
var duration = DateTimeOffset.Now - this.lastTestStart;
this.currentStep++;
this.stepResults.Add((result, duration));
this.lastTestStart = DateTimeOffset.Now;
}
}
private void DrawResultTable()
{
if (ImGui.BeginTable("agingResultTable", 4, ImGuiTableFlags.Borders))
{
ImGui.TableSetupColumn("###index", ImGuiTableColumnFlags.WidthFixed, 12f);
ImGui.TableSetupColumn("Name");
ImGui.TableSetupColumn("Result", ImGuiTableColumnFlags.WidthFixed, 40f);
ImGui.TableSetupColumn("Duration", ImGuiTableColumnFlags.WidthFixed, 90f);
ImGui.TableHeadersRow();
for (var i = 0; i < this.steps.Count; i++)
{
var step = this.steps[i];
ImGui.TableNextRow();
ImGui.TableSetColumnIndex(0);
ImGui.Text(i.ToString());
ImGui.TableSetColumnIndex(1);
ImGui.Text(step.Name);
ImGui.TableSetColumnIndex(2);
ImGui.PushFont(Interface.Internal.InterfaceManager.MonoFont);
if (this.stepResults.Count > i)
for (var i = 0; i < this.steps.Count; i++)
{
var result = this.stepResults[i];
var step = this.steps[i];
ImGui.TableNextRow();
switch (result.Result)
ImGui.TableSetColumnIndex(0);
ImGui.Text(i.ToString());
ImGui.TableSetColumnIndex(1);
ImGui.Text(step.Name);
ImGui.TableSetColumnIndex(2);
ImGui.PushFont(Interface.Internal.InterfaceManager.MonoFont);
if (this.stepResults.Count > i)
{
case SelfTestStepResult.Pass:
ImGui.TextColored(ImGuiColors.HealerGreen, "PASS");
break;
case SelfTestStepResult.Fail:
ImGui.TextColored(ImGuiColors.DalamudRed, "FAIL");
break;
default:
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
break;
}
}
else
{
if (this.selfTestRunning && this.currentStep == i)
{
ImGui.TextColored(ImGuiColors.DalamudGrey, "WAIT");
var result = this.stepResults[i];
switch (result.Result)
{
case SelfTestStepResult.Pass:
ImGui.TextColored(ImGuiColors.HealerGreen, "PASS");
break;
case SelfTestStepResult.Fail:
ImGui.TextColored(ImGuiColors.DalamudRed, "FAIL");
break;
default:
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
break;
}
}
else
{
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
if (this.selfTestRunning && this.currentStep == i)
{
ImGui.TextColored(ImGuiColors.DalamudGrey, "WAIT");
}
else
{
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
}
}
}
ImGui.PopFont();
ImGui.PopFont();
ImGui.TableSetColumnIndex(3);
if (this.stepResults.Count > i)
{
var (_, duration) = this.stepResults[i];
if (duration.HasValue)
ImGui.TableSetColumnIndex(3);
if (this.stepResults.Count > i)
{
ImGui.TextUnformatted(duration.Value.ToString("g"));
var (_, duration) = this.stepResults[i];
if (duration.HasValue)
{
ImGui.TextUnformatted(duration.Value.ToString("g"));
}
}
}
else
{
if (this.selfTestRunning && this.currentStep == i)
else
{
ImGui.TextUnformatted((DateTimeOffset.Now - this.lastTestStart).ToString("g"));
if (this.selfTestRunning && this.currentStep == i)
{
ImGui.TextUnformatted((DateTimeOffset.Now - this.lastTestStart).ToString("g"));
}
}
}
ImGui.EndTable();
}
ImGui.EndTable();
}
}
private void StopTests()
{
this.selfTestRunning = false;
foreach (var agingStep in this.steps)
private void StopTests()
{
try
this.selfTestRunning = false;
foreach (var agingStep in this.steps)
{
agingStep.CleanUp();
}
catch (Exception ex)
{
Log.Error(ex, $"Could not clean up AgingStep: {agingStep.Name}");
try
{
agingStep.CleanUp();
}
catch (Exception ex)
{
Log.Error(ex, $"Could not clean up AgingStep: {agingStep.Name}");
}
}
}
}