static public void Main() { try { //It is a good idea to call CSScript.Evaluator.Reset() between tests. //Though resetting is omitted in these samples to improve the readability. var host = new HostApp(); host.Eval_Returning_Result(); host.Eval_Void(); host.Eval_Void_With_Pure_Mono(); host.LoadCode(); host.LoadCode_With_Interface_Type_Casting(); host.LoadCode_With_Interface_Alignment(); host.LoadCode_With_Host_Referencing(); host.CompileCode_With_CSScript_CreateObject(); host.CompileCode_With_Assembly_CreateInstance(); host.LoadMethod(); host.LoadMethod_With_InterfaceAlignment(); host.LoadMethod_With_Host_Referencing(); host.CreateDelegate(); host.CodeDOM_Debug(); host.Evaluator_Debug(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
static Log4netIntegration() { try { var confFile = new FileInfo(HostApp.GetPath("log4net.config")); if (confFile.Exists) { XmlConfigurator.ConfigureAndWatch(LogRepository, confFile); } else { Configure(); } //检查Logs目录是否存在。docker下测试时无法自动创建。 var logPath = HostApp.GetPath(LogDir); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
static void Test() { var host = new HostApp(); host.CalcTest_InterfaceAlignment(); host.CalcTest_InterfaceInheritance(); host.HelloTest(); }
public NullLogger() { //检查Logs目录是否存在。 LogsDir = HostApp.GetPath("Logs"); if (!Directory.Exists(LogsDir)) { Directory.CreateDirectory(LogsDir); } }
private void Execute(string csScriptName) { var script1 = Path.Combine(_instance.GameInstanceConfiguration.StorageDataPath, "CsScript", csScriptName).LoadTextFile(); Host = new HostApp(); scriptObject = CSScript.LoadCode(script1) .CreateObject("*") .AlignToInterface <IGameScriptVpObject>(); scriptObject.GameVpObject = _vpObject; scriptObject.GameInstance = _instance; scriptObject.Initialize(); }
//默认配置代码 private static void Configure() { #region Appender RollingFileAppender CreateAppender(string file, int maxBackups) => new RollingFileAppender { Name = $"{file}Appender", File = HostApp.GetPath($"{LogDir}{Path.DirectorySeparatorChar}{file}.log"), RollingStyle = RollingFileAppender.RollingMode.Composite, DatePattern = "yyyy-MM-dd'.log'", MaximumFileSize = "200MB", MaxSizeRollBackups = maxBackups, //StaticLogFileName = false, AppendToFile = true, LockingModel = new FileAppender.MinimalLock(), Layout = GetLayout() }; var errorAppender = CreateAppender("error", 60); errorAppender.AddFilter(new LevelRangeFilter { LevelMin = Level.Error, LevelMax = Level.Fatal }); errorAppender.ActivateOptions(); var infoAppender = CreateAppender("info", 30); infoAppender.AddFilter(new LevelRangeFilter { LevelMin = Level.Info, LevelMax = Level.Warn }); infoAppender.ActivateOptions(); var debugAppender = CreateAppender("debug", 30); debugAppender.AddFilter(new LevelMatchFilter { LevelToMatch = Level.Debug }); debugAppender.AddFilter(new DenyAllFilter()); debugAppender.ActivateOptions(); var hierarchy = (Hierarchy)LogRepository; hierarchy.Root.AddAppender(errorAppender); hierarchy.Root.AddAppender(infoAppender); hierarchy.Root.AddAppender(debugAppender); #endregion hierarchy.Root.Level = Level.Debug; hierarchy.Configured = true; }
public static void CalcTest_InterfaceAlignment(HostApp host) { ICalc calc = CSScript.Evaluator .LoadMethod <ICalc>(@" public int Sum(int a, int b) { if(Host != null) Host.Log(""Sum is invoked""); return a + b; } public HostApp Host { get; set; }"); calc.Host = host; int result = calc.Sum(1, 2); }
public static void Test() { var host = new HostApp(); host.Log("CodeDOM Tests..."); CodeDom.HelloTest_1(); CodeDom.HelloTest_2(); CodeDom.CalcTest_InterfaceInheritance(host); CodeDom.CalcTest_InterfaceAlignment(host); host.Log("Mono CompilerAsService Tests..."); CompilerAsService.HelloTest_1(); CompilerAsService.HelloTest_2(); CompilerAsService.CalcTest_InterfaceInheritance(host); CompilerAsService.CalcTest_InterfaceAlignment(host); }
public static void CalcTest_InterfaceInheritance(HostApp host) { ICalc calc = (ICalc)CSScript.LoadCode(@"public class Script : ICalc { public int Sum(int a, int b) { if(Host != null) Host.Log(""Sum is invoked""); return a + b; } public HostApp Host { get; set; } }") .CreateObject("*"); calc.Host = host; int result = calc.Sum(1, 2); }
static void Main(string[] args) { //设置应用程序处理异常方式:ThreadException处理 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Console.WriteLine("Starting..."); string pluginFolder = ConfigurationManager.AppSettings["PluginFolder"]; pluginFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pluginFolder); if (!Directory.Exists(pluginFolder)) { Directory.CreateDirectory(pluginFolder); } HostApp.PlugMgr.LoadPlugins(AppDomain.CurrentDomain.BaseDirectory); HostApp.PlugMgr.LoadPlugins(pluginFolder); foreach (var item in Directory.EnumerateDirectories(pluginFolder)) { HostApp.PlugMgr.LoadPlugins(item); } foreach (string key in HostApp.PlugMgr.Plugins.Keys) { Console.WriteLine("Loaded Plugin: {0}", key); } // register exit event HostApp.Exited += HostApp_Exited; //Host startup try { HostApp.StartUp(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 导出Http请求信息并保存为文件 /// </summary> internal static void DumpRequestToFile(HttpRequest request, string dirName) { try { //var path = HostApp.GetPath("Logs/PayNotify_" + GatewayType); var path = HostApp.GetPath("Logs/" + dirName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, $"notify_{DateTime.Now:yyyy-MM-dd HH-mm-ss}.log"); File.AppendAllText(path, DumpRequest(request), Encoding.UTF8); } catch (Exception ex) { LogService.Error(ex); } }
void _fsw_Changed(object sender, FileSystemEventArgs e) { if (e.ChangeType == WatcherChangeTypes.Changed) { _fsw.EnableRaisingEvents = false; try { _instance.Say("changed"); } finally { _fsw.EnableRaisingEvents = true; } scriptObject.Unload(); scriptObject = null; Host = null; Execute(_csScriptName); } }
internal static string InnerGetAppSet(string key) { if (_configuration == null) { var builder = new ConfigurationBuilder().SetBasePath(HostApp.RootPath); var setFile = HostApp.GetPath(ConfSetFile); if (File.Exists(setFile)) { builder.AddJsonFile(setFile, optional: false, reloadOnChange: true); } else { LogService.WarnFormat($"缺少本地配置文件{ConfSetFile}"); } //.AddJsonFile($"appsettings.{EnvironmentName}.json", optional: true, reloadOnChange: true) //.AddEnvironmentVariables(); _configuration = builder.Build(); } return(_configuration[key]); }
public static void CalcTest_InterfaceAlignment(HostApp host) { ICalc calc = CSScript.Evaluator .LoadMethod<ICalc>(@" public int Sum(int a, int b) { if(Host != null) Host.Log(""Sum is invoked""); return a + b; } public HostApp Host { get; set; }"); calc.Host = host; int result = calc.Sum(1, 2); }
public void StartUpTest() { HostApp.PlugMgr.LoadPlugins(Directory.GetCurrentDirectory()); HostApp.StartUp(); Assert.AreEqual(2, HostApp.PlugMgr.Plugins.Count); }
private async Task <IEnumerable <TestResult> > Run_Internal(IEnumerable <TestCase> testCollection) { HostApp?.RaiseTestRunStarted(testCollection); var t = tcs = new CancellationTokenSource(); Status = $"Running tests..."; OnPropertyChanged(nameof(Status)); DiagnosticsInfo = ""; OnPropertyChanged(nameof(DiagnosticsInfo)); foreach (var item in testCollection) { tests[item.Id].Result = null; } OnPropertyChanged(nameof(TestStatus)); OnPropertyChanged(nameof(NotRunTests)); OnPropertyChanged(nameof(PassedTests)); OnPropertyChanged(nameof(FailedTests)); OnPropertyChanged(nameof(SkippedTests)); OnPropertyChanged(nameof(Percentage)); results = new List <TestResult>(); if (!string.IsNullOrEmpty(Settings.ProgressLogPath)) { var s = System.IO.File.OpenWrite(Settings.ProgressLogPath); logOutput = new System.IO.StreamWriter(s); // Settings.ProgressLogPath, true); logOutput.WriteLine("*************************************************"); logOutput.WriteLine($"* Starting Test Run @ {DateTime.Now}"); logOutput.WriteLine("*************************************************"); } if (!string.IsNullOrEmpty(Settings.TrxOutputPath)) { trxWriter = new TrxWriter(Settings.TrxOutputPath); trxWriter.InitializeReport(); } DateTime start = DateTime.Now; Logger.Log($"STARTING TESTRUN {testCollection.Count()} Tests"); var task = testRunner.Run(testCollection, t.Token); OnPropertyChanged(nameof(IsRunning)); try { await task; if (t.IsCancellationRequested) { Status = $"Test run canceled."; } else { Status = $"Test run completed."; } } catch (System.Exception ex) { Status = $"Test run failed to run: {ex.Message}"; } DateTime end = DateTime.Now; CurrentTestRunning = null; OnPropertyChanged(nameof(CurrentTestRunning)); if (logOutput != null) { Log("*************************************************"); Log(Status); Log(TestStatus); Log("*************************************************\n\n"); logOutput.Dispose(); logOutput = null; } if (trxWriter != null) { trxWriter.FinalizeReport(); trxWriter = null; } DiagnosticsInfo += $"\nLast run duration: {(end - start).ToString("c")}"; DiagnosticsInfo += $"\n{results.Where(a => a.Outcome == TestOutcome.Passed).Count()} passed - {results.Where(a => a.Outcome == TestOutcome.Failed).Count()} failed"; if (Settings.ProgressLogPath != null) { DiagnosticsInfo += $"\nLog: {Settings.ProgressLogPath}"; } if (Settings.TrxOutputPath != null) { DiagnosticsInfo += $"\nTRX Report: {Settings.TrxOutputPath}"; } OnPropertyChanged(nameof(DiagnosticsInfo)); OnPropertyChanged(nameof(IsRunning)); OnPropertyChanged(nameof(Status)); HostApp?.RaiseTestRunCompleted(results); Logger.Log($"COMPLETED TESTRUN Total:{results.Count()} Failed:{results.Where(a => a.Outcome == TestOutcome.Failed).Count()} Passed:{results.Where(a => a.Outcome == TestOutcome.Passed).Count()} Skipped:{results.Where(a => a.Outcome == TestOutcome.Skipped).Count()}"); if (Settings.TerminateAfterExecution) { Terminate(); } return(results); }
static void Main() { HostApp.Test(); }
public HostApp() { Instance = this; }