/// <summary> /// Called when a new request from some instance of excel is made /// </summary> /// <param name="sender"></param> /// <param name="e">Arguments to the call</param> public void OnRequest(object sender, K2RTDServerKit.RequestEventArgs e) { // By convention, at KaiTrade we use the first 4 parameters as follows //=RTD("kaitrade.k2rtd","","WPUB","IBM", "BIDPX", "123.45", ) - reqType = WPUB subject =IBM, Header="BIDPX", Value="123.45" //=RTD("kaitrade.k2rtd","","PX","HPQ","ASKPX") - reqType PX, subject=HPQ, Header="ASKPX" string notUsed = e.parameters[0]; // not used string topicID = e.parameters[1]; // Excel topicID string reqType = e.parameters[2]; // Request Type string subject = e.parameters[3]; // Subject string headerName = e.parameters[4]; // Header Name // The accessID identifies the source of the message so must be used // when you want to support N connections to the server string accessID = e.accessID; // the use of other parameters may vary depending on your // application, if specified in this case parameter 5 is the value // assigned to the header if (e.parameters.Count() > 5) { string headerValue = e.parameters[5]; // Header value } int rtdTopicId = int.Parse(topicID); switch (reqType) { case "WPUB": // Web Publish // Swap the inbound parameter array into a string for debug string request = m_Handler.GetAsString(e.parameters); // Display the string in the list box - note that this needs to use // Invoke to swap threads to the GUI thread listBox1.Invoke((MethodInvoker)(() => listBox1.Items.Add(request) )); /// write a response into Excel m_Handler.TopicUpdate(e.accessID, e.rtdTopicID, DateTime.Now.ToString()); break; case "PX": // this is a request to subscribe m_Handler.Subscribe(subject, headerName, rtdTopicId, e.accessID); break; default: break; } }
/// <summary> /// Handle status updates from the connection to the RTD running in Excel /// </summary> /// <param name="channelStatus"></param> /// <param name="text"></param> public void OnStatusUpdate(object sender, K2RTDServerKit.StatusEventArgs e) { // Note you must use Invoke since the incomming call is on // a different thread from the GUI this.Invoke((MethodInvoker)(() => toolStripStatusLabel1.Text = e.text)); }