summaryrefslogtreecommitdiff
path: root/CSharp/Ivy/IvyProbe/IvyProbe.cs
blob: c491d4e82c37cf3724f764847d1fce6312d285df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
	{
 
		public IvyProbe()
		{
			//
			// Requis pour la prise en charge du Concepteur Windows Forms
			//
			InitializeComponent();
		}
		
        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+"'");
		}

        private void busDomain_DomainChanged(object sender, EventArgs e)
        {
           // bus.stop();
            bus.start(busDomain.Domain);
        }
	}
}