private void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _subscription?.Dispose(); _traceWriter?.Dispose(); } _disposedValue = true; } }
public static void WarmUp(WebHostSettings settings) { var traceWriter = new FileTraceWriter(Path.Combine(settings.LogPath, "Host"), TraceLevel.Info); ScriptHost host = null; try { traceWriter.Info("Warm up started"); string rootPath = settings.ScriptPath; if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } Directory.CreateDirectory(rootPath); string content = ReadResourceString("Functions.host.json"); File.WriteAllText(Path.Combine(rootPath, "host.json"), content); // read in the C# function string functionPath = Path.Combine(rootPath, "Test-CSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_CSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_CSharp.run.csx"); File.WriteAllText(Path.Combine(functionPath, "run.csx"), content); // read in the F# function functionPath = Path.Combine(rootPath, "Test-FSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_FSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_FSharp.run.fsx"); File.WriteAllText(Path.Combine(functionPath, "run.fsx"), content); traceWriter.Info("Warm up functions deployed"); ScriptHostConfiguration config = new ScriptHostConfiguration { RootScriptPath = rootPath, FileLoggingMode = FileLoggingMode.Never, RootLogPath = settings.LogPath, TraceWriter = traceWriter, FileWatchingEnabled = false }; config.HostConfig.StorageConnectionString = null; config.HostConfig.DashboardConnectionString = null; host = ScriptHost.Create(ScriptSettingsManager.Instance, config); traceWriter.Info(string.Format("Starting Host (Id={0})", host.ScriptConfig.HostConfig.HostId)); host.Start(); var arguments = new Dictionary<string, object> { { "input", "{}" } }; host.CallAsync("Test-CSharp", arguments).Wait(); host.CallAsync("Test-FSharp", arguments).Wait(); host.Stop(); traceWriter.Info("Warm up succeeded"); } catch (Exception ex) { traceWriter.Error(string.Format("Warm up failed: {0}", ex)); } finally { host?.Dispose(); traceWriter.Dispose(); } }
public static void WarmUp(WebHostSettings settings) { var traceWriter = new FileTraceWriter(Path.Combine(settings.LogPath, "Host"), TraceLevel.Info); ScriptHost host = null; try { traceWriter.Info("Warm up started"); string rootPath = settings.ScriptPath; if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } Directory.CreateDirectory(rootPath); string content = ReadResourceString("Functions.host.json"); File.WriteAllText(Path.Combine(rootPath, "host.json"), content); // read in the C# function string functionPath = Path.Combine(rootPath, "Test-CSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_CSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_CSharp.run.csx"); File.WriteAllText(Path.Combine(functionPath, "run.csx"), content); // read in the F# function functionPath = Path.Combine(rootPath, "Test-FSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_FSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_FSharp.run.fsx"); File.WriteAllText(Path.Combine(functionPath, "run.fsx"), content); traceWriter.Info("Warm up functions deployed"); ScriptHostConfiguration config = new ScriptHostConfiguration { RootScriptPath = rootPath, FileLoggingMode = FileLoggingMode.Never, RootLogPath = settings.LogPath, TraceWriter = traceWriter, FileWatchingEnabled = false }; config.HostConfig.StorageConnectionString = null; config.HostConfig.DashboardConnectionString = null; host = ScriptHost.Create(config); traceWriter.Info(string.Format("Starting Host (Id={0})", host.ScriptConfig.HostConfig.HostId)); host.Start(); var arguments = new Dictionary <string, object> { { "input", "{}" } }; host.CallAsync("Test-CSharp", arguments).Wait(); host.CallAsync("Test-FSharp", arguments).Wait(); host.Stop(); traceWriter.Info("Warm up succeeded"); } catch (Exception ex) { traceWriter.Error(string.Format("Warm up failed: {0}", ex)); } finally { host?.Dispose(); traceWriter.Dispose(); } }