/// <summary> /// Runs the main entry point method passing arguments to it /// </summary> /// <param name="args">The arguments.</param> /// <param name="logger">The logger.</param> /// <returns>System.Int32.</returns> /// <exception cref="System.InvalidOperationException">Must call TryLock before calling this method</exception> public int Run(string[] args, IServerLogger logger) { if (!isRunning) { throw new InvalidOperationException("Must call TryLock before calling this method"); } try { lastRunTime = DateTime.Now; using (var appDomainRedirectLogger = new AppDomainRedirectLogger(logger)) { appDomainCallback.Logger = appDomainRedirectLogger; appDomainCallback.Arguments = args; appDomain.DoCallBack(appDomainCallback.Run); var result = appDomainCallback.Result; //var result = appDomain.ExecuteAssembly(mainAssemblyPath, args); Console.WriteLine("Return result: {0}", result); return(result); } } catch (Exception exception) { logger.OnLog(string.Format("Unexpected exception: {0}", exception), ConsoleColor.Red); return(1); } finally { lastRunTime = DateTime.Now; } }
/// <summary> /// Runs the main entry point method passing arguments to it /// </summary> /// <param name="workingDirectory"></param> /// <param name="environmentVariables">The environment variables.</param> /// <param name="args">The arguments.</param> /// <param name="logger">The logger.</param> /// <returns>System.Int32.</returns> /// <exception cref="System.InvalidOperationException">Must call TryLock before calling this method</exception> public int Run(string workingDirectory, Dictionary<string, string> environmentVariables, string[] args, IServerLogger logger) { if (!isRunning) { throw new InvalidOperationException("Must call TryLock before calling this method"); } try { lastRunTime = DateTime.Now; using (var appDomainRedirectLogger = new AppDomainRedirectLogger(logger)) { appDomainCallback.Logger = appDomainRedirectLogger; appDomainCallback.CurrentDirectory = workingDirectory; appDomainCallback.EnvironmentVariables = environmentVariables; appDomainCallback.Arguments = args; appDomain.DoCallBack(appDomainCallback.Run); var result = appDomain.GetData("Result") as int?; //var result = appDomain.ExecuteAssembly(mainAssemblyPath, args); Console.WriteLine("Return result: {0}", result); return result ?? -1; } } catch (Exception exception) { logger.OnLog(string.Format("Unexpected exception: {0}", exception), ConsoleColor.Red); return 1; } finally { lastRunTime = DateTime.Now; } }