added config

This commit is contained in:
Matteo Cominetti
2020-06-30 23:20:18 +01:00
parent 0b24ab0881
commit 0913b9952b
9 changed files with 118 additions and 82 deletions
+3 -3
View File
@@ -26,10 +26,10 @@ namespace xUnitRevit
Application app = sender as Application;
UIApplication uiapp = new UIApplication(app);
Runner.ReadConfig();
// uiapp.OpenAndActivateDocument(@"C:\Code\Speckle-Next\SpeckleKitRevit\TestModels\Walls.rvt");
TestRunner.Launch(uiapp);
if(Runner.Config.autoStart)
Runner.Launch(uiapp);
}
+1 -1
View File
@@ -29,7 +29,7 @@ namespace xUnitRevit
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
TestRunner.Launch(uiapp);
Runner.Launch(uiapp);
return Result.Succeeded;
+17
View File
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace xUnitRevit
{
/// <summary>
/// Simple configuration file for lazy developers
/// </summary>
public class Configuration
{
public List<string> startupAssemblies { get; set; } = new List<string>();
public bool autoStart { get; set; } = false;
}
}
+59
View File
@@ -0,0 +1,59 @@
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit.Runner.Wpf;
using Xunit.Runner.Wpf.ViewModel;
using xUnitRevitUtils;
using System.Web.Script.Serialization;
using System.IO;
namespace xUnitRevit
{
public static class Runner
{
internal static Configuration Config = new Configuration();
internal static void Launch(UIApplication uiapp)
{
try
{
var queue = new List<Action>();
var eventHandler = ExternalEvent.Create(new ExternalEventHandler(queue));
xru.Initialize(uiapp, SynchronizationContext.Current, eventHandler, queue);
var main = new MainWindow();
main.Title = "xUnit Revit by Speckle";
//pre-load asssemblies, if you're a lazy developer
(main.DataContext as MainViewModel).StartupAssemblies = Config.startupAssemblies;
main.Show();
}
catch (Exception e)
{
//fail silently
}
}
internal static void ReadConfig()
{
try
{
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var path = Path.Combine(dir, "config.json");
JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer();
var json = File.ReadAllText(path);
Config = JavaScriptSerializer.Deserialize<Configuration>(json);
}
catch
{}
}
}
}
-76
View File
@@ -1,76 +0,0 @@
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit.Runner.Wpf;
using Xunit.Runner.Wpf.ViewModel;
using xUnitRevitUtils;
namespace xUnitRevit
{
public static class TestRunner
{
public static void Launch(UIApplication uiapp)
{
try
{
var queue = new List<Action>();
var eventHandler = ExternalEvent.Create(new ExternalEventHandler(queue));
xru.Initialize(uiapp, SynchronizationContext.Current, eventHandler, queue);
var main = new MainWindow();
main.Title = "xUnit Revit by Speckle";
/// (main.DataContext as MainViewModel).Injector =
(main.DataContext as MainViewModel).StartupAssemblies = new List<string>() { @"C:\Code\Speckle-Next\SpeckleKitRevit\SpeckleRevitTests\bin\Debug\SpeckleRevitTests.dll" };
main.Show();
}
catch (Exception e)
{
}
//return Result.Succeeded;
}
}
//public class Injector : IAssemblyInjector
//{
// private UIApplication uiapp { get; set; }
// SynchronizationContext uiContext { get; set; }
// private List<Action> queue { get; set; }
// private ExternalEvent eventHandler { get; set; }
// public Injector(UIApplication uiapp, SynchronizationContext uiContext, ExternalEvent eventHandler, List<Action> queue)
// {
// this.uiapp = uiapp;
// this.uiContext = uiContext;
// this.eventHandler = eventHandler;
// this.queue = queue;
// }
// public void Inject(Assembly assembly)
// {
// var types = assembly.GetTypes();
// foreach (var type in types)
// {
// if (type.Name == "xru")
// {
// if (type.GetProperties().Select(p => p.Name).Contains("Uiapp"))
// {
// type.GetProperty("Uiapp").SetValue(null, uiapp);
// type.GetProperty("UiContext").SetValue(null, uiContext);
// type.GetProperty("Queue").SetValue(null, queue);
// type.GetProperty("EventHandler").SetValue(null, eventHandler);
// }
// }
// }
// }
//}
}
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
+6
View File
@@ -0,0 +1,6 @@
{
"startupAssemblies": [
"C:\\Code\\Speckle-Next\\SpeckleKitRevit\\SpeckleRevitTests\\bin\\Debug\\SpeckleRevitTests.dll"
],
"autoStart": true
}
+8 -1
View File
@@ -55,17 +55,24 @@
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Web.Extensions" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.cs" />
<Compile Include="CmdAvailabilityViews.cs" />
<Compile Include="Command.cs" />
<Compile Include="Config.cs" />
<Compile Include="ExternalEventHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestRunner.cs" />
<Compile Include="Runner.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="xUnitRevit.addin" />
</ItemGroup>
<ItemGroup>