From 34ed1bccaf5ed6dfeddfdf62a2f082e6eae65daf Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:44:21 +0000 Subject: Utilisateur : Fcolin Date : 30/06/06 Heure : 16:43 Archivé dans $/CSharp/Ivy/IvyPPC Commentaire: (vss 70) --- CSharp/Ivy/Ivy/Ivy.cs | 92 ++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/CSharp/Ivy/Ivy/Ivy.cs b/CSharp/Ivy/Ivy/Ivy.cs index 5ae69d6..892ed0f 100644 --- a/CSharp/Ivy/Ivy/Ivy.cs +++ b/CSharp/Ivy/Ivy/Ivy.cs @@ -23,7 +23,9 @@ namespace IvyBus using System.ComponentModel; using System.Diagnostics; +#if (!PocketPC) using System.ComponentModel.Design; +#endif // using System.Drawing.Design; @@ -194,14 +196,15 @@ namespace IvyBus /// #if (!PocketPC) [Category("Ivy")] -#endif + [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] // sinon bug System.String constructor not found ! [Editor( "System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor,System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" )] - public StringCollection SentMessageFilter +#endif + public List SentMessageFilter { get { @@ -226,6 +229,7 @@ namespace IvyBus #if (!PocketPC) [Category("Ivy")] #endif +#if (PocketPC) [DefaultValue(null)] public System.Windows.Forms.ContainerControl ContainerControl { @@ -235,11 +239,11 @@ namespace IvyBus parentControl = value; } } - +#endif #if (!PocketPC) [Category("Ivy")] -#endif [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] +#endif public List Bindings { get { return app_bindings; } @@ -275,7 +279,7 @@ namespace IvyBus //TODO should be remove samve as above private List app_bindings; private List clients; - private StringCollection sent_messageFilter; + private List sent_messageFilter; private bool stopped = true; internal ushort applicationPort; /* Application port number */ internal IPAddress applicationHost; /* Application host number */ @@ -284,31 +288,31 @@ namespace IvyBus private string ready_message; private CultureInfo culture = new CultureInfo("en-us"); // for synchronous event -#if (SyncContext) - private readonly SynchronizationContext syncContext; -#else +#if (PocketPC) private System.Windows.Forms.ContainerControl parentControl; -#endif - +#else + private readonly SynchronizationContext syncContext; +#endif + public Ivy() { -#if (SynContext) +#if (!PocketPC) syncContext = SynchronizationContext.Current; #endif clients = new List(); bindings = new Dictionary(); app_bindings = new List(); - sent_messageFilter = new StringCollection(); + sent_messageFilter = new List(); #if (!PocketPC) debug = Properties.Settings.Default.IvyDebug; protocolVersion = Properties.Settings.Default.IvyProtocolVersion; #endif } - public Ivy(System.Windows.Forms.ContainerControl parentControl) + public Ivy(IContainer container) : this() { - this.parentControl = parentControl; + container.Add(this); } /// Readies the structures for the software bus connexion. /// @@ -403,7 +407,7 @@ namespace IvyBus // Autobinding on IvyBindingAttribute method public void AutoBinding(Assembly assy) { - foreach (Type typ in assy.GetExportedTypes()) + foreach (Type typ in assy.GetTypes()) { AutoBinding(typ); } @@ -746,37 +750,38 @@ namespace IvyBus v[i].stream.TokenPing(message); return v.Count; } -#if (SyncContext) +#if (PocketPC) internal virtual void FireEvent(EventHandler ev, IvyEventArgs e) { if (ev != null) { - if (syncContext != null) + if (parentControl != null) { - SendOrPostCallback update = delegate(object state) - { - IvyEventArgs args = (IvyEventArgs)state; - ev(this, args); - }; - syncContext.Send(update, e); + parentControl.Invoke(ev, this, e); } else ev(this, e); } } #else - internal virtual void FireEvent(EventHandler ev, IvyEventArgs e) + internal virtual void FireEvent(EventHandler ev, IvyEventArgs e) { if (ev != null) { - if (parentControl != null) + if (syncContext != null) { - parentControl.Invoke(ev, this, e); + SendOrPostCallback update = delegate(object state) + { + IvyEventArgs args = (IvyEventArgs)state; + ev(this, args); + }; + syncContext.Send(update, e); } else ev(this, e); } } + #endif internal virtual void OnDirectMessage(IvyEventArgs e) { @@ -828,26 +833,22 @@ namespace IvyBus EventHandler temp = ErrorMessage; FireEvent(temp, e); } -#if (SyncContext) +#if (PocketPC) internal virtual void OnDie(IvyDieEventArgs e) { // Copy to a temporary variable to be thread-safe. EventHandler temp = DieReceived; if (temp != null) { - if (syncContext != null) + if (parentControl != null) { - SendOrPostCallback update = delegate(object state) - { - IvyDieEventArgs args = (IvyDieEventArgs)state; - temp(this, args); - }; - syncContext.Send(update, e); + parentControl.Invoke(temp, this, e); } else temp(this, e); } } + #else internal virtual void OnDie(IvyDieEventArgs e) { @@ -855,9 +856,14 @@ namespace IvyBus EventHandler temp = DieReceived; if (temp != null) { - if (parentControl != null) + if (syncContext != null) { - parentControl.Invoke(temp, this, e); + SendOrPostCallback update = delegate(object state) + { + IvyDieEventArgs args = (IvyDieEventArgs)state; + temp(this, args); + }; + syncContext.Send(update, e); } else temp(this, e); @@ -934,13 +940,13 @@ namespace IvyBus } return returnaddr; } - + public static string GetDomain(string domainbus) { -#if (PocketPC) +#if (PocketPC) // TODO integrate in normal version if (domainbus == null || domainbus.Length == 0) { - IPAddress addr = getLocalIP(); + IPAddress addr = GetLocalIP(); //TODO Find Braodcast addr from IP; byte[] bytes = addr.GetAddressBytes(); if (IPAddress.IsLoopback(addr)) @@ -957,7 +963,7 @@ namespace IvyBus bytes[3] = 255; } IPAddress bcast = new IPAddress(bytes); - domainbus = bcast + ":" + IvyWatcher.getPort(domainbus); + domainbus = bcast + ":" + Domain.getPort(domainbus); } #else if (domainbus == null || domainbus.Length == 0 ) @@ -1088,7 +1094,7 @@ namespace IvyBus { return domainaddr + ":" + port; } - private static string getDomain(string net) + public static string getDomain(string net) { int sep_index = net.LastIndexOf(":"); if (sep_index != -1) @@ -1109,7 +1115,7 @@ namespace IvyBus return net; } - private static int getPort(string net) + public static int getPort(string net) { if (net == null) return Ivy.DEFAULT_PORT; int sep_index = net.LastIndexOf(":"); @@ -1135,8 +1141,10 @@ namespace IvyBus public void EndInit() { //TODO Autobinding attribute +#if (PocketPC) if (parentControl != null) AutoBinding(parentControl); +#endif AutoBinding(Assembly.GetCallingAssembly()); // TODO ugly should be added directly the bindings Dictionary ! foreach (IvyApplicationBinding bind in app_bindings) -- cgit v1.1