From 2fac7f440359885e464e34d25554c2068eb3350b Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:56:45 +0000 Subject: Utilisateur : Fcolin Date : 30/06/05 Heure : 14:21 Créé Commentaire: Bug start time < 0 en l'absence de rejeu a voir ajouter 1s de blank au debut (vss 1) --- CSharp/Ivy/IvyPPC/IvyBinding.cs | 102 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 CSharp/Ivy/IvyPPC/IvyBinding.cs (limited to 'CSharp/Ivy/IvyPPC/IvyBinding.cs') diff --git a/CSharp/Ivy/IvyPPC/IvyBinding.cs b/CSharp/Ivy/IvyPPC/IvyBinding.cs new file mode 100644 index 0000000..c7be101 --- /dev/null +++ b/CSharp/Ivy/IvyPPC/IvyBinding.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections; +using System.Text.RegularExpressions; + +namespace IvyBus +{ + /// + /// Description résumée de IvyBinding. + /// + internal class IvyBindingBase + { + + internal int key; + internal string expression; + + public IvyBindingBase(int id, string exp) + { + key = id; + expression = exp; + } + public virtual string[] Match(string message) + { + return null; + } + + } + internal class IvyBindingRegexp : IvyBindingBase + { + internal Regex regexp; + + public IvyBindingRegexp(int id, string exp):base(id,exp) + { + regexp = new Regex(expression,RegexOptions.Compiled|RegexOptions.IgnoreCase); + } + public override string[] Match(string message) + { + string[] array = null; + // use of regexp to extract info + Match result = regexp.Match(message); + if (result.Success) + { + // Start at 1 because group 0 represent entire matching + array = new string[result.Groups.Count -1]; + for (int sub = 1; sub < result.Groups.Count; sub++) + { + array[sub-1] = result.Groups[sub].Value; + } + } + return array; + } + } + internal class IvyBindingSimple : IvyBindingBase + { + internal string msgname; // message name + internal string[] msgargs; // list of message args names + static string msgtag; // send message name + static Hashtable args = null; // send message args[name]=value + + public IvyBindingSimple(int id, string exp):base(id,exp) + { + string[] expr = expression.Split( ' ' ); + msgname = expr[0]; + msgargs = new string[ expr.Length -1 ]; + for ( int i = 1; i < expr.Length; i++ ) + msgargs[i-1] = expr[i]; + } + static public void Prepare( string message ) + { + string[] msg = message.Split(' '); + msgtag = msg[0]; + args = new Hashtable(); + for( int sub=1 ; sub < msg.Length; sub++ ) + { + string[] arg = msg[sub].Split('='); // champ = valeur + if ( arg.Length == 2 ) + args[arg[0]] = arg[1]; + else + { + Console.Out.WriteLine("abnormally Formed message expected 'msg champ=valeur champ=valeur....' :" + message); + } + } + + } + public override string[] Match(string message) + { + // the message is already parsed by prepare + // + string[] array = null; + + if (msgtag == msgname) + { + array = new string[msgargs.Length]; + for( int sub= 0; sub < msgargs.Length; sub++) + { + array[sub] = (string) args[ msgargs[sub]]; + } + } + return array; + } + + } +} -- cgit v1.1