private static string GetServiceCommandLine(CommandLine commandLine) { bool nodeConfigFound = false, netConfigFound = false; Option[] options = commandLine.Options; List<Option> normOptions = new List<Option>(options.Length); for (int i = 0; i < options.Length; i++) { Option opt = options[i]; if ((opt.Name == "user" || opt.LongName == "user") || (opt.Name == "user" || opt.LongName == "password") || (opt.Name == "service" || opt.LongName == "service") || (opt.Name == "install" || opt.LongName == "install")) continue; if (opt.Name == "nodeconfig" || opt.LongName == "nodeconfig") { nodeConfigFound = true; } else if (opt.Name == "netconfig" || opt.LongName == "netconfig") { netConfigFound = true; } normOptions.Add(opt); } if (!nodeConfigFound) normOptions.Add(new Option("nodeconfig", true, "")); if (!netConfigFound) normOptions.Add(new Option("netconfig", true, "")); StringBuilder sb = new StringBuilder(); for (int i = 0; i < normOptions.Count; i++) { Option opt = normOptions[i]; sb.Append("-"); if (opt.HasLongName) { sb.Append("-"); sb.Append(opt.LongName); } else { sb.Append(opt.Name); } if (opt.HasArgument) { sb.Append(" "); string value; if (opt.Name == "netconfig") { value = NormalizeFilePath(commandLine.GetOptionValue(opt.Name, "./network.conf")); } else if (opt.Name == "nodeconfig") { value = NormalizeFilePath(commandLine.GetOptionValue(opt.Name, "./node.conf")); } else { value = commandLine.GetOptionValue(opt.Name); } sb.Append(value); } if (i < normOptions.Count - 1) sb.Append(" "); } return sb.ToString(); }
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; }
public override bool HandleCommandLine(CommandLine commandLine) { if (commandLine.HasOption("file")) { string dir = commandLine.GetOptionValue("dir"); if (String.IsNullOrEmpty(dir)) dir = Environment.CurrentDirectory; ((TestApplication)Application).appDir = dir; return true; } return false; }