diff options
author | fcolin | 2007-02-01 09:56:45 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 09:56:45 +0000 |
commit | 2fac7f440359885e464e34d25554c2068eb3350b (patch) | |
tree | 29cdb9339a298e9aab7c19e48e845eb29e043e5f /CSharp/Ivy/IvyPPC/IvyBinding.cs | |
parent | fff77628de3131aeff119e886fecd8f78c42ae3a (diff) | |
download | ivy-csharp-2fac7f440359885e464e34d25554c2068eb3350b.zip ivy-csharp-2fac7f440359885e464e34d25554c2068eb3350b.tar.gz ivy-csharp-2fac7f440359885e464e34d25554c2068eb3350b.tar.bz2 ivy-csharp-2fac7f440359885e464e34d25554c2068eb3350b.tar.xz |
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)
Diffstat (limited to 'CSharp/Ivy/IvyPPC/IvyBinding.cs')
-rw-r--r-- | CSharp/Ivy/IvyPPC/IvyBinding.cs | 102 |
1 files changed, 102 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// Description résumée de IvyBinding.
+ /// </summary>
+ 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;
+ }
+
+ }
+}
|