private void thread_Client(object Logbus) { try { ILogBus ctrl = Logbus as ILogBus; ctrl.CreateChannel("simple", "Simple", new TrueFilter(), "Very simple channel", 0); Dictionary <string, string> input; input = new Dictionary <string, string>(); IEnumerable <KeyValuePair <string, string> > output; input.Add("ip", "127.0.0.1"); input.Add("port", MONITOR_PORT.ToString()); string clientid = ctrl.SubscribeClient("simple", "udp", input, out output); TestContext.WriteLine("Client ID obtained by logbus: {0}", clientid); //Go ahead and send step1.Set(); IPEndPoint remote_ep = new IPEndPoint(IPAddress.Any, 0); using (UdpClient client = new UdpClient(MONITOR_PORT)) { byte[] payload = client.Receive(ref remote_ep); SyslogMessage msg = SyslogMessage.Parse(payload); TestContext.WriteLine("Message1: {0}", msg); payload = client.Receive(ref remote_ep); msg = SyslogMessage.Parse(payload); TestContext.WriteLine("Message2: {0}", msg); } ctrl.UnsubscribeClient(clientid); finish.Set(); } catch (Exception ex) { Assert.Fail("Test failed: {0}", ex); } }
private void t2_thread_Client(object Logbus) { try { ILogBus ctrl = Logbus as ILogBus; ctrl.CreateChannel("simple", "Simple", new TrueFilter(), "Very simple channel", 0); Dictionary <string, string> input; input = new Dictionary <string, string>(); IEnumerable <KeyValuePair <string, string> > output; input.Add("ip", "127.0.0.1"); input.Add("port", t2_client_port.ToString()); string clientid = ctrl.SubscribeClient("simple", "udp", input, out output); TestContext.WriteLine("Client ID obtained by logbus: {0}", clientid); //Go ahead and send t2_step1.Set(); //Only 6 messages expected IPEndPoint remote_ep = new IPEndPoint(IPAddress.Any, 0); using (UdpClient client = new UdpClient(t2_client_port)) { byte[] payload = client.Receive(ref remote_ep); TestContext.WriteLine("Time occurred for a message to traverse the bus: {0} milliseconds", (DateTime.Now - t2_start).TotalMilliseconds.ToString(CultureInfo.CurrentUICulture)); SyslogMessage msg = SyslogMessage.Parse(payload); } ctrl.UnsubscribeClient(clientid); t2_finish.Set(); } catch (Exception ex) { Assert.Fail("Test failed: {0}", ex); } }
private void t1_thread_Client(object Logbus) { try { ILogBus ctrl = Logbus as ILogBus; ctrl.CreateChannel("simple", "Simple", new TrueFilter(), "Very simple channel", 0); Dictionary <string, string> input; input = new Dictionary <string, string>(); IEnumerable <KeyValuePair <string, string> > output; input.Add("ip", "127.0.0.1"); input.Add("port", t1_client_port.ToString()); string clientid = ctrl.SubscribeClient("simple", "udp", input, out output); TestContext.WriteLine("Client ID obtained by logbus: {0}", clientid); //Go ahead and send t1_step1.Set(); //Only 6 messages expected IPEndPoint remote_ep = new IPEndPoint(IPAddress.Any, 0); using (UdpClient client = new UdpClient(t1_client_port)) for (int i = 0; i < 5; i++) { byte[] payload = client.Receive(ref remote_ep); SyslogMessage msg = SyslogMessage.Parse(payload); Assert.AreEqual(SyslogFacility.Audit, msg.Facility); } ctrl.UnsubscribeClient(clientid); t1_finish.Set(); } catch (Exception ex) { Assert.Fail("Test failed: {0}", ex); } }
ChannelSubscriptionResponse IChannelSubscription.SubscribeChannel(ChannelSubscriptionRequest request) { IEnumerable <KeyValuePair <string, string> > out_params; Dictionary <string, string> in_params = new Dictionary <string, string>(); foreach (KeyValuePair kvp in request.param) { in_params.Add(kvp.name, kvp.value); } string clientid; try { clientid = _target.SubscribeClient(request.channelid, request.transport, in_params, out out_params); } catch { throw; } ChannelSubscriptionResponse ret = new ChannelSubscriptionResponse(); ret.clientid = clientid; List <KeyValuePair> lst = new List <KeyValuePair>(); foreach (KeyValuePair <string, string> kvp in out_params) { lst.Add(new KeyValuePair { name = kvp.Key, value = kvp.Value }); } ret.param = lst.ToArray(); return(ret); }
/// <summary> /// Required by ILogBus /// </summary> public string SubscribeClient(string channelId, string transportId, IEnumerable <KeyValuePair <string, string> > transportInstructions, out IEnumerable <KeyValuePair <string, string> > clientInstructions) { return(_target.SubscribeClient(channelId, transportId, transportInstructions, out clientInstructions)); }