private void OnNetworkMessageReceived(object sender, XDMessageEventArgs e) { if (disposed || !e.DataGram.IsValid) { return; } TypedDataGram <NetworkRelayMessage> dataGram = e.DataGram; if (dataGram != null && dataGram.IsValid && dataGram.Message.MachineName != Environment.MachineName) { // rebroadcast locally Task.Factory.StartNew( () => nativeBroadcast.SendToChannel(dataGram.Message.Channel, dataGram.Message.Message)); } }
/// <summary> /// The delegate which processes all cross AppDomain messages and writes them to screen. /// </summary> /// <param name = "sender"></param> /// <param name = "e"></param> private void OnMessageReceived(object sender, XDMessageEventArgs e) { // If called from a seperate thread, rejoin so that be can update form elements. if (InvokeRequired && !IsDisposed) { try { // onClosing messages may fail if the form is being disposed. Invoke((MethodInvoker)(() => OnMessageReceived(sender, e))); } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } } else { switch (e.DataGram.Channel.ToLower()) { case "status": // pain text UpdateDisplayText(e.DataGram.Channel, e.DataGram.Message); break; default: // all other channels contain serialized FormattedUserMessage object if (e.DataGram.AssemblyQualifiedName == typeof(FormattedUserMessage).AssemblyQualifiedName) { TypedDataGram <FormattedUserMessage> typedDataGram = e.DataGram; UpdateDisplayText(typedDataGram.Channel, typedDataGram.Message.FormattedTextMessage); } else { throw new NotSupportedException(string.Format("Unknown message type: {0}", e.DataGram.AssemblyQualifiedName)); } break; } } }
/// <summary> /// Handle the MessageReceived event and trace the message to standard debug. /// </summary> /// <param name = "sender"></param> /// <param name = "e"></param> private void OnMessageReceived(object sender, XDMessageEventArgs e) { // view these debug messages using SysInternals Dbgview. if (e.DataGram.AssemblyQualifiedName != typeof(FormattedUserMessage).AssemblyQualifiedName) { throw new NotSupportedException(string.Format("Unknown message type: {0}", e.DataGram.AssemblyQualifiedName)); } TypedDataGram <FormattedUserMessage> dataGram = e.DataGram; Debug.WriteLine("Test Service: " + e.DataGram.Channel + " " + dataGram.Message); if (dataGram.Message.FormattedTextMessage.EndsWith("STOP")) { broadcast.SendToChannel("Status", "Stopping trace"); isTraceEnabled = false; } else if (dataGram.Message.FormattedTextMessage.EndsWith("START")) { broadcast.SendToChannel("Status", "Starting trace"); isTraceEnabled = true; } }
private void OnMessageReceived(object sender, XDMessageEventArgs e) { if (InvokeRequired && !IsDisposed) { try { Invoke((MethodInvoker)(() => OnMessageReceived(sender, e))); } catch (ObjectDisposedException) { } catch (InvalidOperationException) { } } else { switch (e.DataGram.Channel.ToLower()) { case "status": UpdateDisplayText(e.DataGram.Channel, e.DataGram.Message); break; default: if (e.DataGram.AssemblyQualifiedName == typeof(FormattedUserMessage).AssemblyQualifiedName) { TypedDataGram <FormattedUserMessage> typedDataGram = e.DataGram; UpdateDisplayText(typedDataGram.Channel, typedDataGram.Message.FormattedTextMessage); } else { throw new NotSupportedException(string.Format("Unknown message type: {0}", e.DataGram.AssemblyQualifiedName)); } break; } } }