diff --git a/Torch.API/Utils/IsExternalInit.cs b/Torch.API/Utils/IsExternalInit.cs deleted file mode 100644 index 58e2c72..0000000 --- a/Torch.API/Utils/IsExternalInit.cs +++ /dev/null @@ -1,8 +0,0 @@ -#if NETFRAMEWORK -// ReSharper disable once CheckNamespace -namespace System.Runtime.CompilerServices; - -public class IsExternalInit -{ -} -#endif diff --git a/Torch.API/WebAPI/PluginQuery.cs b/Torch.API/WebAPI/PluginQuery.cs index 4309dde..d095be3 100644 --- a/Torch.API/WebAPI/PluginQuery.cs +++ b/Torch.API/WebAPI/PluginQuery.cs @@ -78,11 +78,7 @@ namespace Torch.API.WebAPI if(File.Exists(path)) File.Delete(path); -#if NETFRAMEWORK - using var f = File.Create(path); -#else await using var f = File.Create(path); -#endif await s.CopyToAsync(f); } catch (Exception ex) diff --git a/Torch.Server/Managers/EntityControlManager.cs b/Torch.Server/Managers/EntityControlManager.cs index d5500ba..b121fdf 100644 --- a/Torch.Server/Managers/EntityControlManager.cs +++ b/Torch.Server/Managers/EntityControlManager.cs @@ -40,13 +40,7 @@ namespace Torch.Server.Managers protected abstract EntityControlViewModel Create(EntityViewModel evm); -#if NETFRAMEWORK - [ReflectedGetter(Name = "Keys")] - private static readonly Func, ICollection> WeakTableKeys = null!; - internal IEnumerable Keys => WeakTableKeys(_models); -#else internal IEnumerable Keys => _models.Select(b => b.Key); -#endif internal EntityControlViewModel GetOrCreate(EntityViewModel evm) { diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index 35ab007..c5faf61 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -221,12 +221,10 @@ namespace Torch.Server LogManager.Flush(); string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe"); -#if NETFRAMEWORK - config.WaitForPID = Process.GetCurrentProcess().Id.ToString(); -#else + config.WaitForPID = Environment.ProcessId.ToString(); -#endif config.TempAutostart = true; + Process.Start(exe, config.ToString()); Environment.Exit(0); @@ -374,11 +372,8 @@ namespace Torch.Server // return stack.ToString(); // Modified from https://www.examplefiles.net/cs/579311 -#if NETFRAMEWORK - using var target = DataTarget.CreateSnapshotAndAttach(Process.GetCurrentProcess().Id); -#else using var target = DataTarget.CreateSnapshotAndAttach(Environment.ProcessId); -#endif + var runtime = target.ClrVersions[0].CreateRuntime(); var clrThread = runtime.Threads.First(b => b.ManagedThreadId == thread.ManagedThreadId); diff --git a/Torch.Server/UnhandledExceptionHandler.cs b/Torch.Server/UnhandledExceptionHandler.cs index 7353719..f252aa7 100644 --- a/Torch.Server/UnhandledExceptionHandler.cs +++ b/Torch.Server/UnhandledExceptionHandler.cs @@ -32,11 +32,9 @@ internal class UnhandledExceptionHandler Console.WriteLine("Restarting in 5 seconds."); Thread.Sleep(5000); var exe = typeof(Program).Assembly.Location; -#if NETFRAMEWORK - _config.WaitForPID = Process.GetCurrentProcess().Id.ToString(); -#else + _config.WaitForPID = Environment.ProcessId.ToString(); -#endif + Process.Start(exe, _config.ToString()); } else diff --git a/Torch/Utils/TorchLauncher.cs b/Torch/Utils/TorchLauncher.cs index 93a8fed..7f58b70 100644 --- a/Torch/Utils/TorchLauncher.cs +++ b/Torch/Utils/TorchLauncher.cs @@ -17,13 +17,8 @@ namespace Torch.Utils try { var name = AssemblyName.GetAssemblyName(file); - var key = name.Name ?? name.FullName.Split(',')[0]; -#if NETFRAMEWORK - if (!Assemblies.ContainsKey(key)) - Assemblies.Add(key, file); -#else + var key = name.Name ?? name.FullName[..',']; Assemblies.TryAdd(key, file); -#endif } catch (BadImageFormatException) { @@ -37,7 +32,7 @@ namespace Torch.Utils private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args) { var name = args.Name; - return Assemblies.TryGetValue(name.IndexOf(',') > 0 ? name.Substring(0, name.IndexOf(',')) : name, out var path) ? Assembly.LoadFrom(path) : null; + return Assemblies.TryGetValue(name.IndexOf(',') > 0 ? name[..','] : name, out var path) ? Assembly.LoadFrom(path) : null; } } } diff --git a/Torch/Utils/TorchLogManager.cs b/Torch/Utils/TorchLogManager.cs index bfe67cb..963e1cf 100644 --- a/Torch/Utils/TorchLogManager.cs +++ b/Torch/Utils/TorchLogManager.cs @@ -13,9 +13,7 @@ namespace Torch.Utils; public static class TorchLogManager { -#if !NETFRAMEWORK - private static AssemblyLoadContext LoadContext = new("TorchLog"); -#endif + private static readonly AssemblyLoadContext LoadContext = new("TorchLog"); public static LoggingConfiguration Configuration { get; private set; } @@ -31,11 +29,7 @@ public static class TorchLogManager if (!Directory.Exists(dir)) return; foreach (var type in Directory.EnumerateFiles(dir, "*.dll") -#if NETFRAMEWORK - .Select(Assembly.LoadFile) -#else .Select(LoadContext.LoadFromAssemblyPath) -#endif .SelectMany(b => b.ExportedTypes) .Where(b => b.GetCustomAttribute() is { })) {