void OnlineMessage(IMessage message) { // We need to build a list of updates, this can then be used by the // RTD server interface to only send back topics that have changed. var now = DateTime.Now; var textMessage = message as ITextMessage; if (textMessage == null) { return; } var record = ExtractPositionRecord(textMessage.Text); record.Add("receiveTime", now.ToString()); // For each record build the cacheKey - the key would be configured var key = BuildPositionKey(record); // store each value var messageType = record["messageType"]; if ("BatchPosition".Equals(messageType)) { _positionCache.AddBatchCacheItem(key, record); _lastUpdateTime = now; RegisterChange(key, record); } else if ("OnlinePosition".Equals(messageType)) { _positionCache.AddOnlineCacheItem(key, record); _lastUpdateTime = now; RegisterChange(key, record); } else if ("HeartBeat".Equals(messageType)) { _heartBeatTime = DateTime.Now; RegisterGenericChange("heartBeat", _heartBeatTime.ToString()); } else if ("Command".Equals(messageType) && record["purgeRecordType"] != null) { _positionCache.ClearCaches(); _lastUpdateTime = now; // Force a recalc of the spreadsheet RegisterGenericChange("heartBeat", DateTime.Now.ToString()); } else { return; } if (_mXlRtdUpdate != null) { _mXlRtdUpdate.UpdateNotify(); } }
public void ToggleFeeding() { feedingToggle = !feedingToggle; if (feedingToggle) { if (rtdUpdateEvent != null) { rtdUpdateEvent.UpdateNotify(); } } }
public void ReceivedOrder(string compositeOrderId) { lock (nmsClient) { // We have the changed orders being tracked by the NmsClientApp, we could do it here instead. xlRTDUpdateCallbackHandler.UpdateNotify(); } }
void TopicChanged(object sender, TopicUpdateEvent e) { try { var message = e.EventMessage; var topic = message["TopicName"]; var brokerUrl = message["BrokerUrl"]; lock (_lockObject) { // put all the received fields into the cache foreach (var field in message) { var valueCacheKey = BuildValueCacheKey(brokerUrl, topic, field.Key); _topicValueCache[valueCacheKey] = field.Value; } // add fields that we are interested in to the change field list var fieldDetailList = GetFieldDetails(brokerUrl, topic); foreach (var field in fieldDetailList) { if (message.ContainsKey(field.Field) && !_changedTopics.Contains(field.TopicId)) { _changedTopics.Add(field.TopicId); } } } if (_xlRtdUpdateCallbackHandler != null) { _xlRtdUpdateCallbackHandler.UpdateNotify(); } } catch (Exception exception) { _log.Error("Tried to update topic", exception); } }
/** * calleback by GigaSpaces when event occured * EventArgs is the data of the event */ private void Space_DataChanged(object sender, SpaceDataEventArgs <HelloMsg> e) { //store in the _receivedData the data we got from the event _eventData = "Message ID: " + e.Pono.ID + " ('" + e.Pono.MSG + "') was set to Done!"; //Tell Excel that we have updates. Then the Excel calls back to RefreshData _xlRTDUpdate.UpdateNotify(); }
public object ConnectData(int topicId, ref Array strings, ref bool newValues) { var isin = strings.GetValue(0) as string; ExcelDna.Logging.LogDisplay.WriteLine("Connecting: {0} {1}", topicId, isin); lock (topics) { // create a listener for this topic var listener = new CalcListener(isin); listener.OnUpdate += (sender, args) => { try { if (callback != null) { callback.UpdateNotify(); } } catch (COMException comex) { ExcelDna.Logging.LogDisplay.WriteLine("Unable to notify Excel: {0}", comex.ToString()); } }; listener.Start(); topics.Add(topicId, listener); } return("WAIT"); }
void TimerEventHandler(object sender, EventArgs args) { m_timer.Stop(); UpdatePrices(); m_callback.UpdateNotify(); }
public int ServerStart(IRTDUpdateEvent CallbackObject) { updateNotify = new System.Action(delegate() { CallbackObject.UpdateNotify(); }); dispatcher = Dispatcher.CurrentDispatcher; return(1); }
/// <summary> /// 發送更新提示給Excel /// </summary> public void UpdateNotify() { try { m_Getter.GetRTDItem(m_Subscribes); m_xlRTDUpdate.UpdateNotify(); } catch (Exception) { } }
public void AddUpdatedTopicId(int topicId) { try { lock (m_updatedTopicIds) { if (!m_updatedTopicIds.Contains(topicId)) { m_updatedTopicIds.Add(topicId); } } m_callback.UpdateNotify(); } catch //(COMException comException) { // comException.Message = "The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))" // Console.WriteLine(comException.Message); } }
void TimerCallbackHandler(object state) { var pattern = state.ToString(); _nowCache[pattern] = "TODAY" == pattern?DateTime.Now.Date.ToOADate() : DateTime.Now.ToOADate(); if (!_updatedPattern.Contains(pattern)) { _updatedPattern.Add(pattern); } _updateEventHandler.UpdateNotify(); }
private void Callback(object sender, EventArgs e) { // Stops timer and tells all queries to run their async delegates _timer.Stop(); lock (_queries) { foreach (KeyValuePair <int, Query> q in _queries) { q.Value.AsyncImport(); } } _callback.UpdateNotify(); }
public object ConnectData(int TopicId, ref Array Strings, ref bool GetNewValues) { if (Strings.Length != 2) { throw new Exception("Error: Must supply ContractId and TickType!"); } string contractKey = Strings.GetValue(0) as string; // The key in OM. Contract cc = XLOM.Get <Contract>(contractKey); int contractId = cc.Id; string contractCcy = cc.Currency; IBTickType tickType = (IBTickType)Enum.Parse(typeof(IBTickType), Strings.GetValue(1) as string, true); // If we're not already subscribed to this contract, crank up TWSSource. if (!(TopicsToContractIds.ContainsKey(TopicId) && TopicsToTickTypes.ContainsKey(TopicId))) { TopicsToContractIds.Add(TopicId, contractId); TopicsToTickTypes.Add(TopicId, tickType); if (!ContractsToMarkets.ContainsKey(contractId)) { ContractsToMarkets.Add(contractId, new Market(DateTimeOffset.UtcNow, contractId, -1, -1)); ContractsUpdated.Add(contractId, true); XL_RTD.DataSource.Subscribe(cc); XL_RTD.Ether.AsObservable <Market>().Where(x => x.ContractId == contractId).Subscribe(x => { ContractsToMarkets[x.ContractId] = x; ContractsUpdated[x.ContractId] = true; try { RTDCallback.UpdateNotify(); } catch (Exception e) { Debug.WriteLine(e.StackTrace); } }, e => { Debug.WriteLine(e.ToString()); }); } } return("(WAITING)"); }
public virtual int ServerStart(IRTDUpdateEvent callback) { if (SecretariumFunctions.Logger.IsDebugEnabled) { SecretariumFunctions.Logger.Debug(@"RequestRtdServer starting"); } _callback = callback; _requesIdToTopics = new Dictionary <string, int>(); _topicsToRequestId = new Dictionary <int, string>(); _xlRequestToRequestId = new Dictionary <XlRequest, string>(); _requestIdToPayload = new Dictionary <string, string>(); // This Windows.Forms Single threaded (UI thread) timer must be started in this correct COM appartment _timer = new System.Windows.Forms.Timer { Interval = 1000 }; _timer.Tick += (object sender, EventArgs args) => { _timer.Stop(); lock (_updatesLocker) { CleanUpUpdates(); if (_updates.Count > 0) { _callback.UpdateNotify(); } } _timer.Start(); }; SecretariumFunctions.Scp.OnMessage += OnMessage; SecretariumFunctions.Scp.OnStateChange += x => { SetValue(RtdTypes.ConnectionState, SecretariumFunctions.Scp.State.ToString()); }; if (SecretariumFunctions.Logger.IsDebugEnabled) { SecretariumFunctions.Logger.Debug(@"RequestRtdServer started"); } return(1); // 1 means OK }
private void job(object sender, EventArgs args) { _callback.UpdateNotify(); var techXApp = "daominah_electron_demo"; System.Diagnostics.Process[] pname = System.Diagnostics.Process.GetProcessesByName(techXApp); if (pname.Length == 0) { _isElectronStopped = true; // Console.WriteLine("{0} stopped", techXApp); } else { _isElectronStopped = false; // Console.WriteLine("{0} is running", techXApp); } }
}//RefreshData() // #endregion//RTD Event Handlers #region Event Handlers // ***************************************************************** // **** Event Handlers **** // ***************************************************************** /// <summary> /// This is called periodically using a thread from a thread pool. /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs eventArgs) { OnUpdateNotify(); // Check if topics have changed. bool notifyExcel = false; foreach (TopicBase topic in m_Topics.Values) { if (topic.IsChangedSinceLastRead) { notifyExcel = true; break; } } if (notifyExcel) { m_RtdUpdateEvent.UpdateNotify(); } }
private void TimerEventHandler(object sender, EventArgs args) { bool updatesExist = false; foreach (string formula in this.formulas) { // push to update queue if (updateQueue.Count() < updateQueueMaxLength) { int topicId; if (reverseTopicIdMap.TryGetValue(formula, out topicId)) { updatesExist = true; updateQueue.Enqueue(new RtdUpdateQueueItem(topicId, formula, provider.QueryData(formula))); } } } if (updatesExist && (rtdUpdateEvent != null)) { rtdUpdateEvent.UpdateNotify(); } }
private void Callback(object sender, EventArgs e) { // foreach (int topicId in m_bland.Keys) { Source source; Field field; if (!Enum.TryParse <Source>(m_source[topicId], out source)) { continue; } if (!Enum.TryParse <Field>(m_field[topicId], out field)) { continue; } m_extractor.Load(source, m_bland[topicId]); m_data[topicId] = m_extractor.GetMarketData(m_bland[topicId], field); } m_callback.UpdateNotify(); }
public int ServerStart(IRTDUpdateEvent rtdUpdateEvent) { _timer = new Timer(delegate { rtdUpdateEvent.UpdateNotify(); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); return 1; }
/// <summary> /// 發送更新提示給Excel /// </summary> public void UpdateNotify() { m_Getter.GetRTDItem(m_Subscribes); m_xlRTDUpdate.UpdateNotify(); }
private void TimerEventHandler(Object source, ElapsedEventArgs e) { m_NotifyPeriodTimer.Stop();//Stopping the timer is important since we don’t want to call UpdateNotify repeatedly m_callback.UpdateNotify(); }
// Notify Excel of updated results private void PostUpdateNotify() { // Must only call rtdUpdateEvent.UpdateNotify() from the thread that calls ServerStart. // Use synchronizationContext which captures the thread dispatcher. synchronizationContext.Post(delegate(object state) { _rtdUpdateEvent.UpdateNotify(); }, null); }
public int ServerStart(IRTDUpdateEvent CallbackObject) { updateNotify = new System.Action(delegate() { CallbackObject.UpdateNotify(); }); dispatcher = Dispatcher.CurrentDispatcher; return 1; }
private void TimeEventHandler(object sender, ElapsedEventArgs e) { callback.UpdateNotify(); }
protected void OnTimerEvent(object o, ElapsedEventArgs e) { m_timer.Stop( ); m_callback.UpdateNotify( ); }
private void TimerEventHandler(object sender, EventArgs args) { theTimer.Stop(); theCallback.UpdateNotify(); }
private void Callback(object sender, EventArgs e) { _timer.Stop(); _callback.UpdateNotify(); }
void task_OnComplete(object sender, EventArgs e) { _callback.UpdateNotify(); }
public int ServerStart(IRTDUpdateEvent rtdUpdateEvent) { _timer = new Timer(delegate { rtdUpdateEvent.UpdateNotify(); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(5)); return(1); }
/* TimerEventHandler is the private method that is called when the timer Tick event is raised. It stops the timer and * uses the callback interface to let Excel know that updates are available. Stopping the timer is important since we * don’t want to call UpdateNotify repeatedly. */ void timer_Tick(object sender, EventArgs e) { m_timer.Stop(); m_callback.UpdateNotify(); }