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> /// 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> /// 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"); }
/// <summary> /// Adds or removes the Message channel from the messaging API. This effects whether messages /// sent on this channel will be received by the application. Status messages are broadcast /// on the Status channel whenever this setting is changed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void channel1_CheckedChanged(object sender, EventArgs e) { if (channel1Check.Checked) { listener.RegisterChannel("Channel1"); broadcast.SendToChannel("Status", string.Format("{0} is registering Channel1.", this.Handle)); } else { listener.UnRegisterChannel("Channel1"); broadcast.SendToChannel("Status", string.Format("{0} is unregistering Channel1.", this.Handle)); } }
private void Channel1CheckedChanged(object sender, EventArgs e) { if (channel1Check.Checked) { listener.RegisterChannel("BinaryChannel1"); var message = $"{uniqueInstanceName} is registering Channel1."; broadcast.SendToChannel("Status", message); } else { listener.UnRegisterChannel("BinaryChannel1"); var message = $"{uniqueInstanceName} is unregistering Channel1."; broadcast.SendToChannel("Status", message); } }
private void RegisterNetworkListener(XDTransportMode mode) { if (disposed) { return; } if (!IsAlive) { return; } Task.Factory.StartNew(() => { propagateListener.RegisterChannel( NetworkRelayBroadcaster.GetNetworkListenerName(mode)); propagateListener.MessageReceived += OnNetworkMessageReceived; }).ContinueWith(t => { // ReSharper disable once UnusedVariable var e = t.Exception; if (disposed) { return; } Thread.Sleep(NetworkReTryTimeoutMilliSeconds); RegisterNetworkListener(mode); }, TaskContinuationOptions.OnlyOnFaulted); }
private void RegisterNetworkListener(XDTransportMode mode) { if (disposed) { return; } if (!IsAlive) { return; } // listen on the network channel for this mode Task.Factory.StartNew(() => { propagateListener.RegisterChannel( NetworkRelayBroadcaster.GetNetworkListenerName(mode)); propagateListener.MessageReceived += OnNetworkMessageReceived; }).ContinueWith(t => { var e = t.Exception; if (!disposed) { Thread.Sleep(networkReTryTimeoutMilliSeconds); // retry attach listener RegisterNetworkListener(mode); } }, TaskContinuationOptions.OnlyOnFaulted); }
public IXDListener CreateListener(XDListener.XDMessageHandler handler) { IXDListener listener = XDListener.CreateListener(Mode, !Propagate); listener.RegisterChannel(Name); listener.MessageReceived += handler; return(listener); }
/// <summary> /// Adds or removes the Message channel from the messaging API. This effects whether messages /// sent on this channel will be received by the application. Status messages are broadcast /// on the Status channel whenever this setting is changed. /// </summary> /// <param name = "sender"></param> /// <param name = "e"></param> private void Channel1CheckedChanged(object sender, EventArgs e) { if (channel1Check.Checked) { listener.RegisterChannel("BinaryChannel1"); // send in pain text var message = string.Format("{0} is registering Channel1.", uniqueInstanceName); broadcast.SendToChannel("Status", message); } else { listener.UnRegisterChannel("BinaryChannel1"); // send in pain text var message = string.Format("{0} is unregistering Channel1.", uniqueInstanceName); broadcast.SendToChannel("Status", message); } }
public void RegisterChannel(string channelName) { if (disposed) { return; } nativeListener.RegisterChannel(channelName); }
/// <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); }
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; }
/// <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(); } }
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); }
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; }
/// <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); }