From eb9264d9ecbc98b7a31c8668c5ee920d393402af Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 10:08:28 +0000 Subject: Utilisateur : Fcolin Date : 23/06/06 Heure : 15:33 Archivé dans $/CSharp/Ivy/IvyProbeConsole Commentaire: (vss 15) --- CSharp/Ivy/IvyProbeConsole/IvyProbeConsole.cs | 115 +++++++++++++++++++------- 1 file changed, 85 insertions(+), 30 deletions(-) (limited to 'CSharp/Ivy') diff --git a/CSharp/Ivy/IvyProbeConsole/IvyProbeConsole.cs b/CSharp/Ivy/IvyProbeConsole/IvyProbeConsole.cs index 6c9ce7a..691e544 100644 --- a/CSharp/Ivy/IvyProbeConsole/IvyProbeConsole.cs +++ b/CSharp/Ivy/IvyProbeConsole/IvyProbeConsole.cs @@ -29,10 +29,43 @@ namespace IvyProbeConsole } } + public void BindFromFile(string name) + { + string line; + try + { + FileStream file = new FileStream(name, FileMode.Open, FileAccess.Read); + TextReader reader = new StreamReader(file); + while ((line = reader.ReadLine()) != null) + { + bus.BindMsg(line, receive); + } + } + catch (FileNotFoundException e) + { + Console.WriteLine(e.Message); + } + } + public const string helpCommands = + "Available commands:\n"+ + ".die CLIENTNAME sends a die message\n" + + ".direct CLIENTNAME ID MESSAGE sends the direct message to the client, with a message id set to the numerical ID\n" + + ".bye quits the application\n" + + ".quit idem\n" + + ".list lists the available clients\n" + + ".ping sends a ping request if IVY_PING is enabled\n" + + ".bind REGEXP binds to a regexp at runtime\n" + + ".unbind REGEXP unbinds to a regexp at runtime"; - public const String helpCommands = "Available commands:\n.die CLIENTNAME sends a die message\n.direct CLIENTNAME ID MESSAGE sends the direct message to the client, with a message id set to the numerical ID\n.bye quits the application\n.quit idem\n.list lists the available clients\n.ping sends a ping request if IVY_PING is enabled\n.bind REGEXP binds to a regexp at runtime\n.unbind REGEXP unbinds to a regexp at runtime"; - - public const String helpmsg = "usage: IvyProbe [options] [regexp]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-n ivyname (default JPROBE)\n\t-q\tquiet, no tty output\n\t-d\tdebug\n\t-t\ttime stamp each message\n\t-h\thelp\n\n\t regexp is a Perl5 compatible regular expression"; + public const String helpmsg = + "usage: IvyProbe [options] [regexp]\n" + + "\t-b BUS\tspecifies the Ivy bus domain\n" + + "\t-n ivyname (default JPROBE)\n" + + "\t-q\tquiet, no tty output\n" + + "\t-d\tdebug\n" + + "\t-t\ttime stamp each message\n" + + "\t-h\thelp\n\n" + + "\t regexp is a Perl5 compatible regular expression"; private TextReader in_Renamed; private volatile Thread looperThread; @@ -43,10 +76,11 @@ namespace IvyProbeConsole [STAThread] public static void Main(String[] args) { - String name = "C#PROBE"; + string name = "C#PROBE"; + string fname = null; bool quiet = false; bool timestamp = false; - String domain = Ivy.GetDomain(null); + string domain = Ivy.GetDomain(null); bool debug = false; domain = Properties.Settings.Default.domain; @@ -56,29 +90,34 @@ namespace IvyProbeConsole debug = Properties.Settings.Default.IvyDebug; - GetOpt opt = new GetOpt(args, "n:b:dqht"); + GetOpt opt = new GetOpt(args, "f:n:b:dqht"); Arg a; while ((a = opt.NextArg()) != null) { switch (a.Flag) { - case 'd': - //UPGRADE_ISSUE: Method 'java.lang.System.getProperties' was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1000_javalangSystemgetProperties"' - //System.Configuration.AppSettingsReader sysProp = System.getProperties(); - //SupportClass.PutElement(sysProp, "IVY_DEBUG", "yes"); + case 'd': + debug = true; break; case 'b': - domain = a.Parameter; break; + domain = a.Parameter; + break; case 'n': - name = a.Parameter; break; + name = a.Parameter; + break; + case 'f': + fname = a.Parameter; + break; case 'q': - quiet = true; break; + quiet = true; + break; case 't': - timestamp = true; break; + timestamp = true; + break; case 'h': default: System.Console.Out.WriteLine(helpmsg); @@ -92,7 +131,12 @@ namespace IvyProbeConsole IvyProbeConsole p = new IvyProbeConsole(System.Console.In, timestamp, quiet, debug ); p.ExitOnDie = true; Ivy bus = new Ivy(name, name + " ready"); - foreach(string ex in opt.Extras) + p.start(bus); + + if (fname != null) + p.BindFromFile(fname); + + foreach(string ex in opt.Extras) { if (!quiet) System.Console.Out.WriteLine("you want to subscribe to " + ex); @@ -103,7 +147,7 @@ namespace IvyProbeConsole System.Console.Out.WriteLine(Ivy.Domains(domain)); bus.Start(domain); - p.start(bus); + } @@ -137,11 +181,29 @@ namespace IvyProbeConsole bus.ClientDisconnected += disconnect; bus.DieReceived += die ; bus.DirectMessageReceived += directMessage; + bus.BindingAdd += new EventHandler(bus_BindingAdd); + bus.BindingRemove += new EventHandler(bus_BindingRemove); + bus.BindingFilter += new EventHandler(bus_BindingFilter); looperThread = new Thread(new ThreadStart(Run)); looperThread.Name = "Keyboard Input Thread"; looperThread.Start(); } + + void bus_BindingFilter(object sender, IvyEventArgs e) + { + println("filtred regexp {0} from {1}", e.Argument, e.Client.ApplicationName); + } + + void bus_BindingRemove(object sender, IvyEventArgs e) + { + println("Removed regexp {0} from {1}", e.Argument, e.Client.ApplicationName); + } + + void bus_BindingAdd(object sender, IvyEventArgs e) + { + println("Added regexp {0} from {1}", e.Argument, e.Client.ApplicationName); + } public void Run() @@ -249,10 +311,6 @@ namespace IvyProbeConsole private void connect(object sender, IvyEventArgs e) { println(e.Client.ApplicationName + " connected from "+e.Client.RemoteAddress+":"+e.Client.RemotePort); - foreach (string re in e.Client.Regexps ) - { - println(e.Client.ApplicationName + " subscribes to " + re); - } } private void disconnect(object sender, IvyEventArgs e) @@ -288,17 +346,14 @@ namespace IvyProbeConsole { Trace.WriteLineIf(debug, "-->Probe<-- " + s); } - private void println(String s) - { - if (!quiet) - System.Console.Out.WriteLine(date() + s); - } - private String date() + private void println(string format, params object[] args) { - if (!timestamp) - return ""; - System.DateTime d = System.DateTime.Now; - return "[" + d + "] "; + if (!quiet) + { + if (timestamp) System.Console.Out.Write(string.Format("[ {0|HH:mm:ss.fff} ]",System.DateTime.Now )); + System.Console.Out.WriteLine(string.Format(format,args)); + } } + } } \ No newline at end of file -- cgit v1.1