public void SetUp() { SetupEvent.WaitOne(); adminService = CreateAdminService(storeType); IServiceConnector connector = CreateConnector(); NetworkConfigSource config = new NetworkConfigSource(); Config(config); adminService.Config = config; adminService.Connector = connector; adminService.Start(); networkProfile = new NetworkProfile(connector); NetworkConfigSource netConfig = new NetworkConfigSource(); netConfig.AddNetworkNode(LocalAddress); networkProfile.Configuration = netConfig; OnSetUp(); SetupEvent.Set(); }
protected override void Config(ConfigSource config) { base.Config(config); NetworkConfigSource networkConfig = (NetworkConfigSource)config; networkConfig.AddAllowedIp("localhost"); networkConfig.AddAllowedIp("127.0.0.1"); networkConfig.AddAllowedIp("::1"); }
public void SetUp() { SetupEvent.WaitOne(); IServiceConnector connector = CreateConnector(); adminService = CreateAdminService(storeType); NetworkConfigSource config = new NetworkConfigSource(); Config(config); adminService.Config = config; adminService.Connector = connector; adminService.Start(); networkProfile = new NetworkProfile(connector); NetworkConfigSource netConfig = new NetworkConfigSource(); netConfig.AddNetworkNode(LocalAddress); networkProfile.Configuration = netConfig; SetupEvent.Set(); }
private static int Main(string[] args) { string nodeConfig = null, netConfig = null; string hostArg = null, portArg = null; StringWriter wout = new StringWriter(); Options options = GetOptions(); CommandLine commandLine = null; bool failed = false; bool isService = false; try { ICommandLineParser parser = new GnuParser(options); commandLine = parser.Parse(args); nodeConfig = commandLine.GetOptionValue("nodeconfig", "./node.conf"); netConfig = commandLine.GetOptionValue("netconfig", "./network.conf"); hostArg = commandLine.GetOptionValue("host"); portArg = commandLine.GetOptionValue("port"); } catch (ParseException) { wout.WriteLine("Error parsing arguments."); failed = true; } if (commandLine != null) { if (commandLine.HasOption("install")) { try { Install(commandLine); Console.Out.WriteLine("Service installed succesfully."); return(0); } catch (Exception e) { Console.Error.WriteLine("Error installing service: " + e.Message); #if DEBUG Console.Error.WriteLine(e.StackTrace); #endif return(1); } } if (commandLine.HasOption("uninstall")) { try { Uninstall(); Console.Out.WriteLine("Service uninstalled succesfully."); return(0); } catch (Exception e) { Console.Error.WriteLine("Error uninstalling service: " + e.Message); #if DEBUG Console.Error.WriteLine(e.StackTrace); #endif return(1); } } isService = commandLine.HasOption("service"); } if (isService) { MachineNodeService mnodeService = new MachineNodeService(commandLine); try { if (Environment.UserInteractive) { mnodeService.Start(args); Console.Out.WriteLine("Press any key to stop..."); Console.Read(); mnodeService.Stop(); } else { ServiceBase.Run(mnodeService); } } catch (Exception) { return(1); } return(0); } AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException); SetEventHandlers(); ProductInfo libInfo = ProductInfo.GetProductInfo(typeof(TcpAdminService)); ProductInfo nodeInfo = ProductInfo.GetProductInfo(typeof(MachineNode)); Console.Out.WriteLine("{0} {1} ( {2} )", nodeInfo.Title, nodeInfo.Version, nodeInfo.Copyright); Console.Out.WriteLine(nodeInfo.Description); Console.Out.WriteLine(); Console.Out.WriteLine("{0} {1} ( {2} )", libInfo.Title, libInfo.Version, libInfo.Copyright); // Check arguments that can be null, if (netConfig == null) { wout.WriteLine("Error, no network configuration given."); failed = true; } else if (nodeConfig == null) { wout.WriteLine("Error, no node configuration file given."); failed = true; } //if (portArg == null) { // wout.WriteLine("Error, no port address given."); // failed = true; //} if (!failed) { //TODO: support for remote (eg. HTTP, FTP, TCP/IP) configurations) nodeConfig = NormalizeFilePath(nodeConfig); netConfig = NormalizeFilePath(netConfig); if (!File.Exists(nodeConfig)) { wout.WriteLine("Error, node configuration file not found ({0}).", nodeConfig); failed = true; } else if (!File.Exists(netConfig)) { wout.WriteLine("Error, node configuration file not found ({0}).", netConfig); failed = true; } } wout.Flush(); // If failed, if (failed) { HelpFormatter formatter = new HelpFormatter(); if (!IsConsoleRedirected()) { formatter.Width = Console.WindowWidth; } formatter.CommandLineSyntax = "mnode"; formatter.Options = options; formatter.PrintHelp(); Console.Out.WriteLine(); Console.Out.WriteLine(wout.ToString()); return(1); } try { #if DEBUG Console.Out.WriteLine("Retrieving node configuration from {0}", nodeConfig); #endif // Get the node configuration file, ConfigSource nodeConfigSource = new ConfigSource(); using (FileStream fin = new FileStream(nodeConfig, FileMode.Open, FileAccess.Read, FileShare.None)) { //TODO: make it configurable ... nodeConfigSource.LoadProperties(new BufferedStream(fin)); } #if DEBUG Console.Out.WriteLine("Retrieving network configuration from {0}", netConfig); #endif // Parse the network configuration string, NetworkConfigSource netConfigSource; using (FileStream stream = new FileStream(netConfig, FileMode.Open, FileAccess.Read, FileShare.None)) { netConfigSource = new NetworkConfigSource(); //TODO: make it configurable ... netConfigSource.LoadProperties(stream); } string password = nodeConfigSource.GetString("network_password", null); if (password == null) { Console.Out.WriteLine("Error: couldn't determine the network password."); return(1); } // configure the loggers Logger.Init(nodeConfigSource); //TODO: support also IPv6 // The base path, IPAddress host = null; if (hostArg != null) { IPAddress[] addresses = Dns.GetHostAddresses(hostArg); for (int i = 0; i < addresses.Length; i++) { IPAddress address = addresses[i]; if (address.AddressFamily == AddressFamily.InterNetwork) { host = address; break; } } } else { host = IPAddress.Loopback; } if (host == null) { Console.Out.WriteLine("Error: couldn't determine the host address."); return(1); } int port = DefaultPort; if (!String.IsNullOrEmpty(portArg)) { if (!Int32.TryParse(portArg, out port)) { Console.Out.WriteLine("Error: couldn't parse port argument: " + portArg); return(1); } } string storage = commandLine.GetOptionValue("storage", null); IServiceFactory serviceFactory = GetServiceFactory(storage, nodeConfigSource); Console.Out.WriteLine("Machine Node, " + host + " : " + port); service = new TcpAdminService(serviceFactory, host, port, password); service.Config = netConfigSource; service.Start(); Console.Out.WriteLine(); Console.Out.WriteLine(); Console.Out.WriteLine("Press CTRL+C to quit..."); waitHandle = new AutoResetEvent(false); waitHandle.WaitOne(); } catch (Exception e) { Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.StackTrace); return(1); } finally { if (service != null) { service.Dispose(); } } return(0); }
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args) { if (Application.ActiveContext != null && Application.ActiveContext.IsIsolated) { Error.WriteLine("a context is already opened: try to disconnect first"); Error.WriteLine(); return CommandResultCode.ExecutionFailed; } if (!args.MoveNext()) return CommandResultCode.SyntaxError; if (args.Current != "to") return CommandResultCode.SyntaxError; if (!args.MoveNext()) return CommandResultCode.SyntaxError; string address = args.Current; IServiceAddress serviceAddress; try { serviceAddress = ServiceAddresses.ParseString(address); } catch(Exception) { Error.WriteLine("Invalid service address specified: {0}", address); return CommandResultCode.ExecutionFailed; } NetworkConfigSource configSource = new NetworkConfigSource(); try { configSource.AddNetworkNode(serviceAddress); } catch(Exception e) { Error.WriteLine("The address '" + address + "' is invalid: " + e.Message); return CommandResultCode.ExecutionFailed; } string protocol = "tcp"; string credentials = String.Empty; string format = "binary"; if (args.MoveNext()) { if (args.Current == "identified") { if (!args.MoveNext()) return CommandResultCode.SyntaxError; if (args.Current != "by") return CommandResultCode.SyntaxError; if (!args.MoveNext()) return CommandResultCode.SyntaxError; credentials = args.Current; if (args.MoveNext()) { if (args.Current != "on") return CommandResultCode.SyntaxError; protocol = args.Current; if (args.MoveNext()) { if (args.Current != "with") return CommandResultCode.SyntaxError; format = args.Current; } } } else if (args.Current == "on") { if (!args.MoveNext()) return CommandResultCode.SyntaxError; protocol = args.Current; if (args.MoveNext()) { if (args.Current != "with") return CommandResultCode.SyntaxError; format = args.Current; } } else if (args.Current == "with") { if (!args.MoveNext()) return CommandResultCode.SyntaxError; format = args.Current; } else { return CommandResultCode.SyntaxError; } } IServiceConnector connector; if (protocol == "tcp") { if (String.IsNullOrEmpty(credentials)) { while(String.IsNullOrEmpty(credentials = Readline.ReadPassword("password: "******"please provide a valid password..."); } Out.WriteLine(); } connector = new TcpServiceConnector(credentials); } else if (protocol == "http") { string userName = credentials; string password = null; int index = credentials.IndexOf(':'); if (index != -1) { password = credentials.Substring(index + 1); userName = credentials.Substring(0, index); } if (String.IsNullOrEmpty(password)) { while(String.IsNullOrEmpty(password = Readline.ReadPassword("password: "******"please provide a valid password..."); } Out.WriteLine(); } connector = new HttpServiceConnector(userName, password); } else { return CommandResultCode.SyntaxError; } IMessageSerializer serializer; if (format == "binary") { serializer = new BinaryRpcMessageSerializer(); } else if (format == "xml") { serializer = new XmlRpcMessageSerializer(); } else if (format == "json") { if (JsonRpcMessageSerializer == null) { Error.WriteLine("JSON serializer was not installed."); Error.WriteLine(); return CommandResultCode.ExecutionFailed; } serializer = JsonRpcMessageSerializer; } else { return CommandResultCode.SyntaxError; } connector.MessageSerializer = serializer; NetworkProfile networkProfile = new NetworkProfile(connector); networkProfile.Configuration = configSource; //TODO: test the connection is correct ... ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile)); Out.WriteLine("connected successfully to {0}" , address); Out.WriteLine(); return CommandResultCode.Success; }
public override bool HandleCommandLine(CommandLine commandLine) { string protocol = commandLine.GetOptionValue("protocol", "tcp"); string address = commandLine.GetOptionValue("address", null); string format = commandLine.GetOptionValue("format", "binary"); if (String.IsNullOrEmpty(address)) return false; IServiceConnector connector; if (protocol.Equals("tcp", StringComparison.InvariantCultureIgnoreCase)) { string netPassword = commandLine.GetOptionValue("password"); if (String.IsNullOrEmpty(netPassword)) throw new ArgumentException("Netwrok password required for TCP/IP protocol."); connector = new TcpServiceConnector(netPassword); } else if (protocol.Equals("http", StringComparison.InvariantCultureIgnoreCase)) { string user = commandLine.GetOptionValue("user"); string password = commandLine.GetOptionValue("password"); if (String.IsNullOrEmpty(user)) throw new ArgumentException("User name not specified. for HTTP connection."); if (String.IsNullOrEmpty(password)) throw new ArgumentException("Password not specofoed for HTTP connection."); connector = new HttpServiceConnector(user, password); } else { throw new ArgumentException("Invalid protocol '" + protocol + "'."); } IMessageSerializer serializer; if (format.Equals("xml", StringComparison.InvariantCultureIgnoreCase)) { serializer = new XmlRpcMessageSerializer(); } else if (format.Equals("binary", StringComparison.InvariantCultureIgnoreCase)) { serializer = new BinaryRpcMessageSerializer(); } else if (format.Equals("json", StringComparison.InvariantCultureIgnoreCase)) { if (JsonRpcMessageSerializer == null) throw new ApplicationException("The JSON serializer was not installed."); serializer = JsonRpcMessageSerializer; } else { throw new ArgumentException("Invalid message format."); } connector.MessageSerializer = serializer; NetworkProfile networkProfile = new NetworkProfile(connector); NetworkConfigSource configSource = new NetworkConfigSource(); configSource.AddNetworkNode(address); networkProfile.Configuration = configSource; ((CloudAdmin) Application).SetNetworkContext(new NetworkContext(networkProfile)); return true; }
private static int Main(string[] args) { string nodeConfig = null, netConfig = null; string hostArg = null, portArg = null; StringWriter wout = new StringWriter(); Options options = GetOptions(); CommandLine commandLine = null; bool failed = false; bool isService = false; try { ICommandLineParser parser = new GnuParser(options); commandLine = parser.Parse(args); nodeConfig = commandLine.GetOptionValue("nodeconfig", "./node.conf"); netConfig = commandLine.GetOptionValue("netconfig", "./network.conf"); hostArg = commandLine.GetOptionValue("host"); portArg = commandLine.GetOptionValue("port"); } catch (ParseException) { wout.WriteLine("Error parsing arguments."); failed = true; } if (commandLine != null) { if (commandLine.HasOption("install")) { try { Install(commandLine); Console.Out.WriteLine("Service installed succesfully."); return 0; } catch (Exception e) { Console.Error.WriteLine("Error installing service: " + e.Message); #if DEBUG Console.Error.WriteLine(e.StackTrace); #endif return 1; } } if (commandLine.HasOption("uninstall")) { try { Uninstall(); Console.Out.WriteLine("Service uninstalled succesfully."); return 0; } catch (Exception e) { Console.Error.WriteLine("Error uninstalling service: " + e.Message); #if DEBUG Console.Error.WriteLine(e.StackTrace); #endif return 1; } } isService = commandLine.HasOption("service"); } if (isService) { MachineNodeService mnodeService = new MachineNodeService(commandLine); try { if (Environment.UserInteractive) { mnodeService.Start(args); Console.Out.WriteLine("Press any key to stop..."); Console.Read(); mnodeService.Stop(); } else { ServiceBase.Run(mnodeService); } } catch(Exception) { return 1; } return 0; } AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException); SetEventHandlers(); ProductInfo libInfo = ProductInfo.GetProductInfo(typeof (TcpAdminService)); ProductInfo nodeInfo = ProductInfo.GetProductInfo(typeof (MachineNode)); Console.Out.WriteLine("{0} {1} ( {2} )", nodeInfo.Title, nodeInfo.Version, nodeInfo.Copyright); Console.Out.WriteLine(nodeInfo.Description); Console.Out.WriteLine(); Console.Out.WriteLine("{0} {1} ( {2} )", libInfo.Title, libInfo.Version, libInfo.Copyright); // Check arguments that can be null, if (netConfig == null) { wout.WriteLine("Error, no network configuration given."); failed = true; } else if (nodeConfig == null) { wout.WriteLine("Error, no node configuration file given."); failed = true; } if (portArg == null) { wout.WriteLine("Error, no port address given."); failed = true; } if (!failed) { //TODO: support for remote (eg. HTTP, FTP, TCP/IP) configurations) nodeConfig = NormalizeFilePath(nodeConfig); netConfig = NormalizeFilePath(netConfig); if (!File.Exists(nodeConfig)) { wout.WriteLine("Error, node configuration file not found ({0}).", nodeConfig); failed = true; } else if (!File.Exists(netConfig)) { wout.WriteLine("Error, node configuration file not found ({0}).", netConfig); failed = true; } } wout.Flush(); // If failed, if (failed) { HelpFormatter formatter = new HelpFormatter(); if (!IsConsoleRedirected()) { formatter.Width = Console.WindowWidth; } formatter.CommandLineSyntax = "mnode"; formatter.Options = options; formatter.PrintHelp(); Console.Out.WriteLine(); Console.Out.WriteLine(wout.ToString()); return 1; } try { #if DEBUG Console.Out.WriteLine("Retrieving node configuration from {0}", nodeConfig); #endif // Get the node configuration file, ConfigSource nodeConfigSource = new ConfigSource(); using (FileStream fin = new FileStream(nodeConfig, FileMode.Open, FileAccess.Read, FileShare.None)) { //TODO: make it configurable ... nodeConfigSource.LoadProperties(new BufferedStream(fin)); } #if DEBUG Console.Out.WriteLine("Retrieving network configuration from {0}", netConfig); #endif // Parse the network configuration string, NetworkConfigSource netConfigSource; using (FileStream stream = new FileStream(netConfig, FileMode.Open, FileAccess.Read, FileShare.None)) { netConfigSource = new NetworkConfigSource(); //TODO: make it configurable ... netConfigSource.LoadProperties(stream); } string password = nodeConfigSource.GetString("network_password", null); if (password == null) { Console.Out.WriteLine("Error: couldn't determine the network password."); return 1; } // configure the loggers Logger.Init(nodeConfigSource); //TODO: support also IPv6 // The base path, IPAddress host = null; if (hostArg != null) { IPAddress[] addresses = Dns.GetHostAddresses(hostArg); for (int i = 0; i < addresses.Length; i++) { IPAddress address = addresses[i]; if (address.AddressFamily == AddressFamily.InterNetwork) { host = address; break; } } } else { host = IPAddress.Loopback; } if (host == null) { Console.Out.WriteLine("Error: couldn't determine the host address."); return 1; } int port; if (!Int32.TryParse(portArg, out port)) { Console.Out.WriteLine("Error: couldn't parse port argument: " + portArg); return 1; } string storage = commandLine.GetOptionValue("storage", null); IServiceFactory serviceFactory = GetServiceFactory(storage, nodeConfigSource); Console.Out.WriteLine("Machine Node, " + host + " : " + port); service = new TcpAdminService(serviceFactory, host, port, password); service.Config = netConfigSource; service.Start(); waitHandle = new AutoResetEvent(false); waitHandle.WaitOne(); } catch (Exception e) { Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.StackTrace); return 1; } finally { if (service != null) service.Dispose(); } return 0; }
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args) { if (Application.ActiveContext != null && Application.ActiveContext.IsIsolated) { Error.WriteLine("a context is already opened: try to disconnect first"); Error.WriteLine(); return(CommandResultCode.ExecutionFailed); } if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } if (args.Current != "to") { return(CommandResultCode.SyntaxError); } if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } string address = args.Current; IServiceAddress serviceAddress; try { serviceAddress = ServiceAddresses.ParseString(address); } catch (Exception) { Error.WriteLine("Invalid service address specified: {0}", address); return(CommandResultCode.ExecutionFailed); } NetworkConfigSource configSource = new NetworkConfigSource(); try { configSource.AddNetworkNode(serviceAddress); } catch (Exception e) { Error.WriteLine("The address '" + address + "' is invalid: " + e.Message); return(CommandResultCode.ExecutionFailed); } string protocol = "tcp"; string credentials = String.Empty; string format = "binary"; if (args.MoveNext()) { if (args.Current == "identified") { if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } if (args.Current != "by") { return(CommandResultCode.SyntaxError); } if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } credentials = args.Current; if (args.MoveNext()) { if (args.Current != "on") { return(CommandResultCode.SyntaxError); } protocol = args.Current; if (args.MoveNext()) { if (args.Current != "with") { return(CommandResultCode.SyntaxError); } format = args.Current; } } } else if (args.Current == "on") { if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } protocol = args.Current; if (args.MoveNext()) { if (args.Current != "with") { return(CommandResultCode.SyntaxError); } format = args.Current; } } else if (args.Current == "with") { if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } format = args.Current; } else { return(CommandResultCode.SyntaxError); } } IServiceConnector connector; if (protocol == "tcp") { if (String.IsNullOrEmpty(credentials)) { while (String.IsNullOrEmpty(credentials = Readline.ReadPassword("password: "******"please provide a valid password..."); } Out.WriteLine(); } connector = new TcpServiceConnector(credentials); } else if (protocol == "http") { string userName = credentials; string password = null; int index = credentials.IndexOf(':'); if (index != -1) { password = credentials.Substring(index + 1); userName = credentials.Substring(0, index); } if (String.IsNullOrEmpty(password)) { while (String.IsNullOrEmpty(password = Readline.ReadPassword("password: "******"please provide a valid password..."); } Out.WriteLine(); } // TODO: connector = new HttpServiceConnector(userName, password); Out.WriteLine("Not supported yet."); return(CommandResultCode.ExecutionFailed); } else { return(CommandResultCode.SyntaxError); } IMessageSerializer serializer; if (format == "binary") { serializer = new BinaryRpcMessageSerializer(); } else if (format == "xml") { //TODO: serializer = new XmlRpcMessageSerializer(); return(CommandResultCode.ExecutionFailed); } else if (format == "json") { if (JsonRpcMessageSerializer == null) { Error.WriteLine("JSON serializer was not installed."); Error.WriteLine(); return(CommandResultCode.ExecutionFailed); } serializer = JsonRpcMessageSerializer; } else { return(CommandResultCode.SyntaxError); } connector.MessageSerializer = serializer; NetworkProfile networkProfile = new NetworkProfile(connector); networkProfile.Configuration = configSource; //TODO: test the connection is correct ... ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile)); Out.WriteLine("connected successfully to {0}", address); Out.WriteLine(); return(CommandResultCode.Success); }
public override bool HandleCommandLine(CommandLine commandLine) { string protocol = commandLine.GetOptionValue("protocol", "tcp"); string address = commandLine.GetOptionValue("address", null); string format = commandLine.GetOptionValue("format", "binary"); if (String.IsNullOrEmpty(address)) { return(false); } IServiceConnector connector; if (protocol.Equals("tcp", StringComparison.InvariantCultureIgnoreCase)) { string netPassword = commandLine.GetOptionValue("password"); if (String.IsNullOrEmpty(netPassword)) { throw new ArgumentException("Netwrok password required for TCP/IP protocol."); } connector = new TcpServiceConnector(netPassword); } else if (protocol.Equals("http", StringComparison.InvariantCultureIgnoreCase)) { string user = commandLine.GetOptionValue("user"); string password = commandLine.GetOptionValue("password"); if (String.IsNullOrEmpty(user)) { throw new ArgumentException("User name not specified. for HTTP connection."); } if (String.IsNullOrEmpty(password)) { throw new ArgumentException("Password not specofoed for HTTP connection."); } //TODO: connector = new HttpServiceConnector(user, password); throw new NotSupportedException("HTTP not supported yet."); } else { throw new ArgumentException("Invalid protocol '" + protocol + "'."); } IMessageSerializer serializer; if (format.Equals("xml", StringComparison.InvariantCultureIgnoreCase)) { //TODO: serializer = new XmlRpcMessageSerializer(); throw new NotSupportedException("XML format not supported yet."); } else if (format.Equals("binary", StringComparison.InvariantCultureIgnoreCase)) { serializer = new BinaryRpcMessageSerializer(); } else if (format.Equals("json", StringComparison.InvariantCultureIgnoreCase)) { if (JsonRpcMessageSerializer == null) { throw new ApplicationException("The JSON serializer was not installed."); } serializer = JsonRpcMessageSerializer; } else { throw new ArgumentException("Invalid message format."); } connector.MessageSerializer = serializer; NetworkProfile networkProfile = new NetworkProfile(connector); NetworkConfigSource configSource = new NetworkConfigSource(); configSource.AddNetworkNode(address); networkProfile.Configuration = configSource; ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile)); return(true); }
protected override void OnStart(string[] args) { eventLog.WriteEntry("Starting the service.", EventLogEntryType.Information); string nodeConfig, netConfig; string hostArg, portArg; try { nodeConfig = commandLine.GetOptionValue("nodeconfig", "node.conf"); netConfig = commandLine.GetOptionValue("netconfig", "network.conf"); hostArg = commandLine.GetOptionValue("host"); portArg = commandLine.GetOptionValue("port"); } catch (ParseException e) { eventLog.WriteEntry("Parse Error: " + e.Message, EventLogEntryType.Error); ExitCode = 1; throw new ApplicationException("Invalid arguments passed."); } try { // Get the node configuration file, ConfigSource nodeConfigSource = new ConfigSource(); using (FileStream fin = new FileStream(nodeConfig, FileMode.Open, FileAccess.Read, FileShare.None)) { nodeConfigSource.LoadProperties(new BufferedStream(fin)); } // Parse the network configuration string, NetworkConfigSource netConfigSource; using (FileStream stream = new FileStream(netConfig, FileMode.Open, FileAccess.Read, FileShare.None)) { netConfigSource = new NetworkConfigSource(); //TODO: make it configurable ... netConfigSource.LoadProperties(stream); } string password = nodeConfigSource.GetString("network_password", null); if (password == null) { throw new ApplicationException("Error: couldn't determine the network password."); } // configure the loggers Logger.Init(nodeConfigSource); //TODO: support also IPv6 // The base path, IPAddress host = null; if (hostArg != null) { IPAddress[] addresses = Dns.GetHostAddresses(hostArg); for (int i = 0; i < addresses.Length; i++) { IPAddress address = addresses[i]; if (address.AddressFamily == AddressFamily.InterNetwork) { host = address; break; } } } else { host = IPAddress.Loopback; } if (host == null) { throw new ApplicationException("Could not determine the host address."); } int port; if (!Int32.TryParse(portArg, out port)) { throw new ApplicationException("Error: couldn't parse port argument: " + portArg); } string storage = commandLine.GetOptionValue("storage", null); IServiceFactory serviceFactory = GetServiceFactory(storage, nodeConfigSource); service = new TcpAdminService(serviceFactory, host, port, password); service.Config = netConfigSource; service.Start(); eventLog.WriteEntry("TCP/IP service started successfully: " + host + ":" + port, EventLogEntryType.Information); eventLog.WriteEntry("Storage system: " + storage); } catch (Exception e) { if (service != null) { service.Dispose(); } eventLog.WriteEntry("Error on start: " + e.Message, EventLogEntryType.Error); throw; } }