From cca6ec2ebc782a7c6fa9a48137d473face4d8599 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:58:55 +0000 Subject: Utilisateur : Fcolin Date : 23/06/06 Heure : 11:12 Archivé dans $/CSharp/Ivy/Ivy Commentaire: (vss 47) --- CSharp/Ivy/IvyPPC/IvyClient.cs | 60 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'CSharp/Ivy/IvyPPC/IvyClient.cs') diff --git a/CSharp/Ivy/IvyPPC/IvyClient.cs b/CSharp/Ivy/IvyPPC/IvyClient.cs index a207974..0e46765 100644 --- a/CSharp/Ivy/IvyPPC/IvyClient.cs +++ b/CSharp/Ivy/IvyPPC/IvyClient.cs @@ -46,8 +46,11 @@ namespace IvyBus get { StringCollection tab = new StringCollection(); - foreach( IvyBindingBase bind in bindings.Values ) - tab.Add(bind.expression); + lock (bindings) + { + foreach (IvyBindingBase bind in bindings.Values) + tab.Add(bind.Expression); + } return tab; } @@ -130,9 +133,9 @@ namespace IvyBus // sends our regexps to the peer lock( bus.bindings ) { - foreach (Ivy.ApplicationBinding bind in bus.bindings.Values ) + foreach (IvyApplicationBinding bind in bus.bindings.Values) { - stream.TokenAddBinding(bind); + stream.TokenAddBinding(bind.Binding, bind.Key, bind.Expression); } } stream.TokenEndRegexp(); @@ -242,18 +245,15 @@ namespace IvyBus internal int sendMsg(String message) { int count = 0; - + lock( bindings ) { - // hash message in V4 protocol only - if (bus.ProtocolVersion == 4) - IvyBindingSimple.Prepare(message); - foreach (IvyBindingBase bind in bindings.Values ) + foreach (IvyBindingBase bind in bindings.Values ) { string[] args = bind.Match(message); if ( stream != null && args!=null ) { - stream.TokenMsg(bind.key, args); + stream.TokenMsg(bind.Key, args); count++; } } @@ -380,26 +380,32 @@ namespace IvyBus close(false); // will fire diconnected } - void IvyProtocol.TokenAddBinding(Ivy.ApplicationBinding bind) + void IvyProtocol.TokenAddBinding(BindingType type, ushort id, string expression) { - try - { - if (bind.type == Ivy.BindingType.BindRegexp && !bus.CheckRegexp(bind.expression)) + + if (type == BindingType.Regexp && !bus.CheckRegexp(expression)) + { + bus.OnClientFilterBinding(new IvyEventArgs(this, id, expression )); + return; + } + IvyBindingBase bind = null; + try + { + switch (type) { - bus.OnClientFilterBinding(new IvyEventArgs(this, bind.key, bind.expression )); - return; + case BindingType.Regexp: + bind = new IvyBindingRegexp(id, expression); + break; + case BindingType.Simple: + bind = new IvyBindingSimple(id, expression); + break; } lock (bindings) { - IvyBindingBase binding; - if (bind.type == Ivy.BindingType.BindRegexp) - binding = new IvyBindingRegexp(bind.key, bind.expression); - else - binding = new IvyBindingSimple(bind.key, bind.expression); - bindings.Add(bind.key, binding); + bindings.Add(id, bind); } - bus.OnClientAddBinding(new IvyEventArgs(this, bind.key, bind.expression)); + bus.OnClientAddBinding(new IvyEventArgs(this, id, expression)); } catch (ArgumentException ex) @@ -414,8 +420,8 @@ namespace IvyBus { try { - IvyBindingBase bind = (IvyBindingBase)bindings[id]; - bus.OnClientRemoveBinding(new IvyEventArgs(this, bind.key, bind.expression)); + IvyBindingBase bind = bindings[id]; + bus.OnClientRemoveBinding(new IvyEventArgs(this, bind.Key, bind.Expression)); bindings.Remove(id); } catch (KeyNotFoundException ex) @@ -444,13 +450,13 @@ namespace IvyBus } void IvyProtocol.TokenEndRegexp() { - bus.OnClientConnected(new IvyEventArgs(this, 0, "")); /* * the peer is perhaps not ready to handle this message * an assymetric processing should be written */ if (bus.ReadyMessage != null) - sendMsg(bus.ReadyMessage); + sendMsg(bus.ReadyMessage); + bus.OnClientConnected(new IvyEventArgs(this, 0, "")); } void IvyProtocol.TokenStartRegexp(ushort id, string arg) { -- cgit v1.1