Skip to content

Commit

Permalink
adding some changes to launch codes
Browse files Browse the repository at this point in the history
  • Loading branch information
andyopayne committed Aug 14, 2023
1 parent 73f2fde commit 1728e36
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/compute.geometry/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Program

static void Main(string[] args)
{
//Uncomment these two lines to attach to remote debugger
//Console.WriteLine("Waiting to attach to debugger...");
//Console.ReadLine();

Config.Load();
Logging.Init();

Expand Down
34 changes: 30 additions & 4 deletions src/compute.geometry/Resolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using compute.geometry;
using Serilog;

namespace RhinoInside
{
Expand All @@ -23,11 +25,35 @@ public static void Initialize()

// Force load WindowsBase from the WindowsDesktop set of assemblies
var path = typeof(int).Assembly.Location;
string directory =Path.GetDirectoryName(path);
//string directory = Path.GetDirectoryName(path);
//string directory = @"C:\dev\github\mcneel\compute.rhino3d\src\dist\compute.geometry";
string directory = @"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.5";
Log.Information($"Assembly Directory = {directory}");
int index = directory.IndexOf("NETCORE", StringComparison.OrdinalIgnoreCase);
directory = directory.Substring(0, index) + "WindowsDesktop" + directory.Substring(index + "NETCORE".Length);
string windowsBase = Path.Combine(directory, "WindowsBase.dll");
Assembly.LoadFrom(windowsBase);
if (index > -1)
{
directory = directory.Substring(0, index) + "WindowsDesktop" + directory.Substring(index + "NETCORE".Length);
string windowsBase = Path.Combine(directory, "WindowsBase.dll");
var assm = Assembly.LoadFrom(windowsBase);
}
else
{
DirectoryInfo dirInfo = new DirectoryInfo(directory);
try
{
var result = dirInfo.EnumerateFiles("WindowsBase.dll", SearchOption.AllDirectories);
if (result.FirstOrDefault() is FileInfo _windowsBase)
{
Log.Information($"Found WindowsBase.dll at {_windowsBase.FullName}");
Log.Information($"Confirmed to be running in self-contained mode");
var assembly = Assembly.LoadFrom(_windowsBase.FullName);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
}
}

static string _rhinoSystemDirectory;
Expand Down
3 changes: 3 additions & 0 deletions src/compute.geometry/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using Carter;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
Expand Down Expand Up @@ -41,7 +42,9 @@ public void Configure(IApplicationBuilder app)

void RhinoCoreStartup()
{
Log.Information("Entering RhinoCoreStartup Method...");
Program.RhinoCore = new Rhino.Runtime.InProcess.RhinoCore(null, Rhino.Runtime.InProcess.WindowStyle.NoWindow);
Log.Information("New RhinoCore Started...");
Environment.SetEnvironmentVariable("RHINO_TOKEN", null, EnvironmentVariableTarget.Process);
Rhino.Runtime.HostUtils.OnExceptionReport += (source, ex) => {
Log.Error(ex, "An exception occurred while processing request");
Expand Down
3 changes: 3 additions & 0 deletions src/compute.geometry/compute.geometry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<OutputPath>..\bin\Release\$(AssemblyName)</OutputPath>
<PublishDir>..\dist\$(AssemblyName)</PublishDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Optimize>True</Optimize>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Carter" Version="7.0.0" />
Expand Down

0 comments on commit 1728e36

Please sign in to comment.