remove compat for netframework
This commit is contained in:
@@ -1,8 +0,0 @@
|
|||||||
#if NETFRAMEWORK
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
public class IsExternalInit
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
@@ -78,11 +78,7 @@ namespace Torch.API.WebAPI
|
|||||||
if(File.Exists(path))
|
if(File.Exists(path))
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
|
||||||
using var f = File.Create(path);
|
|
||||||
#else
|
|
||||||
await using var f = File.Create(path);
|
await using var f = File.Create(path);
|
||||||
#endif
|
|
||||||
await s.CopyToAsync(f);
|
await s.CopyToAsync(f);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@@ -40,13 +40,7 @@ namespace Torch.Server.Managers
|
|||||||
|
|
||||||
protected abstract EntityControlViewModel Create(EntityViewModel evm);
|
protected abstract EntityControlViewModel Create(EntityViewModel evm);
|
||||||
|
|
||||||
#if NETFRAMEWORK
|
|
||||||
[ReflectedGetter(Name = "Keys")]
|
|
||||||
private static readonly Func<ConditionalWeakTable<EntityViewModel, EntityControlViewModel>, ICollection<EntityViewModel>> WeakTableKeys = null!;
|
|
||||||
internal IEnumerable<EntityViewModel> Keys => WeakTableKeys(_models);
|
|
||||||
#else
|
|
||||||
internal IEnumerable<EntityViewModel> Keys => _models.Select(b => b.Key);
|
internal IEnumerable<EntityViewModel> Keys => _models.Select(b => b.Key);
|
||||||
#endif
|
|
||||||
|
|
||||||
internal EntityControlViewModel GetOrCreate(EntityViewModel evm)
|
internal EntityControlViewModel GetOrCreate(EntityViewModel evm)
|
||||||
{
|
{
|
||||||
|
@@ -221,12 +221,10 @@ namespace Torch.Server
|
|||||||
LogManager.Flush();
|
LogManager.Flush();
|
||||||
|
|
||||||
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
|
string exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe");
|
||||||
#if NETFRAMEWORK
|
|
||||||
config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
|
|
||||||
#else
|
|
||||||
config.WaitForPID = Environment.ProcessId.ToString();
|
config.WaitForPID = Environment.ProcessId.ToString();
|
||||||
#endif
|
|
||||||
config.TempAutostart = true;
|
config.TempAutostart = true;
|
||||||
|
|
||||||
Process.Start(exe, config.ToString());
|
Process.Start(exe, config.ToString());
|
||||||
|
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
@@ -374,11 +372,8 @@ namespace Torch.Server
|
|||||||
// return stack.ToString();
|
// return stack.ToString();
|
||||||
|
|
||||||
// Modified from https://www.examplefiles.net/cs/579311
|
// 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);
|
using var target = DataTarget.CreateSnapshotAndAttach(Environment.ProcessId);
|
||||||
#endif
|
|
||||||
var runtime = target.ClrVersions[0].CreateRuntime();
|
var runtime = target.ClrVersions[0].CreateRuntime();
|
||||||
|
|
||||||
var clrThread = runtime.Threads.First(b => b.ManagedThreadId == thread.ManagedThreadId);
|
var clrThread = runtime.Threads.First(b => b.ManagedThreadId == thread.ManagedThreadId);
|
||||||
|
@@ -32,11 +32,9 @@ internal class UnhandledExceptionHandler
|
|||||||
Console.WriteLine("Restarting in 5 seconds.");
|
Console.WriteLine("Restarting in 5 seconds.");
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
var exe = typeof(Program).Assembly.Location;
|
var exe = typeof(Program).Assembly.Location;
|
||||||
#if NETFRAMEWORK
|
|
||||||
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
|
|
||||||
#else
|
|
||||||
_config.WaitForPID = Environment.ProcessId.ToString();
|
_config.WaitForPID = Environment.ProcessId.ToString();
|
||||||
#endif
|
|
||||||
Process.Start(exe, _config.ToString());
|
Process.Start(exe, _config.ToString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -17,13 +17,8 @@ namespace Torch.Utils
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var name = AssemblyName.GetAssemblyName(file);
|
var name = AssemblyName.GetAssemblyName(file);
|
||||||
var key = name.Name ?? name.FullName.Split(',')[0];
|
var key = name.Name ?? name.FullName[..','];
|
||||||
#if NETFRAMEWORK
|
|
||||||
if (!Assemblies.ContainsKey(key))
|
|
||||||
Assemblies.Add(key, file);
|
|
||||||
#else
|
|
||||||
Assemblies.TryAdd(key, file);
|
Assemblies.TryAdd(key, file);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
catch (BadImageFormatException)
|
catch (BadImageFormatException)
|
||||||
{
|
{
|
||||||
@@ -37,7 +32,7 @@ namespace Torch.Utils
|
|||||||
private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
|
private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
|
||||||
{
|
{
|
||||||
var name = args.Name;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,9 +13,7 @@ namespace Torch.Utils;
|
|||||||
|
|
||||||
public static class TorchLogManager
|
public static class TorchLogManager
|
||||||
{
|
{
|
||||||
#if !NETFRAMEWORK
|
private static readonly AssemblyLoadContext LoadContext = new("TorchLog");
|
||||||
private static AssemblyLoadContext LoadContext = new("TorchLog");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public static LoggingConfiguration Configuration { get; private set; }
|
public static LoggingConfiguration Configuration { get; private set; }
|
||||||
|
|
||||||
@@ -31,11 +29,7 @@ public static class TorchLogManager
|
|||||||
if (!Directory.Exists(dir)) return;
|
if (!Directory.Exists(dir)) return;
|
||||||
|
|
||||||
foreach (var type in Directory.EnumerateFiles(dir, "*.dll")
|
foreach (var type in Directory.EnumerateFiles(dir, "*.dll")
|
||||||
#if NETFRAMEWORK
|
|
||||||
.Select(Assembly.LoadFile)
|
|
||||||
#else
|
|
||||||
.Select(LoadContext.LoadFromAssemblyPath)
|
.Select(LoadContext.LoadFromAssemblyPath)
|
||||||
#endif
|
|
||||||
.SelectMany(b => b.ExportedTypes)
|
.SelectMany(b => b.ExportedTypes)
|
||||||
.Where(b => b.GetCustomAttribute<TargetAttribute>() is { }))
|
.Where(b => b.GetCustomAttribute<TargetAttribute>() is { }))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user