From df898a41f338af6b69b7cc03de9c71bc3e79d8ca Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:56:12 +0000 Subject: Utilisateur : Fcolin Date : 30/06/06 Heure : 13:40 Archivé dans $/CSharp/Ivy/Ivy Commentaire: gestion designer (vss 68) --- CSharp/Ivy/IvyPPC/Ivy.cs | 174 +++++++++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 90 deletions(-) (limited to 'CSharp/Ivy/IvyPPC') diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs index 7dd6b6c..c58fd42 100644 --- a/CSharp/Ivy/IvyPPC/Ivy.cs +++ b/CSharp/Ivy/IvyPPC/Ivy.cs @@ -16,7 +16,6 @@ namespace IvyBus using System.Net.Sockets; using System.Threading; using System.Configuration; - using System.Windows.Forms; using System.Globalization; using System.Text.RegularExpressions; using System.Text; @@ -24,9 +23,8 @@ namespace IvyBus using System.ComponentModel; using System.Diagnostics; - using System.ComponentModel; using System.ComponentModel.Design; - using System.Drawing.Design; +// using System.Drawing.Design; /// The Main bus Class @@ -57,7 +55,7 @@ namespace IvyBus public event EventHandler BindingAdd; /// fires when a client receive a remove binding from another client public event EventHandler BindingRemove; - /// fires when a client receive a binding from another clientand it as been filtered + /// fires when a client receive a binding from another client and it as been filtered public event EventHandler BindingFilter; /// fires when a client receive a remove binding from another client public event EventHandler ErrorMessage; @@ -222,46 +220,35 @@ namespace IvyBus get { return ready_message; } set { ready_message = value; } } -#if (!PocketPC) - [Category("Ivy")] -#endif - [DefaultValue(null)] - public Control SyncControl - { - get { return syncControl; } - set - { - syncControl = value; - } - } + +#if (!Mono) + #if (!PocketPC) [Category("Ivy")] #endif - [DefaultValue(null)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - [Editor(typeof(IvyBindingCollectionEditor), typeof(UITypeEditor))] + //[Editor(typeof(IvyBindingCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))] public List Bindings { get { return app_bindings; } - //set { app_bindings = value; } } //create a collection editor class - private class IvyBindingCollectionEditor : CollectionEditor - { - public IvyBindingCollectionEditor(Type type) - : base(type) - { - } - - //Over ride the function which will return the STYLES collection - protected override System.Type[] CreateNewItemTypes() - { - return new Type[] { typeof(IvyApplicationBinding) }; - } - } - + //private class IvyBindingCollectionEditor : CollectionEditor + //{ + // public IvyBindingCollectionEditor(Type type) + // : base(type) + // { + // } + + // //Over ride the function which will return the STYLES collection + // protected override System.Type[] CreateNewItemTypes() + // { + // return new Type[] { typeof(IvyApplicationBinding) }; + // } + //} +#endif internal class MyTcpListener : TcpListener { public MyTcpListener(IPAddress address, int port) @@ -301,20 +288,27 @@ namespace IvyBus private string ready_message; private CultureInfo culture = new CultureInfo("en-us"); // for synchronous event - private Control syncControl; // null by runtime default + private readonly SynchronizationContext syncContext; + public Ivy() { + syncContext = SynchronizationContext.Current; clients = new List(); bindings = new Dictionary(); app_bindings = new List(); sent_messageFilter = new StringCollection(); -#if (!PocketPC ) +#if (!PocketPC) debug = Properties.Settings.Default.IvyDebug; protocolVersion = Properties.Settings.Default.IvyProtocolVersion; #endif } + public Ivy(IContainer container) + : this() + { + container.Add(this); + } /// Readies the structures for the software bus connexion. /// /// This sample shows how to start working with Ivy. @@ -337,22 +331,13 @@ namespace IvyBus /// /// The hellow message you will send once ready /// - public Ivy(string name, string message) + public Ivy(string name, string rdy_message) : this() { appName = name; - ready_message = message; - } - public Ivy(Control sync) - : this() - { - syncControl = sync; - } - public Ivy(string name, string message, Control sync) - : this(name, message) - { - syncControl = sync; + ready_message = rdy_message; } + protected override void Dispose(bool disposing) { try @@ -414,6 +399,15 @@ namespace IvyBus } } + // Autobinding on IvyBindingAttribute method + public void AutoBinding(Assembly assy) + { + foreach (Type typ in assy.GetExportedTypes()) + { + AutoBinding(typ); + } + + } /// connects the Ivy bus to a domain or list of domains. /// /// @@ -610,7 +604,7 @@ namespace IvyBus } // public ushort BindMsg(IvyApplicationBinding newbind) - { + { newbind.Key = serial++; lock (bindings) bindings.Add(newbind.Key, newbind); @@ -619,7 +613,7 @@ namespace IvyBus { foreach (IvyClient c in clients) { - c.stream.TokenAddBinding(newbind.Binding, newbind.Key, newbind.Expression); + c.stream.TokenAddBinding(newbind.Binding, newbind.Key, newbind.FormatedExpression); } } return newbind.Key; @@ -751,24 +745,22 @@ namespace IvyBus v[i].stream.TokenPing(message); return v.Count; } - internal bool IsSynchronous() - { - if (syncControl != null -#if (!PocketPC ) - && syncControl.Created - && ! syncControl.IsDisposed -#endif -) - return true; - else return false; - } + internal virtual void FireEvent(EventHandler ev, IvyEventArgs e) { if (ev != null) { - if (IsSynchronous()) - syncControl.Invoke(ev, this, e); - else ev(this, e); + if (syncContext != null) + { + SendOrPostCallback update = delegate(object state) + { + IvyEventArgs args = (IvyEventArgs)state; + ev(this, args); + }; + syncContext.Send(update, e); + } + else + ev(this, e); } } internal virtual void OnDirectMessage(IvyEventArgs e) @@ -827,13 +819,31 @@ namespace IvyBus EventHandler temp = DieReceived; if (temp != null) { - if (IsSynchronous()) - syncControl.Invoke(temp, this, e ); - else temp(this, e); + if (syncContext != null) + { + SendOrPostCallback update = delegate(object state) + { + IvyDieEventArgs args = (IvyDieEventArgs)state; + temp(this, args); + }; + syncContext.Send(update, e); + } + else + temp(this, e); } } - + internal void OnMessage(IvyMessageEventArgs e) + { + IvyApplicationBinding bind = bindings[e.Id]; + + if (bind == null) + { + throw new IvyException("(callCallback) Not regexp matching id " + e.Id); + } + bind.Firevent(syncContext,e); + } + /* * removes a client from the list */ @@ -879,26 +889,7 @@ namespace IvyBus client.SendBindings(); } - internal void OnMessage(IvyMessageEventArgs e) - { - IvyApplicationBinding bind = bindings[e.Id]; - - if (bind == null) - { - throw new IvyException("(callCallback) Not regexp matching id " + e.Id); - } - //// Safely invoke an event: - EventHandler temp = bind.CallbackHandler; - - if (temp == null) - { - throw new IvyException("(callCallback) Not callback for id " + e.Id); - } - if (IsSynchronous()) - syncControl.Invoke(temp, this, e ); - else temp(this, e); - } - + public static IPAddress GetLocalIP() { IPAddress returnaddr = null; @@ -946,7 +937,7 @@ namespace IvyBus if (domainbus == null || domainbus.Length == 0) { domainbus = Properties.Settings.Default.IvyBus; - } + } #endif if (domainbus == null || domainbus.Length == 0) domainbus = DEFAULT_DOMAIN; @@ -1112,11 +1103,14 @@ namespace IvyBus public void EndInit() { - if (syncControl != null) - AutoBinding(syncControl); + //TODO Autobinding attribute + //if (syncControl != null) + AutoBinding(Assembly.GetCallingAssembly()); // TODO ugly should be added directly the bindings Dictionary ! foreach (IvyApplicationBinding bind in app_bindings) + { BindMsg(bind); + } } #endregion -- cgit v1.1