From 5e415074ec406ff083e49cc156b38e51f8af4cc0 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:56:49 +0000 Subject: Utilisateur : Fcolin Date : 19/12/05 Heure : 16:54 Archivé dans $/CSharp/Ivy Commentaire: (vss 3) --- CSharp/Ivy/IvyPPC/IvyBinding.cs | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'CSharp') diff --git a/CSharp/Ivy/IvyPPC/IvyBinding.cs b/CSharp/Ivy/IvyPPC/IvyBinding.cs index c5fd5fe..1ff96e5 100644 --- a/CSharp/Ivy/IvyPPC/IvyBinding.cs +++ b/CSharp/Ivy/IvyPPC/IvyBinding.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Specialized; using System.Text.RegularExpressions; namespace IvyBus @@ -9,39 +10,42 @@ namespace IvyBus /// internal abstract class IvyBindingBase { - - internal int key; + + internal ushort key; internal string expression; - - public IvyBindingBase(int id, string exp) + + public IvyBindingBase(ushort id, string exp) { key = id; expression = exp; } - public abstract IvyArgument Match(string message); + public abstract string[] Match(string message); } internal class IvyBindingRegexp : IvyBindingBase { internal Regex regexp; - - public IvyBindingRegexp(int id, string exp):base(id,exp) + + public IvyBindingRegexp(ushort id, string exp) + : base(id, exp) { regexp = new Regex(expression,RegexOptions.Compiled|RegexOptions.IgnoreCase); } - public override IvyArgument Match(string message) + public override string[] Match(string message) { - IvyArgument args = null; + string[] args = null; // use of regexp to extract info Match result = regexp.Match(message); if (result.Success) { // Start at 1 because group 0 represent entire matching - args = new IvyArgument(""); + StringCollection coll = new StringCollection(); for (int sub = 1; sub < result.Groups.Count; sub++) { - args.addChild( new IvyArgument( result.Groups[sub].Value )); + coll.Add(result.Groups[sub].Value); } + args = new string[coll.Count]; + coll.CopyTo(args, 0); } return args; } @@ -52,8 +56,9 @@ namespace IvyBus internal string[] msgargs; // list of message args names static string msgtag; // send message name static Hashtable args_values = null; // send message args[name]=value - - public IvyBindingSimple(int id, string exp):base(id,exp) + + public IvyBindingSimple(ushort id, string exp) + : base(id, exp) { string[] expr = expression.Split( ' ' ); msgname = expr[0]; @@ -78,19 +83,21 @@ namespace IvyBus } } - public override IvyArgument Match(string message) + public override string[] Match(string message) { // the message is already parsed by prepare // - IvyArgument args = null; + string[] args = null; if (msgtag == msgname) { - args = new IvyArgument(""); + StringCollection coll = new StringCollection(); for( int sub= 0; sub < msgargs.Length; sub++) { - args.addChild( new IvyArgument( (string) args_values[ msgargs[sub]] )); + coll.Add((string)args_values[msgargs[sub]]); } + args = new string[coll.Count]; + coll.CopyTo(args, 0); } return args; } -- cgit v1.1