void LightRequestReceived(DetailedDelivery delivery) { long checksum = CheckSum(delivery.Message()); GC.Collect(); GC.WaitForPendingFinalizers(); StringBuilder receiptTerms = new StringBuilder(delivery.ReceiptTerminalNames()[0]); for (int i = 1; i < delivery.ReceiptTerminalNames().Length; i++) { receiptTerms.Append(","); receiptTerms.Append(delivery.ReceiptTerminalNames()[i]); } string[] item = new string[] { DateTime.Now.ToShortTimeString(), delivery.Message().Length.ToString(), checksum.ToString(), receiptTerms.ToString(), delivery.SourceApplication(), delivery.SourceHost(), delivery.SourceTerminalName(), uxRespShowReq.Checked ? delivery.MessageString() : "" }; if (uxRespList.Items.Count >= Convert.ToInt32(uxRespMax.Value)) { uxRespList.Items.RemoveAt(0); } uxRespList.Items.Add(new ListViewItem(item)); uxStatusText.Text = "Request received."; }
/* Requester */ static void cMain(string[] args) { // create the cient LightrailClient client = new LightrailClient("name", "description"); // start the client client.StartDeliveries(); // register the requester terminal client.RegisterTerminal(TerminalStandpoint.Requester, "ReqTerminal", "ReqDesc", "[Global>Company>Region>Domain>App>Instance>Request]"); // create a request message Delivery request = new Delivery("This is a string message that will be encoded as UTF-8"); // send the request and get the response with a 30 second timeout DetailedDelivery response = client.Request("ReqTerminal", request, 30000); // parse the response string responseString = response.MessageString(); // send more and more and more requests // close the instance client.StopDeliveries(); }
static Delivery client_OnRequestReceived(DetailedDelivery delivery) { // get the request message as a string string message = delivery.MessageString(); Delivery response = new Delivery("The response message."); return(response); }
void LightPublishReceived(DetailedDelivery delivery) { long checksum = CheckSum(delivery.Message()); // get average bytes per second m_subReceived.Add(new KeyValuePair <DateTime, long>(DateTime.Now, delivery.Message().Length)); m_subReceivedTotal += delivery.Message().Length; DateTime watchTime = DateTime.Now.AddSeconds(-20); while (m_subReceived.Count > 0 && m_subReceived[0].Key < watchTime) { m_subReceivedTotal -= m_subReceived[0].Value; m_subReceived.RemoveAt(0); } if (m_subReceived.Count > 1) { TimeSpan span = m_subReceived[m_subReceived.Count - 1].Key - m_subReceived[0].Key; uxSubRcvPerSec.Text = (((double)m_subReceivedTotal / span.TotalSeconds) / 1024.0).ToString(); } else { uxSubRcvPerSec.Text = "Not Enough"; } GC.Collect(); GC.WaitForPendingFinalizers(); StringBuilder receiptTerms = new StringBuilder(delivery.ReceiptTerminalNames()[0]); for (int i = 1; i < delivery.ReceiptTerminalNames().Length; i++) { receiptTerms.Append(","); receiptTerms.Append(delivery.ReceiptTerminalNames()[i]); } string[] item = new string[] { DateTime.Now.ToShortTimeString(), delivery.Message().Length.ToString(), checksum.ToString(), receiptTerms.ToString(), delivery.SourceApplication(), delivery.SourceHost(), delivery.SourceTerminalName(), uxSubShowText.Checked ? delivery.MessageString() : "" }; if (uxSubList.Items.Count >= Convert.ToInt32(uxSubMaxShow.Value)) { uxSubList.Items.RemoveAt(0); } uxSubList.Items.Add(new ListViewItem(item)); uxSubNumMsg.Text = (Int32.Parse(uxSubNumMsg.Text) + 1).ToString(); uxStatusText.Text = "Publication received."; }
private void uxReqSend_Click(object sender, EventArgs e) { try { uxReqList.Items.Clear(); Delivery delivery = new Delivery(uxReqMsg.Text); int numToSend = Convert.ToInt32(uxReqNumSend.Value); for (int i = 0; i < numToSend; i++) { IAsyncResult result = m_doRequest.BeginInvoke(uxReqTermName.Text, delivery, null, null); result.AsyncWaitHandle.WaitOne(); if (!result.IsCompleted) { throw new Exception("The event wait failed?"); } DetailedDelivery response = null; if (m_response is Exception) { throw (Exception)m_response; } else { response = (DetailedDelivery)m_response; } if (uxReqList.Items.Count >= Convert.ToInt32(uxReqMaxShow.Value)) { uxReqList.Items.RemoveAt(0); } uxReqList.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToShortTimeString(), response.Message().Length.ToString(), response.SourceApplication(), response.SourceHost(), uxRespShowMsg.Checked ? response.MessageString() : "", })); uxReqNumSent.Text = String.Format("Req/Resp {0} of {1}", (i + 1), numToSend); } uxStatusText.Text = "Request/Response(s) completed."; } catch (Exception ex) { MessageBox.Show("Failed to request: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void SendRequest(string terminal, Delivery message) { try { DetailedDelivery response = m_client.Request(uxReqTermName.Text, message, 30000, Convert.ToInt32(uxReqNumResponders.Value)); m_response = response; } catch (Exception ex) { m_response = ex; } }
Delivery m_client_OnRequestReceived(DetailedDelivery delivery) { this.BeginInvoke(m_lightReqReceived, delivery); if (uxRespFile.Checked) { lock (this) { if (m_loadedResponse == null) { return(null); } else { return(new Delivery(m_loadedResponse, DeliveryEncoding.None)); } } } else { return(new Delivery(uxRespTextTexas.Text)); } }
private void m_client1_OnPublishReceived(DetailedDelivery delivery) { Assert.AreEqual(m_encoding, delivery.Encoding()); Assert.IsTrue(TestHelper.CompareStringArrayUnstable(m_labelNameList, delivery.GetLabelNameList())); Assert.IsTrue(TestHelper.CompareByteArray(m_message, delivery.Message())); Assert.IsTrue(TestHelper.CompareStringArray(m_receiptTerms, delivery.ReceiptTerminalNames())); Assert.IsTrue(m_sendTimeStart <= delivery.SendTimeUtc().AddSeconds(1)); Assert.IsTrue(m_sendTimeStart.AddMinutes(5) >= delivery.SendTimeUtc().AddSeconds(1)); Assert.AreEqual(m_sourceApp, delivery.SourceApplication()); Assert.AreEqual(Environment.MachineName, delivery.SourceHost()); Assert.AreEqual(m_sourceTerm, delivery.SourceTerminalName()); foreach (string label in m_labelNameList) { Assert.AreEqual(m_labels[label], delivery.Label(label)); } m_numReceived++; if (m_numReceived == m_numExpected) { m_wait.Set(); } }
static void client_OnPublishReceived(DetailedDelivery delivery) { // get the message as a string string message = delivery.MessageString(); }
void m_client_OnPublishReceived(DetailedDelivery delivery) { this.BeginInvoke(m_lightPubReceived, delivery); }