/// <summary> Creates an IpcEventChannel that persists state in IChannelRegistrar provided </summary> /// <param name="registrar">The serialization provider for registration</param> /// <param name="channelName">The name of the channel to subscribe or send events to</param> public IpcEventChannel(IIpcChannelRegistrar registrar, string channelName) { _sync = new object(); _instanceId = Guid.NewGuid().ToString(); _registrar = Check.NotNull(registrar); _channelName = Check.NotEmpty(channelName); _events = new Event[0]; OnModified += Ignore; }
/// <summary> Creates an IpcEventChannel that persists state in IChannelRegistrar provided </summary> /// <param name="registrar">The serialization provider for registration</param> /// <param name="channelName">The name of the channel to subscribe or send events to</param> public IpcEventChannel(IIpcChannelRegistrar registrar, string channelName) { _sync = new object(); _instanceId = Guid.NewGuid().ToString(); _registrar = Check.NotNull(registrar); _channelName = Check.NotEmpty(channelName); _events = new Event[0]; OnModified += Ignore; }
public virtual void Teardown() { _registrar = null; Registry.CurrentUser.DeleteSubKeyTree(KeyPath); }
public virtual void Setup() { _registrar = new IpcChannelRegistrar(Registry.CurrentUser, KeyPath); }
public static void RUN() { _registrar = new IpcChannelRegistrar(Registry.CurrentUser, KeyPath); using (IpcEventChannel ch1 = new IpcEventChannel(_registrar, _channel)) using (IpcEventChannel ch2 = new IpcEventChannel(_registrar, _channel)) using (IpcEventChannel sender = new IpcEventChannel(_registrar, _channel)) { ch1.StartListening("ch1"); ch2.StartListening("ch2"); sender.EnableAsyncSend(); //////////////////////////////////////////////////////////////////// ch1["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e) { Console.WriteLine(string.Format("LISTENING_{0}: {1}", 1, String.Join(",", e.Arguments))); }; ch2["Message"].OnEvent += delegate(object o, IpcSignalEventArgs e) { Console.WriteLine(string.Format("LISTENING_{0}: {1}", 2, String.Join(",", e.Arguments))); }; sender.ExecutionTimeout = 1000; Console.WriteLine("Enter to SEND broadcast to CHANNEL LISTENING ..."); Console.ReadLine(); sender.SendTo("CH1", "Message", "p1", "p2", "p3"); sender.SendTo(new string[] { "CH2" }, "Message", "p1", "p2", "p3"); sender.SendTo(1000, new string[] { "ch1", "ch2" }, "Message", "p1", "p2", "p3"); //////////////////////////////////////////////////////////////////// //ch1.OnError += delegate (object o, ErrorEventArgs e) //{ // string error = e.GetException().Message; // Console.WriteLine(string.Format("LISTENING_ERROR: {0}", error)); //}; //ch1["Test"].OnEvent += delegate (object o, IpcSignalEventArgs e) //{ // Console.WriteLine(string.Format("LISTENING_{0}: {1}", 1, String.Join(",", e.Arguments))); //}; //ch2["Test"].OnEvent += delegate (object o, IpcSignalEventArgs e) //{ // Console.WriteLine(string.Format("LISTENING_{0}: {1}", 2, String.Join(",", e.Arguments))); //}; //Console.WriteLine("Enter to SEND broadcast to CHANNEL LISTENING ..."); //Console.ReadLine(); //for (int i = 0; i < 1000; i++) //{ // //sender.SendTo(10000, i % 2 == 0 ? "ch1" : "ch2", "Test", "p1", "p2", "p3"); // sender.Broadcast(100, "Test", "1", "2", "3"); //} //////////////////////////////////////////////////////////////////// sender.StopAsyncSending(true, -1); ch1.StopListening(); ch2.StopListening(); } ///////////////////////////////////////// /// FREE RESOURCE Console.WriteLine("Enter to exit..."); Console.ReadLine(); _registrar = null; Registry.CurrentUser.DeleteSubKeyTree(KeyPath); }
public virtual void Teardown() { _registrar = null; Registry.CurrentUser.DeleteSubKeyTree(KeyPath); }
public virtual void Setup() { _registrar = new IpcChannelRegistrar(Registry.CurrentUser, KeyPath); }