Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.4.0 #53

Merged
merged 15 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.4.0] / 2024-09-05
### Features
- Support `NUnit.Timeout` option to abort application. (default '10' minutes) (Fix: #51)
- Autoclose `VIEWER MODE` warning dialog box when Revit starts. (Fix: #52)
### Application
- Add `DialogBoxResolver` to cancel dialog box before revit initialization.
### Console
- Change `TimeoutMinutesDefault` to 10 minutes in the `RevitTestUtils`.
- Remove deprecated `wait` option and `RevitDebugUtils`.
- Add `Timeout` option to abort application.
- Fail all tests when `Timeout` happen.
- Update execution/timeout message in the log.
### Command
- Add `RevitTestProcessStart` to run tests with `ProcessStart`.
- Remove deprecated `wait` option.
- Add `Timeout` option to abort application.
### TestAdapter
- Add project `ricaun.RevitTest.Command` with `ricaun.NUnit`
- Remove references `CommandLineParser` and `NUnit` not used.
- Use `RevitTestProcessStartUtils` to start the process.
- Add `NUnit.Timeout` option to timeout the application.

## [1.3.6] / 2024-08-30
### TestAdapter
- Remove log in the `LocalFileExists` in the `ApplicationUtils`.
Expand Down Expand Up @@ -451,6 +473,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [x] TestsFail

[vNext]: ../../compare/1.0.0...HEAD
[1.4.0]: ../../compare/1.3.6...1.4.0
[1.3.6]: ../../compare/1.3.5...1.3.6
[1.3.5]: ../../compare/1.3.4...1.3.5
[1.3.4]: ../../compare/1.3.3...1.3.4
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.3.6</Version>
<Version>1.4.0</Version>
</PropertyGroup>
</Project>
5 changes: 3 additions & 2 deletions README.old.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ For more information see [Wiki](https://github.com/ricaun-io/ricaun.RevitTest/wi
* [ricaun.Revit.UI.Tasks](https://github.com/ricaun-io/ricaun.Revit.UI.Tasks)
* [ricaun.Revit.UI.Busy](https://github.com/ricaun-io/ricaun.Revit.UI.Busy)
* [ricaun.RevitTest.Shared](ricaun.RevitTest.Shared)
#### Command
* [ricaun.NUnit](https://github.com/ricaun-io/ricaun.NUnit)
#### Console
* [ricaun.Revit.Installation](https://github.com/ricaun-io/ricaun.Revit.Installation)
* [ricaun.RevitTest.Command](ricaun.RevitTest.Command)
* [ricaun.RevitTest.Shared](ricaun.RevitTest.Shared)
* [ricaun.RevitTest.Application.bundle.zip](ricaun.RevitTest.Application)
#### Command
* [ricaun.NUnit](https://github.com/ricaun-io/ricaun.NUnit)
#### Shared
* [ricaun.NUnit](https://github.com/ricaun-io/ricaun.NUnit)
* [NamedPipeWrapper.Json](https://github.com/ricaun-io/named-pipe-wrapper-json)
#### TestAdapter
* [ricaun.RevitTest.Console.exe](ricaun.RevitTest.Console)
* [ricaun.RevitTest.Command](ricaun.RevitTest.Command)
* [ricaun.Security.WinTrust](https://github.com/ricaun-io/ricaun.Security.WinTrust)

## CommandLine
Expand Down
7 changes: 6 additions & 1 deletion ricaun.RevitTest.Application/Revit/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class App : IExternalApplication
private static PipeTestServer PipeTestServer;
private static RevitTaskService RevitTask;
private static RevitBusyService RevitBusyService;
private static DialogBoxResolver DialogBoxResolver;
private static bool IsTestRunning = false;

private const int TestThreadSleepMin = 50;
Expand All @@ -38,6 +39,9 @@ public Result OnStartup(UIControlledApplication application)
RevitTask = new RevitTaskService(application);
RevitTask.Initialize();

DialogBoxResolver = new DialogBoxResolver(application);
DialogBoxResolver.Initialize();

Log.WriteLine();
Log.WriteLine($"{AppUtils.GetInfo()}");

Expand Down Expand Up @@ -219,9 +223,10 @@ public Result OnShutdown(UIControlledApplication application)
});

ribbonPanel?.Remove();

PipeTestServer?.Dispose();
RevitBusyService?.Dispose();

DialogBoxResolver?.Dispose();
RevitTask?.Dispose();

Log.Finish();
Expand Down
64 changes: 64 additions & 0 deletions ricaun.RevitTest.Application/Revit/Utils/DialogBoxResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Autodesk.Revit.UI;
using System;

namespace ricaun.RevitTest.Application.Revit.Utils
{
/// <summary>
/// DialogBoxResolver resolve the dialog box by DialogId and override the result to cancel.
/// </summary>
/// <remarks>The resolver only works before Revit initialize.</remarks>
public class DialogBoxResolver : IDisposable
{
private readonly UIControlledApplication application;
private readonly string[] TaskDialogIds;
public DialogBoxResolver(UIControlledApplication application)
{
this.application = application;
this.TaskDialogIds = new string[]
{
"TaskDialog_License_Current_Status_Demo_Mode", // Viewer Mode
"TaskDialog_DNSMTemplate" // Revit Warning
};
}

/// <summary>
/// Initialize the events to resolve the dialog box.
/// </summary>
/// <remarks>The Initialize is ignored if the <see cref="Autodesk.Revit.UI.UIControlledApplication.IsLateAddinLoading"/>.</remarks>
public virtual void Initialize()
{
if (this.application.IsLateAddinLoading) return;
Dispose();
this.application.DialogBoxShowing += OnDialogBoxShowing;
this.application.ControlledApplication.ApplicationInitialized += OnApplicationInitialized;
}

/// <summary>
/// Dispose the events.
/// </summary>
public virtual void Dispose()
{
this.application.DialogBoxShowing -= OnDialogBoxShowing;
this.application.ControlledApplication.ApplicationInitialized -= OnApplicationInitialized;
}

private void OnDialogBoxShowing(object sender, Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs e)
{
if (TaskDialogIds is null) return;
foreach (var dialogId in TaskDialogIds)
{
if (dialogId == e.DialogId)
{
Console.WriteLine($"{nameof(DialogBoxResolver)}: [{e.DialogId}]");
e.OverrideResult((int)TaskDialogResult.Cancel);
return;
}
}
}
private void OnApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
{
Dispose();
}
}

}
2 changes: 1 addition & 1 deletion ricaun.RevitTest.Command/Command/IRunTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public bool RunTests(
Action<string> actionOutput = null,
string forceLanguageToRevit = null,
bool forceToOpenNewRevit = false,
bool forceToWaitRevit = false,
bool forceToCloseRevit = false,
int timeoutMinutes = 0,
params string[] testFilters);
}
}
10 changes: 5 additions & 5 deletions ricaun.RevitTest.Command/Command/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ private static Parser CreateParser()
HelpText = "Force to open a new Revit process.")]
public bool ForceToOpen { get; set; }

[Option("wait",
Default = false,
HelpText = "Force to wait after test done.")]
public bool ForceToWait { get; set; }

[Option("close",
Default = false,
HelpText = "Force to close the Revit process.")]
public bool ForceToClose { get; set; }

[Option("timeout",
Default = 0,
HelpText = "Timeout in minutes to abort this application.")]
public int Timeout { get; set; }

[Option("debugger",
Default = false,
Hidden = true,
Expand Down
7 changes: 4 additions & 3 deletions ricaun.RevitTest.Command/Command/RunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ricaun.RevitTest.Command.Extensions;
using ricaun.NUnit;
using ricaun.RevitTest.Command.Extensions;
using ricaun.RevitTest.Command.Utils;
using System;
using System.IO;
Expand Down Expand Up @@ -30,7 +31,7 @@ private void ValidadeOptions()

private void Initialize()
{
NUnit.TestEngine.Initialize(out string init);
TestEngine.Initialize(out string init);

Log.WriteLine();
Log.WriteLine($"{AppUtils.GetInfo()} [{init}]");
Expand Down Expand Up @@ -77,8 +78,8 @@ private bool RunOrReadTests()
outputAction,
options.RevitLanguage,
options.ForceToOpen,
options.ForceToWait,
options.ForceToClose,
options.Timeout,
options.Test.ToArray());

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text;
using System.Text.RegularExpressions;

namespace ricaun.RevitTest.TestAdapter.Services
namespace ricaun.RevitTest.Command.Extensions
{
/// <summary>
/// EncodeParameterArgumentExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using ricaun.RevitTest.Command.Extensions;

namespace ricaun.RevitTest.TestAdapter.Services
namespace ricaun.RevitTest.Command.Process
{
internal class ProcessStart
public class ProcessStart
{
protected virtual void WriteLine(string message)
{
Debug.WriteLine(message);
}

private const int DelayAfterExit = 100;
private string processPath;
private Dictionary<string, object> argumentsPair = new Dictionary<string, object>();
Expand Down Expand Up @@ -46,11 +52,11 @@ string ConvertValue(object value)
arguments += $"{ConvertKey(item.Key)} ";
arguments += $"{ConvertValue(item.Value)} ";
}
AdapterLogger.Logger.Debug($"\tCreateArguments: {arguments}");
WriteLine($"\tCreateArguments: {arguments}");
return arguments;
}

public ProcessStart SetArgument(string name, object value = null)
protected ProcessStart SetArgument(string name, object value = null)
{
argumentsPair[name] = value;
return this;
Expand All @@ -76,53 +82,23 @@ private ProcessStartInfo NewProcessStartInfo(string arguments)
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
//StandardOutputEncoding = System.Text.Encoding.UTF8,
//StandardErrorEncoding = System.Text.Encoding.UTF8,
};
}


public async Task<string> Run()
{
var arguments = CreateArguments();
Debug.WriteLine($"Run: {arguments}");
return await Run(arguments);
}

public async Task Run(Action<string> consoleAction, Action<string> errorAction = null)
{
var arguments = CreateArguments();
Debug.WriteLine($"Run: {arguments}");

AdapterLogger.Logger.DebugOnlyLocal($"ProcessStart: {processPath}");
AdapterLogger.Logger.DebugOnlyLocal($"ProcessStart.Run: {arguments}");

foreach (var item in System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(processPath)))
{
AdapterLogger.Logger.DebugOnlyLocal($"ProcessStart.File: {item}");
}

WriteLine($"ProcessStart: {processPath}");
WriteLine($"ProcessStart.Run: {arguments}");
await Run(arguments, consoleAction, errorAction);
}

private async Task<string> Run(string arguments)
{
if (string.IsNullOrEmpty(processPath)) return string.Empty;
var psi = NewProcessStartInfo(arguments);
var process = Process.Start(psi);
var output = await process.StandardOutput.ReadToEndAsync();
//var error = await process.StandardError.ReadToEndAsync();
process.WaitForExit(int.MaxValue);
return output;
}

private async Task Run(string arguments,
Action<string> consoleAction = null,
Action<string> errorAction = null)
{
if (string.IsNullOrEmpty(processPath)) return;
var psi = NewProcessStartInfo(arguments);
var process = Process.Start(psi);
var process = System.Diagnostics.Process.Start(psi);
process.OutputDataReceived += (sender, e) =>
{
consoleAction?.Invoke(e.Data);
Expand Down
Loading