using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Threading; namespace IvyBus { /* 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 */ public class IvyApplicationBinding { private BindingType binding; public BindingType Binding { get { return binding; } set { binding = value; } } private ushort key; public ushort Key { get { return key; } set { key = value; } } private object[] args; public object[] Args { get { return args; } set { args = value; } } private string expression; public string Expression { get { return expression; } set { expression = value; } } private string formated_expression; public string FormatedExpression { get { FormatExpression(); return formated_expression; } } private List arguments; ///SentMessageClasses the first word token of sent messages /// optimise the parsing process when sending messages /// public List Arguments { get { return arguments; } } public event EventHandler Callback; public IvyApplicationBinding() { arguments = new List(); } // translate part of expression to object property public void FormatExpression() { //// Safely : #if (!PocketPC)//TODO Pocket PC doesn't have Target Member EventHandler temp = Callback; if (temp != null) { //TODO Pocket PC doesn't have Target Member object target = temp.Target; if (args == null) { args = new object[arguments.Count]; for (int i = 0; i < arguments.Count; i++) { System.Reflection.PropertyInfo prop = target.GetType().GetProperty(arguments[i]); if (prop != null) args[i] = prop.GetValue(target, null); else //TODO what else BUG msgbox in desing mode !!! args[i] = arguments[i]; } } formated_expression = string.Format(expression, args); } else //TODO Abnormal condition Design Time #endif formated_expression = expression; } #if ( PocketPC ) internal void Firevent(System.Windows.Forms.Control control, IvyMessageEventArgs e) { //// Safely invoke an event: EventHandler temp = Callback; if (temp == null) { throw new IvyException("(callCallback) Not callback for id " + e.Id); } if (control != null) { control.Invoke(temp, this, e); } else temp(this, e); } #else internal void Firevent(System.Threading.SynchronizationContext syncContext, IvyMessageEventArgs e) { //// Safely invoke an event: EventHandler temp = Callback; if (temp == null) { throw new IvyException("(callCallback) Not callback for id " + e.Id); } if (syncContext != null) { SendOrPostCallback update = delegate(object state) { IvyMessageEventArgs args = (IvyMessageEventArgs)state; temp(this, args); }; syncContext.Post(update, e); } else temp(this, e); } #endif } }