{
public static class AssemblyManager
{
+ public static AssemblyLoader CurrentAssemblyLoaderContext
+ {
+ get;
+ private set;
+ }
+
public static bool Launch(
[In] string rootPath,
[In] string path,
[In] int argc,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=2)]
+ [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
[In] string[] argv)
{
ALog.Debug($"Application Launch path : {path}");
try
{
- DirectoryInfo bindir = new DirectoryInfo(Path.Combine(rootPath, "bin"));
- DirectoryInfo libdir = new DirectoryInfo(Path.Combine(rootPath, "lib"));
- if (Directory.Exists(bindir.FullName))
+ DirectoryInfo binDir = new DirectoryInfo(Path.Combine(rootPath, "bin"));
+ DirectoryInfo libDir = new DirectoryInfo(Path.Combine(rootPath, "lib"));
+ if (Directory.Exists(binDir.FullName))
{
- CurrentAssemblyLoaderContext.AddSearchableDirectory(bindir.FullName);
+ CurrentAssemblyLoaderContext.AddSearchableDirectory(binDir.FullName);
}
- if (Directory.Exists(libdir.FullName))
+
+ if (Directory.Exists(libDir.FullName))
{
- CurrentAssemblyLoaderContext.AddSearchableDirectory(libdir.FullName);
+ CurrentAssemblyLoaderContext.AddSearchableDirectory(libDir.FullName);
}
+
Execute(path, argv);
}
- catch(Exception e)
+ catch (Exception e)
{
ALog.Debug("Exception in Launch()");
PrintException(e);
ALog.Debug($"Failed to Initialized");
}
}
- catch(Exception e)
+ catch (Exception e)
{
ALog.Debug("Exception at Preparing");
PrintException(e);
}
}
- private static void PrintException(Exception exception)
- {
- while (exception != null)
- {
- ALog.Debug(exception.ToString());
- exception = exception.InnerException;
- }
- }
-
public static void UnhandledExceptionHandler(object sender, object args)
{
TypeInfo unhandledExceptionEventArgsType =
{
try
{
- // Set UnhandledException handler with reflection
- // we must replace this to no reflection method after AppDomain is comming in used net standard
+ /// Set UnhandledException handler with reflection
+ /// we must replace this to no reflection method after AppDomain is comming in used net standard
TypeInfo appdomainType = Type.GetType("System.AppDomain").GetTypeInfo();
PropertyInfo currentDomain = appdomainType.GetProperty("CurrentDomain",
BindingFlags.Public | BindingFlags.Static);
EventInfo unhandledException = appdomainType.GetDeclaredEvent("UnhandledException");
- object appdomain = currentDomain.GetValue(null, null);
+ object appDomain = currentDomain.GetValue(null, null);
MethodInfo handlerInfo = typeof(AssemblyManager).GetTypeInfo().GetDeclaredMethod("UnhandledExceptionHandler");
Delegate handler = handlerInfo.CreateDelegate(unhandledException.EventHandlerType);
var addMethod = unhandledException.GetAddMethod(true);
- addMethod.Invoke(appdomain, new[] {handler});
+ addMethod.Invoke(appDomain, new[] {handler});
}
catch (Exception e)
{
PrintException(e);
return false;
}
+
return true;
}
{
Assembly asm = CurrentAssemblyLoaderContext.LoadFromPath(f.FullName);
- if (asm == null) throw new FileNotFoundException($"{f.FullName} is not found");
- if (asm.EntryPoint == null) throw new ArgumentException($"{f.FullName} did not have EntryPoint");
- asm.EntryPoint.Invoke(null, new object[]{argv});
+ if (asm == null)
+ {
+ throw new FileNotFoundException($"{f.FullName} is not found");
+ }
+
+ if (asm.EntryPoint == null)
+ {
+ throw new ArgumentException($"{f.FullName} did not have EntryPoint");
+ }
+
+ asm.EntryPoint.Invoke(null, new object[] {argv});
}
else
{
}
}
- public static AssemblyLoader CurrentAssemblyLoaderContext
+ private static void PrintException(Exception exception)
{
- get;
- private set;
+ while (exception != null)
+ {
+ ALog.Debug(exception.ToString());
+ exception = exception.InnerException;
+ }
}
}