private void InitializeMode(XDTransportMode mode) { listener?.Dispose(); listener = client.Listeners.GetListenerForMode(mode); listener.MessageReceived += OnMessageReceived; if (statusCheckBox.Checked) { listener.RegisterChannel("Status"); } if (channel1Check.Checked) { listener.RegisterChannel("BinaryChannel1"); } if (channel2Check.Checked) { listener.RegisterChannel("BinaryChannel2"); } if (broadcast != null) { var message = $"{uniqueInstanceName} is changing mode to {mode}"; broadcast.SendToChannel("Status", message); } broadcast = client.Broadcasters.GetBroadcasterForMode(mode, propagateCheck.Checked); }
/// <summary> /// Broadcast a message that the service has started. /// </summary> /// <param name = "args"></param> protected override void OnStart(string[] args) { isTraceEnabled = true; client = new XDMessagingClient().WithAmazonSettings(RegionEndPoint.EUWest1); listener = client.Listeners.GetListenerForMode(XDTransportMode.Compatibility); listener.MessageReceived += OnMessageReceived; listener.RegisterChannel("BinaryChannel1"); listener.RegisterChannel("BinaryChannel2"); //only the following mode is supported in windows services broadcast = client.Broadcasters.GetBroadcasterForMode(XDTransportMode.Compatibility); broadcast.SendToChannel("Status", "Test Service has started: Send STOP on Channel 1/2 to halt timer. Send START to Channel 1/2 to restart."); cancelToken = new CancellationTokenSource(); Task.Factory.StartNew(() => { while (!cancelToken.IsCancellationRequested) { if (isTraceEnabled) { broadcast.SendToChannel("Status", "The time is: " + DateTime.Now.ToString("f")); Thread.Sleep(5000); } } }); }
/// <summary> /// Implementation of IDisposable used to clean up the listener instance. /// </summary> public void Dispose() { if (propagateListener != null) { propagateListener.Dispose(); propagateListener = null; } }
public MainWindow() { InitializeComponent(); var channel = XDChannelFactory.GetLocalChannel(Settings.Default.ChannelName_Status, Settings.Default.TransportMode); broadcast = channel.CreateBroadcast(); listener = channel.CreateListener(listener_MessageReceived); }
public IXDListener CreateListener(XDListener.XDMessageHandler handler) { IXDListener listener = XDListener.CreateListener(Mode, !Propagate); listener.RegisterChannel(Name); listener.MessageReceived += handler; return(listener); }
public void Start() { Console.WriteLine(string.Format("Register Channel '{0}'", Settings.Default.ChannelName_Commands)); var channel = XDChannelFactory.GetLocalChannel(Settings.Default.ChannelName_Commands, Settings.Default.TransportMode); broadcast = channel.CreateBroadcast(); listener = channel.CreateListener(MessageReceived); broadcast.SendToChannel(Settings.Default.ChannelName_Status, "Process started!"); }
public static void StartPrcMessaging() { if (_broadcast != null) { return; } _broadcast = XDBroadcast.CreateBroadcast(XDTransportMode.WindowsMessaging, false); _listener = XDListener.CreateListener(XDTransportMode.WindowsMessaging); _listener.MessageReceived += Listener_MessageReceived; _listener.RegisterChannel(channel); }
public ExplorerMonitorAdapter(SynchronizationContext synchronizationContext) { this.synchronizationContext = synchronizationContext ?? throw new ArgumentNullException(nameof(synchronizationContext)); messageClient = new XDMessagingClient(); broadcaster = messageClient.Broadcasters.GetBroadcasterForMode(XDTransportMode.HighPerformanceUI); sink = messageClient.Listeners.GetListenerForMode(XDTransportMode.HighPerformanceUI); sink.RegisterChannel("SelectionOfExplorerWindowChanged"); sink.MessageReceived += Sink_MessageReceived; }
public CommManager() { this.otherInstances = new List <LogViewerInstance>(); this.listener = XDListener.CreateListener(XDTransportMode.WindowsMessaging); this.broadcast = XDBroadcast.CreateBroadcast(XDTransportMode.WindowsMessaging, false); this.listener.RegisterChannel(myID.ToString()); //Channel only for me this.listener.RegisterChannel(ChannelBroadcast); //Channel for everyone listener.MessageReceived += new XDListener.XDMessageHandler(listener_MessageReceived); this.MainWindowHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; }
/// <summary> /// Default constructor. /// </summary> public TestService() { InitializeComponent(); this.ServiceName = "Test Service"; //only the following mode is supported in windows services broadcast = XDBroadcast.CreateBroadcast(XDTransportMode.IOStream); listener = XDListener.CreateListener(XDTransportMode.IOStream); listener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived); listener.RegisterChannel("Status"); listener.RegisterChannel("Channel1"); listener.RegisterChannel("Channel2"); }
internal NetworkRelayListener(IXDBroadcaster nativeBroadcast, IXDListener nativeListener, IXDListener propagateListener, XDTransportMode mode) { nativeBroadcast.Requires("nativeBroadcast").IsNotNull(); nativeListener.Requires("nativeListener").IsNotNull(); propagateListener.Requires("propagateListener").IsNotNull(); this.nativeBroadcast = nativeBroadcast; this.propagateListener = propagateListener; this.nativeListener = nativeListener; this.nativeListener.MessageReceived += OnMessageReceived; RegisterNetworkListener(mode); }
/// <summary> /// Default constructor. /// </summary> /// <param name = "nativeBroadcast"></param> /// <param name = "nativeListener"></param> /// <param name = "propagateListener"></param> /// <param name = "mode"></param> internal NetworkRelayListener(IXDBroadcaster nativeBroadcast, IXDListener nativeListener, IXDListener propagateListener, XDTransportMode mode) { Validate.That(nativeBroadcast).IsNotNull(); Validate.That(nativeListener).IsNotNull(); Validate.That(propagateListener).IsNotNull(); this.nativeBroadcast = nativeBroadcast; this.propagateListener = propagateListener; this.nativeListener = nativeListener; this.nativeListener.MessageReceived += OnMessageReceived; RegisterNetworkListener(mode); }
public void TestMethod1() { string channelName = "testChannel"; IXDChannel channel = XDChannelFactory.GetLocalChannel(channelName, XDTransportMode.IOStream); IXDBroadcast broadcast = channel.CreateBroadcast(); IXDListener listener = channel.CreateListener(MessageReceived); broadcast.SendToChannel(channelName, "test"); while (waitForMessage) { Thread.Sleep(200); } Assert.IsFalse(waitForMessage); }
/// <summary> /// Default constructor. /// </summary> /// <param name="nativeBroadcast"></param> /// <param name="propagateListener"></param> internal NetworkRelayListener(IXDBroadcast nativeBroadcast, IXDListener propagateListener) { if (nativeBroadcast == null) { throw new ArgumentNullException("nativeBroadcast"); } if (propagateListener == null) { throw new ArgumentNullException("propagateListener"); } this.nativeBroadcast = nativeBroadcast; this.propagateListener = propagateListener; // listen on the network channel for this mode this.propagateListener.RegisterChannel(NetworkRelayBroadcast.GetPropagateNetworkMailSlotName(nativeBroadcast)); this.propagateListener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived); }
/// <summary> /// Initialize the broadcast and listener mode. /// </summary> /// <param name = "mode">The new mode.</param> private void InitializeMode(XDTransportMode mode) { if (listener != null) { // ensure we dispose any previous listeners, dispose should aways be // called on IDisposable objects when we are done with it to avoid leaks listener.Dispose(); } // creates an instance of the IXDListener object using the given implementation listener = client.Listeners.GetListenerForMode(mode); // attach the message handler listener.MessageReceived += OnMessageReceived; // register the channels we want to listen on if (statusCheckBox.Checked) { listener.RegisterChannel("Status"); } // register if checkbox is checked if (channel1Check.Checked) { listener.RegisterChannel("BinaryChannel1"); } // register if checkbox is checked if (channel2Check.Checked) { listener.RegisterChannel("BinaryChannel2"); } // if we already have a broadcast instance if (broadcast != null) { // send in plain text var message = string.Format("{0} is changing mode to {1}", uniqueInstanceName, mode); broadcast.SendToChannel("Status", message); } // create an instance of IXDBroadcast using the given mode broadcast = client.Broadcasters.GetBroadcasterForMode(mode, propagateCheck.Checked); }
/// <summary> /// Initialize the broadcast and listener mode. /// </summary> /// <param name="mode">The new mode.</param> private void InitializeMode(XDTransportMode mode) { if (listener != null) { // ensure we dispose any previous listeners, dispose should aways be // called on IDisposable objects when we are done with it to avoid leaks listener.Dispose(); } // creates an instance of the IXDListener object using the given implementation listener = XDListener.CreateListener(mode); // attach the message handler listener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived); // register the channels we want to listen on if (statusCheckBox.Checked) { listener.RegisterChannel("Status"); } // register if checkbox is checked if (channel1Check.Checked) { listener.RegisterChannel("Channel1"); } // register if checkbox is checked if (channel2Check.Checked) { listener.RegisterChannel("Channel2"); } // if we already have a broadcast instance if (broadcast != null) { broadcast.SendToChannel("Status", string.Format("{0} is changing mode to {1}", this.Handle, mode)); } // create an instance of IXDBroadcast using the given mode, // note IXDBroadcast does not implement IDisposable broadcast = XDBroadcast.CreateBroadcast(mode, propagateCheck.Checked); }
/// <summary> /// Initialize the broadcast and listener mode. /// </summary> /// <param name="mode">The new mode.</param> public static void InitializeMode(XDTransportMode mode) { if (listener != null) { // ensure we dispose any previous listeners, dispose should aways be // called on IDisposable objects when we are done with it to avoid leaks listener.Dispose(); } listener = XDListener.CreateListener(mode); // attach the message handler listener.MessageReceived += OnMessageReceived; listener.RegisterChannel(CHANNEL_NAME); // create an instance of IXDBroadcast using the given mode, // note IXDBroadcast does not implement IDisposable broadcast = XDBroadcast.CreateBroadcast(mode, false); }
public LoadingForm() { InitializeComponent(); string[] args = Environment.GetCommandLineArgs(); if (args.Contains("-packing") || args.Contains("packing")) { labPacking.Visible = true; } else if (args.Contains("-unpacking") || args.Contains("unpacking")) { labUnpacking.Visible = true; } // Setup XDMessagingClient listener to receive progress updates XDMessagingClient client = new XDMessagingClient(); listener = client.Listeners.GetListenerForMode(XDTransportMode.HighPerformanceUI); listener.RegisterChannel("AppackerProgress"); // Attach event handler for incoming messages listener.MessageReceived += (o, ea) => { if (ea.DataGram.Channel == "AppackerProgress") { // 'Done' is sent when packing/unpacking is finished => close this splash if (ea.DataGram.Message == "Done") { progressBar.Value = progressBar.Maximum; Exit(); } // Other messages are progress updates else { string[] tokens = ea.DataGram.Message.Split(' '); progressBar.Maximum = int.Parse(tokens[1]); progressBar.Value = int.Parse(tokens[0]); } } }; }
public MonitorApplicationContext(CommandlineOptions commandline) { messageClient = new XDMessagingClient(); broadcaster = messageClient.Broadcasters.GetBroadcasterForMode(XDTransportMode.HighPerformanceUI); sink = messageClient.Listeners.GetListenerForMode(XDTransportMode.HighPerformanceUI); sink.RegisterChannel("ExplorerObserverCommand"); sink.MessageReceived += Sink_MessageReceived; observer = new ExplorerMonitor(); observer.ExplorerSelectionChanged += Observer_ExplorerSelectionChanged; observer.ExplorerWindowGotFocus += Observer_ExplorerWindowGotFocus; WatchParentProcessExit(commandline.ParentProcessId); observer.Start(); if (commandline.ShowDebugForm) { this.MainForm = new DebugForm(); this.MainForm.Show(); } }
public FTDataSource(string config) : base(config) { LogAndMessage.LogSource = "FTDataSource"; #region Context menu // main menu mReconnect = new ToolStripMenuItem("Connect", null, new EventHandler(mReconnect_Click)); mDisconnect = new ToolStripMenuItem("Disconnect", null, new EventHandler(mDisconnect_Click)); ToolStripSeparator mSeparator1 = new ToolStripSeparator(); mBackfill = new ToolStripMenuItem("Backfill Current"); mBackfillWL = new ToolStripMenuItem("Backfill Watchlist"); mBackfillAll = new ToolStripMenuItem("Backfill All"); mCancel = new ToolStripMenuItem("Cancel All Backfills", null, new EventHandler(mCancel_Click)); ToolStripSeparator mSeparator2 = new ToolStripSeparator(); mUpdateSymbolInfo = new ToolStripMenuItem("Update Symbol Data", null, mUpdateSymbolInfo_Click); mOpenIBContract = new ToolStripMenuItem("Open IB Contract", null, new EventHandler(mOpenIBContract_Click)); mFindIBContract = new ToolStripMenuItem("Find IB Contract", null, new EventHandler(mFindIBContract_Click)); ToolStripSeparator mSeparator3 = new ToolStripSeparator(); mOpenLogFile = new ToolStripMenuItem("Open Log File", null, new EventHandler(mOpenLogFile_Click)); // backfill submenu menu1Day = new ToolStripMenuItem("1 Day", null, new EventHandler(mBackfill_Click)); menu1Week = new ToolStripMenuItem("1 Week", null, new EventHandler(mBackfill_Click)); menu2Weeks = new ToolStripMenuItem("2 Weeks", null, new EventHandler(mBackfill_Click)); menu1Month = new ToolStripMenuItem("1 Month", null, new EventHandler(mBackfill_Click)); menu3Months = new ToolStripMenuItem("3 Months", null, new EventHandler(mBackfill_Click)); menu6Months = new ToolStripMenuItem("6 Months", null, new EventHandler(mBackfill_Click)); menu1Year = new ToolStripMenuItem("1 Year", null, new EventHandler(mBackfill_Click)); menuMax = new ToolStripMenuItem("Maximum", null, new EventHandler(mBackfill_Click)); // backfillWL submenu menu1DayWL = new ToolStripMenuItem("1 Day", null, new EventHandler(mBackfillWL_Click)); menu1WeekWL = new ToolStripMenuItem("1 Week", null, new EventHandler(mBackfillWL_Click)); menu2WeeksWL = new ToolStripMenuItem("2 Weeks", null, new EventHandler(mBackfillWL_Click)); menu1MonthWL = new ToolStripMenuItem("1 Month", null, new EventHandler(mBackfillWL_Click)); menu3MonthsWL = new ToolStripMenuItem("3 Months", null, new EventHandler(mBackfillWL_Click)); menu6MonthsWL = new ToolStripMenuItem("6 Months", null, new EventHandler(mBackfillWL_Click)); menu1YearWL = new ToolStripMenuItem("1 Year", null, new EventHandler(mBackfillWL_Click)); menuMaxWL = new ToolStripMenuItem("Maximum", null, new EventHandler(mBackfillWL_Click)); // backfillAll submenu menu1DayAll = new ToolStripMenuItem("1 Day", null, new EventHandler(mBackfillAll_Click)); menu1WeekAll = new ToolStripMenuItem("1 Week", null, new EventHandler(mBackfillAll_Click)); menu2WeeksAll = new ToolStripMenuItem("2 Weeks", null, new EventHandler(mBackfillAll_Click)); menu1MonthAll = new ToolStripMenuItem("1 Month", null, new EventHandler(mBackfillAll_Click)); menu3MonthsAll = new ToolStripMenuItem("3 Months", null, new EventHandler(mBackfillAll_Click)); menu6MonthsAll = new ToolStripMenuItem("6 Months", null, new EventHandler(mBackfillAll_Click)); menu1YearAll = new ToolStripMenuItem("1 Year", null, new EventHandler(mBackfillAll_Click)); menuMaxAll = new ToolStripMenuItem("Maximum", null, new EventHandler(mBackfillAll_Click)); // adding submenus mBackfill.DropDownItems.AddRange(new ToolStripItem[] { menu1Day, menu1Week, menu2Weeks, menu1Month, menu3Months, menu6Months, menu1Year, menuMax }); mBackfillWL.DropDownItems.AddRange(new ToolStripItem[] { menu1DayWL, menu1WeekWL, menu2WeeksWL, menu1MonthWL, menu3MonthsWL, menu6MonthsWL, menu1YearWL, menuMaxWL }); mBackfillAll.DropDownItems.AddRange(new ToolStripItem[] { menu1DayAll, menu1WeekAll, menu2WeeksAll, menu1MonthAll, menu3MonthsAll, menu6MonthsAll, menu1YearAll, menuMaxAll }); mContextMenu = new ContextMenuStrip(); mContextMenu.Items.AddRange(new ToolStripItem[] { mReconnect, mDisconnect, mSeparator1, mBackfill, mBackfillWL, mBackfillAll, mCancel, mSeparator2, mUpdateSymbolInfo, mOpenIBContract, mFindIBContract, mSeparator3, mOpenLogFile }); SetContextMenuState(); #endregion rtWindowTickersBck = new StringCollection(); timer = new System.Threading.Timer(timer_Tick); timer.Change(TimerInterval, TimerInterval); XDMessagingClient client = new XDMessagingClient(); // Create listener instance using HighPerformanceUI mode IXDListener listener = client.Listeners .GetListenerForMode(XDTransportMode.HighPerformanceUI); // Register channel to listen on listener.RegisterChannel("commands"); listener.MessageReceived += Listener_MessageReceived; }