public CommandMenu() { _menuItems = new List <Command>(new[] { new Command("Exit", "Exits the application.", (a) => { _output.WriteLine("Exiting"); return(CommandResult.Exit); }), new Command("StartRPCClient", "Starts a default Thrift RPC agent", StartRpcClient), new Command("StopRPCClient", "Stops the default Thrift RPC agent", StopRpcClient), new Command("StartSimpleProducer", "Starts a simple producer", StartSimpleProducer), new Command("StopSimpleProducer", "Starts a simple producer", StopSimpleProducer), new Command("ConsumePurchase", "Consumes a service (first price of first service found)", ConsumePurchase), new Command("FindProducers", "Lists out all the producers that could be found", FindProducers), }); // TODO Parameterise these so output can be written to a specific file _output = Console.Out; _error = Console.Error; _reader = Console.In; _defaultAgentConfig = new RpcAgentConfiguration { ServicePort = 9091, CallbackPort = 9092, LogLevel = "panic,fatal,error,warn,info,debug", LogFile = new FileInfo("wpwithin.log") }; }
private CommandResult FindProducers(string[] arg) { RpcAgentConfiguration consumerConfig = new RpcAgentConfiguration { LogLevel = "panic,fatal,error,warn,info,debug", LogFile = new FileInfo("WPWithinConsumer.log"), ServicePort = 9096, }; RpcAgentManager consumerAgent = new RpcAgentManager(consumerConfig); consumerAgent.StartThriftRpcAgentProcess(); try { WPWithinService service = new WPWithinService(consumerConfig); service.SetupDevice("Scanner", $".NET Sample Producer scanner running on ${Dns.GetHostName()}"); List <ServiceMessage> devices = service.DeviceDiscovery(10000).ToList(); _output.WriteLine("Found total of {0} devices", devices.Count); for (int deviceIndex = 0; deviceIndex < devices.Count; deviceIndex++) { ServiceMessage device = devices[deviceIndex]; _output.WriteLine( $"Device {deviceIndex}) {device.ServerId} running on {device.Hostname}:{device.PortNumber}"); _output.WriteLine($"\tDescription: {device.DeviceDescription}, URL Prefix: {device.UrlPrefix}"); service.InitConsumer("http://", device.Hostname, device.PortNumber ?? 80, device.UrlPrefix, device.ServerId, new HceCard("Bilbo", "Baggins", "Card", "5555555555554444", 11, 2018, "113")); try { List <ServiceDetails> services = service.RequestServices().ToList(); _output.WriteLine("\t{0} services found on device {1}", services.Count, deviceIndex); for (int serviceIndex = 0; serviceIndex < services.Count; serviceIndex++) { ServiceDetails svc = services[serviceIndex]; _output.WriteLine($"\t\tService {serviceIndex}) {svc.ServiceId}: {svc.ServiceDescription}"); List <Price> prices = service.GetServicePrices(svc.ServiceId).ToList(); foreach (Price price in prices) { _output.WriteLine("\t\t\tPrice: {0}", price); } } } catch (Exception ex) { _error.WriteLine(ex); } } } finally { consumerAgent.StopThriftRpcAgentProcess(); } return(CommandResult.Success); }
public WPWithinService(RpcAgentConfiguration localAgentConfiguration) { InitClient(localAgentConfiguration); if (localAgentConfiguration.CallbackPort > 0) { _listener = new CallbackServerManager(localAgentConfiguration); _listener.Start(); } else { Log.Info("Callbacks disabled as port specified as 0"); } }
private void InitClient(RpcAgentConfiguration config) { TTransport transport = config.GetThriftTransport(); transport.Open(); TProtocol protocol = config.GetThriftProtcol(transport); ThriftWPWithinService.Client client = new ThriftWPWithinService.Client(protocol); _transport = transport; _client = client; Log.InfoFormat("Client connected to Thrift RPC Agent endpoint at {0}:{1} using {2}", config.ServiceHost, config.ServicePort, config.Protocol); }
/// <summary> /// Creates an instance of the service that will communicate with remote devices using the configuration supplied by <paramref name="localAgentConfiguration"/>. /// </summary> /// <param name="localAgentConfiguration">Describes how the local Thrift RPC agent (the core SDK) can be communicated with.</param> public WPWithinService(RpcAgentConfiguration localAgentConfiguration) { if (localAgentConfiguration == null) { throw new ArgumentNullException("A configuration must be supplied", nameof(localAgentConfiguration)); } InitClient(localAgentConfiguration); if (localAgentConfiguration.CallbackPort > 0) { _listener = new CallbackServerManager(localAgentConfiguration); _listener.Start(); } else { Log.Info("Callbacks disabled as port specified as 0"); } }
private CommandResult ConsumePurchase(string[] arg) { RpcAgentConfiguration consumerConfig = new RpcAgentConfiguration { LogLevel = "panic,fatal,error,warn,info,debug", LogFile = new FileInfo("WPWithinConsumer.log"), ServicePort = 9096, }; RpcAgentManager consumerAgent = new RpcAgentManager(consumerConfig); consumerAgent.StartThriftRpcAgentProcess(); WPWithinService service = new WPWithinService(consumerConfig); SimpleConsumer consumer = new SimpleConsumer(_output, _error); consumer.MakePurchase(service); consumerAgent.StopThriftRpcAgentProcess(); return CommandResult.Success; }
public void StartAndStop() { RpcAgentConfiguration cfg = new RpcAgentConfiguration { CallbackPort = 9092, ServicePort = 9091, ServiceHost = "localhost" }; RpcAgentManager mgr = new RpcAgentManager(cfg); mgr.StartThriftRpcAgentProcess(); try { using (WPWithinService service = new WPWithinService(cfg)) { Log.InfoFormat("Successfully connected {0} to Thrift RPC Agent on {1}", service, cfg); } } finally { mgr.StopThriftRpcAgentProcess(); } }
public CallbackServerManager(RpcAgentConfiguration config) { _config = config; }