From 683fa99d6ccdba424a659892bc7cf39bee7ac7ad Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:56:14 +0000 Subject: Utilisateur : Fcolin Date : 30/06/06 Heure : 14:37 Archivé dans $/CSharp/Ivy/Ivy Commentaire: (vss 69) --- CSharp/Ivy/IvyPPC/Ivy.cs | 82 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs index c58fd42..5ae69d6 100644 --- a/CSharp/Ivy/IvyPPC/Ivy.cs +++ b/CSharp/Ivy/IvyPPC/Ivy.cs @@ -221,34 +221,30 @@ namespace IvyBus set { ready_message = value; } } -#if (!Mono) + #if (!PocketPC) [Category("Ivy")] #endif + [DefaultValue(null)] + public System.Windows.Forms.ContainerControl ContainerControl + { + get { return parentControl; } + set + { + parentControl = value; + } + } +#if (!PocketPC) + [Category("Ivy")] +#endif [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - //[Editor(typeof(IvyBindingCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))] public List Bindings { get { return app_bindings; } } - //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) }; - // } - //} -#endif + internal class MyTcpListener : TcpListener { public MyTcpListener(IPAddress address, int port) @@ -288,13 +284,18 @@ namespace IvyBus private string ready_message; private CultureInfo culture = new CultureInfo("en-us"); // for synchronous event +#if (SyncContext) private readonly SynchronizationContext syncContext; - +#else + private System.Windows.Forms.ContainerControl parentControl; +#endif public Ivy() { +#if (SynContext) syncContext = SynchronizationContext.Current; +#endif clients = new List(); bindings = new Dictionary(); app_bindings = new List(); @@ -304,10 +305,10 @@ namespace IvyBus protocolVersion = Properties.Settings.Default.IvyProtocolVersion; #endif } - public Ivy(IContainer container) + public Ivy(System.Windows.Forms.ContainerControl parentControl) : this() { - container.Add(this); + this.parentControl = parentControl; } /// Readies the structures for the software bus connexion. /// @@ -745,7 +746,7 @@ namespace IvyBus v[i].stream.TokenPing(message); return v.Count; } - +#if (SyncContext) internal virtual void FireEvent(EventHandler ev, IvyEventArgs e) { if (ev != null) @@ -763,6 +764,20 @@ namespace IvyBus ev(this, e); } } +#else + internal virtual void FireEvent(EventHandler ev, IvyEventArgs e) + { + if (ev != null) + { + if (parentControl != null) + { + parentControl.Invoke(ev, this, e); + } + else + ev(this, e); + } + } +#endif internal virtual void OnDirectMessage(IvyEventArgs e) { // Copy to a temporary variable to be thread-safe. @@ -813,6 +828,7 @@ namespace IvyBus EventHandler temp = ErrorMessage; FireEvent(temp, e); } +#if (SyncContext) internal virtual void OnDie(IvyDieEventArgs e) { // Copy to a temporary variable to be thread-safe. @@ -832,7 +848,22 @@ namespace IvyBus temp(this, e); } } - +#else + internal virtual void OnDie(IvyDieEventArgs e) + { + // Copy to a temporary variable to be thread-safe. + EventHandler temp = DieReceived; + if (temp != null) + { + if (parentControl != null) + { + parentControl.Invoke(temp, this, e); + } + else + temp(this, e); + } + } +#endif internal void OnMessage(IvyMessageEventArgs e) { IvyApplicationBinding bind = bindings[e.Id]; @@ -841,7 +872,7 @@ namespace IvyBus { throw new IvyException("(callCallback) Not regexp matching id " + e.Id); } - bind.Firevent(syncContext,e); + bind.Firevent(parentControl, e); } /* @@ -1104,7 +1135,8 @@ namespace IvyBus public void EndInit() { //TODO Autobinding attribute - //if (syncControl != null) + if (parentControl != null) + AutoBinding(parentControl); AutoBinding(Assembly.GetCallingAssembly()); // TODO ugly should be added directly the bindings Dictionary ! foreach (IvyApplicationBinding bind in app_bindings) -- cgit v1.1