public static void Main(string[] args) { Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, (a, b) => true, false))); IWebHost host = null; try { var conf = new ExplorerConfiguration(); conf.LoadArgs(args); using (var runtime = conf.CreateRuntime()) { runtime.StartNodeListener(conf.StartHeight); host = runtime.CreateWebHost(); host.Run(); } } catch (ConfigException ex) { if (!string.IsNullOrEmpty(ex.Message)) { Logs.Configuration.LogError(ex.Message); } } catch (Exception exception) { Logs.Explorer.LogError("Exception thrown while running the server"); Logs.Explorer.LogError(exception.ToString()); } finally { if (host != null) { host.Dispose(); } } }
public ServerTester(string directory) { try { var rootTestData = "TestData"; var cachedNodes = "TestData/CachedNodes"; directory = rootTestData + "/" + directory; _Directory = directory; if (!Directory.Exists(rootTestData)) { Directory.CreateDirectory(rootTestData); } if (!Directory.Exists(cachedNodes)) { Directory.CreateDirectory(cachedNodes); RunScenario(cachedNodes); } if (!TryDelete(directory, false)) { foreach (var process in Process.GetProcessesByName("elementd")) { if (process.MainModule.FileName.Replace("\\", "/").StartsWith(Path.GetFullPath(rootTestData).Replace("\\", "/"), StringComparison.Ordinal)) { process.Kill(); process.WaitForExit(); } } TryDelete(directory, true); } NodeBuilder = NodeBuilder.Create(directory); NodeBuilder.CleanBeforeStartingNode = false; Copy(cachedNodes, directory); User1 = NodeBuilder.CreateNode(); User2 = NodeBuilder.CreateNode(); Explorer = NodeBuilder.CreateNode(); NodeBuilder.StartAll(); var creds = ExtractCredentials(File.ReadAllText(Explorer.Config)); var conf = new ExplorerConfiguration(); conf.DataDir = Path.Combine(directory, "explorer"); conf.Network = Network.RegTest; conf.RPC = new RPCArgs() { User = creds.Item1, Password = creds.Item2, Url = Explorer.CreateRPCClient().Address, NoTest = true }; conf.NodeEndpoint = Explorer.Endpoint; conf.Network = ExplorerConfiguration.CreateNetwork(conf.Network, Explorer.CreateRPCClient().GetBlock(0)); Runtime = conf.CreateRuntime(); Runtime.Repository.SetIndexProgress(new BlockLocator() { Blocks = { Runtime.RPC.GetBestBlockHash() } }); Runtime.StartNodeListener(conf.StartHeight); Host = Runtime.CreateWebHost(); Host.Start(); } catch { Dispose(); throw; } }