summaryrefslogtreecommitdiff
path: root/Ivy/IvyApplicationBinding.cs
diff options
context:
space:
mode:
authorfcolin2008-08-22 16:44:01 +0000
committerfcolin2008-08-22 16:44:01 +0000
commit8d10e8bbd1e19adc7c70e1101dbb69c213c910dd (patch)
treef41034ab66b1b3174277b07c8aa45791dadbaae8 /Ivy/IvyApplicationBinding.cs
parent7053d3d604920ab708076e107be4b55666c5af80 (diff)
downloadivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.zip
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.gz
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.bz2
ivy-csharp-8d10e8bbd1e19adc7c70e1101dbb69c213c910dd.tar.xz
optimisation for parsing same regular expression from multiple client
using fxCop for code beauty fix bug on concurrent connect
Diffstat (limited to 'Ivy/IvyApplicationBinding.cs')
-rw-r--r--Ivy/IvyApplicationBinding.cs69
1 files changed, 48 insertions, 21 deletions
diff --git a/Ivy/IvyApplicationBinding.cs b/Ivy/IvyApplicationBinding.cs
index 299f459..b5fe303 100644
--- a/Ivy/IvyApplicationBinding.cs
+++ b/Ivy/IvyApplicationBinding.cs
@@ -1,11 +1,14 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Text;
-using System.Threading;
namespace IvyBus
{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.Specialized;
+ using System.Text;
+ using System.Threading;
+ using System.Text.RegularExpressions;
+ using System.Collections.ObjectModel;
+
/* This is the Application side of binding storage */
/* association of a generated Key and a delegate and the expression */
/* this is SEND to other client */
@@ -14,15 +17,20 @@ namespace IvyBus
{
private BindingType binding;
+ // Argument formatting Expression to replace argument in in regular expresion binding
+ // format %number[:objectFormat]%
+ // where number in argument index and objectFormat the ToString format passed to argument
+ private Regex re = new Regex(@"%(\d+)(|:(.*))%");
+
public BindingType Binding
{
get { return binding; }
set { binding = value; }
}
- private ushort key;
+ private int key;
- public ushort Key
+ public int Key
{
get { return key; }
set { key = value; }
@@ -30,11 +38,6 @@ namespace IvyBus
private object[] args;
- public object[] Args
- {
- get { return args; }
- set { args = value; }
- }
private string expression;
public string Expression
@@ -42,22 +45,22 @@ namespace IvyBus
get { return expression; }
set { expression = value; }
}
- private string formated_expression;
- public string FormatedExpression
+ private string formatted_expression;
+ public string FormattedExpression
{
get
{
FormatExpression();
- return formated_expression;
+ return formatted_expression;
}
}
- private List<string> arguments;
+ private Collection<string> arguments;
///<summary>SentMessageClasses the first word token of sent messages
///<remarks> optimise the parsing process when sending messages </remarks>
///</summary>
- public List<string> Arguments
+ public Collection<string> Arguments
{
get
{
@@ -66,12 +69,35 @@ namespace IvyBus
}
public event EventHandler<IvyMessageEventArgs> Callback;
-
+
public IvyApplicationBinding()
+ :this(BindingType.RegularExpression,string.Empty,null)
{
- arguments = new List<string>();
+
+ }
+ public IvyApplicationBinding(BindingType type, string expression, params object[] args)
+ {
+ arguments = new Collection<string>();
+ this.Binding = type;
+ this.Expression = expression;
+ this.args = args;
}
+ private string ReplaceArgs(Match m)
+ {
+ string s = string.Empty;
+ // Get the matched string. convert to argindex
+ int argindex = int.Parse(m.Groups[1].Value);
+ // use %... to specify formating
+ object arg = args[argindex];
+ IFormattable fmt = arg as IFormattable;
+ if (fmt != null)
+ s = fmt.ToString(m.Groups[3].Value, null);
+ else if (arg != null)
+ s = arg.ToString();
+
+ return s;
+ }
// translate part of expression to object property
public void FormatExpression()
{
@@ -94,11 +120,12 @@ namespace IvyBus
args[i] = arguments[i];
}
}
- formated_expression = string.Format(expression, args);
+
+ formatted_expression = re.Replace(expression, ReplaceArgs);
}
else //TODO Abnormal condition Design Time
#endif
- formated_expression = expression;
+ formatted_expression = expression;
}