namespace IvyProbe { using System; using System.Windows.Forms; using IvyBus; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Reflection; partial class IvyProbe : System.Windows.Forms.Form { //internal Ivy bus; public IvyProbe() { // // Requis pour la prise en charge du Concepteur Windows Forms // InitializeComponent(); } public void stop() { //bus.clientConnected -= new Ivy.ClientConnectedHandler( connect ); //bus.clientDisconnected -= new Ivy.ClientDisconnectedHandler( disconnect ); //bus.dieReceived -= new Ivy.DieHandler( die ); //bus.directMessageReceived -= new Ivy.DirectMessageHandler( directMessage ); //bus.stop(); } private void append(System.String s) { // je mettrais bien la date, aussi. ta.AppendText(s + "\r\n"); } private void connect(IvyClient client) { append(client.ApplicationName + " connected from "+client.RemoteAddress); } private void disconnect(IvyClient client) { append(client.ApplicationName + " disconnected from " + client.RemoteAddress); } private bool die(IvyClient client, int id, string message) { append("receive die from "+client.ApplicationName+" cause: "+message ); // return true terminate the application return false; } private void directMessage(IvyClient client, int id, string arg) { append(client.ApplicationName + " direct Message " + id + arg); } public void RegexpCB(System.Object event_sender, System.EventArgs e) { // ajoute la nouvelle regex string regexp = tbRegexp.Text; regexp.Trim(); int regexp_id = bus.bindMsg(regexp, new Ivy.MessageHandler(receive)); tbRegexp.Text = ""; append( "bind("+regexp_id+") ->"+regexp); } public void ExpressionCB(System.Object event_sender, System.EventArgs e) { // ajoute la nouvelle regex string expression = tbRegexp.Text; expression.Trim(); int regexp_id = bus.bindSimpleMsg(expression, new Ivy.MessageHandler(receive)); tbRegexp.Text = ""; append( "bind("+regexp_id+") ->"+expression); } [IvyBinding("(.*)")] private void receive(IvyClient client, string[] args) { string receive_str = "client " + client.ApplicationName + " envoie: ["; for (int i = 0; i < args.Length; i++) { receive_str += args[i]+ ","; } receive_str = receive_str.TrimEnd(new char[] { ',' }); receive_str += "]"; append(receive_str); } public void SendCB(System.Object event_sender, System.EventArgs e) { int count; System.String tosend = tbMsg.Text; tbMsg.Text = ""; count = bus.sendMsg(tosend); append("Sending '" + tosend + "' count " + count); } [STAThread] public static void Main(System.String[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new IvyProbe()); } private void tbMsg_TextChanged(object sender, System.EventArgs e) { btSend.Enabled = (tbMsg.Text != ""); } private void tbRegexp_TextChanged(object sender, System.EventArgs e) { bool enable = (tbRegexp.Text != ""); btBind.Enabled = enable; btBindSimple.Enabled = enable; btUnbind.Enabled = enable; } private void btUnbind_Click(object sender, System.EventArgs e) { // enleve la regex string regexp = tbRegexp.Text; bool removed = bus.unBindMsg( regexp ); if ( removed ) { append( "unbind("+regexp+")"); tbRegexp.Text = ""; } else { append( "unbind can't find binding ("+regexp+")"); } } private void bus_addBinding(IvyClient app, string arg) { append( app.ApplicationName + " add binding '"+arg+"'"); } private void bus_removeBinding(IvyClient app, string arg) { append( app.ApplicationName + " remove binding '"+arg+"'"); } } }