summaryrefslogtreecommitdiff
path: root/CSharp/Ivy/IvyPPC
diff options
context:
space:
mode:
authorfcolin2007-02-01 09:56:12 +0000
committerfcolin2007-02-01 09:56:12 +0000
commitdf898a41f338af6b69b7cc03de9c71bc3e79d8ca (patch)
tree0cb0b1683b822577c811265986de723bc60330b6 /CSharp/Ivy/IvyPPC
parent4574d0630db042cf82b29ffa37824e8ae93da44f (diff)
downloadivy-csharp-df898a41f338af6b69b7cc03de9c71bc3e79d8ca.zip
ivy-csharp-df898a41f338af6b69b7cc03de9c71bc3e79d8ca.tar.gz
ivy-csharp-df898a41f338af6b69b7cc03de9c71bc3e79d8ca.tar.bz2
ivy-csharp-df898a41f338af6b69b7cc03de9c71bc3e79d8ca.tar.xz
Utilisateur : Fcolin Date : 30/06/06 Heure : 13:40 Archivé dans $/CSharp/Ivy/Ivy Commentaire: gestion designer (vss 68)
Diffstat (limited to 'CSharp/Ivy/IvyPPC')
-rw-r--r--CSharp/Ivy/IvyPPC/Ivy.cs174
1 files changed, 84 insertions, 90 deletions
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;
/// <summary> The Main bus Class
@@ -57,7 +55,7 @@ namespace IvyBus
public event EventHandler<IvyEventArgs> BindingAdd;
/// <summary>fires when a client receive a remove binding from another client</summary>
public event EventHandler<IvyEventArgs> BindingRemove;
- /// <summary>fires when a client receive a binding from another clientand it as been filtered </summary>
+ /// <summary>fires when a client receive a binding from another client and it as been filtered </summary>
public event EventHandler<IvyEventArgs> BindingFilter;
/// <summary>fires when a client receive a remove binding from another client</summary>
public event EventHandler<IvyEventArgs> 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<IvyApplicationBinding> 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<IvyClient>();
bindings = new Dictionary<int, IvyApplicationBinding>();
app_bindings = new List<IvyApplicationBinding>();
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);
+ }
/// <summary> Readies the structures for the software bus connexion.
/// </summary>
/// <example> This sample shows how to start working with Ivy.
@@ -337,22 +331,13 @@ namespace IvyBus
/// </param>
/// <param name='message'>The hellow message you will send once ready
/// </param>
- 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);
+ }
+
+ }
/// <summary> connects the Ivy bus to a domain or list of domains.
/// </summary>
/// <remarks>
@@ -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<IvyEventArgs> 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<IvyDieEventArgs> 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<IvyMessageEventArgs> 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