public ShellViewModel( ITimerHandler timerHandler, IPlaybackHandler playbackHandler, ICommandHandler commandHandler ) { this.TimerHandler = timerHandler; this.playbackHandler = playbackHandler; this.TimerHandler.TimedEventCompleted += ( se, ea ) => { this.playbackHandler.PlayTimedEventComplete( se as TimedEvent ); }; commandHandler.CommandRecognized += ( se, ea ) => { this.playbackHandler.PlayCommandAccepted(); var command = se as Command; if ( command.Verb == "time" ) { this.TimerHandler.Start( command.Noun ); } else if ( command.Verb == "clear" ) { this.TimerHandler.Clear( command.Noun ); } }; }
public void RemoveTimer(ITimerHandler timer) { if (timerList.Contains(timer)) { timerList.Remove(timer); } }
/// <summary> /// 杀掉一个定时器 /// </summary> /// <param name="timerID">定时器ID</param> /// <param name="handler">处理接口</param> /// <returns>成功失败</returns> public bool DeleteTimer(int nID, ITimerHandler handler) { List <sTimer> list = null; if (false == m_DicTimer.TryGetValue(handler, out list)) { return(false); } // 遍历 foreach (var node in list) { if (node.dwTimerID == nID) { if (node.isLock() == true) { node.bRemove = true; } else { // 删除刻度 LinkedList <sTimer> GridPos = m_TimerAxis[node.dwGridIndex]; GridPos.Remove(node); // 删除管理 list.Remove(node); break; } } } return(true); }
public void AddTimer(ITimerHandler timer) { if (timer == null) { return; } timerList.Add(timer); }
public int GetTimerCD(string uid) { ITimerHandler timer = GetTimer(uid); if (timer == null) { return(0); } else { return(timer.cdTime); } }
/// <summary> /// 设置一个定时器 /// </summary> /// <param name="nID">定时器ID</param> /// <param name="fTime">定时器调用间隔</param> /// <param name="handler">处理接口</param> /// <param name="callTimes">调用次数,默认调用无穷次</param> /// <param name="debugInfo">调试信息</param> /// <returns>成功/失败</returns> public bool AddTimer(int nID, float fTime, ITimerHandler handler, int nCallTimes, string szLog) { if (handler == null) { return(false); } // 进行最小时间安全判断 if (fTime < CTimerAxis.CHECK_FREQUENCY / 1000.0f) { fTime = CTimerAxis.CHECK_FREQUENCY / 1000.0f; } // 诞生结构体 sTimer timer = new sTimer(); timer.dwTimerID = nID; timer.handler = handler; timer.dnDuration = (int)(fTime * 1000); timer.dwCallTimes = nCallTimes; timer.dwLastCallTick = m_dwLastCheckTick; timer.debugInfo = szLog; // 检查相同的回调函数 是否已经有TimerList 了, 如果没有创建一个新的 , 如果已经有了在旧的上面进行添加 List <sTimer> list = null; if (false == m_DicTimer.TryGetValue(handler, out list)) { list = new List <sTimer>(); m_DicTimer.Add(handler, list); } // 进行查重 foreach (var node in list) { if (node.dwTimerID == timer.dwTimerID) { return(false); } } list.Add(timer); // 将节点插入到时间轴上 timer.dwGridIndex = ((timer.dwLastCallTick + timer.dnDuration) / CTimerAxis.TIME_GRID) % CTimerAxis.ARRAY_LENGTH; LinkedList <sTimer> GridPos = m_TimerAxis[timer.dwGridIndex]; /*注意这里的计算方法 ,如果开始为0 1s 对应的gridId 为62 ,由于浮点数计算的时候无法精确, 我们hashtable会很大,1/0.016(一帧的时间)也就是说我们运行1s 需要在62帧之后才能运行 */ GridPos.AddFirst(timer); return(true); }
public VoiceCommandHandler( IConfigHandler config, ITimerHandler timerHandler ) { this.engine = new SpeechRecognitionEngine(); this.timerHandler = timerHandler; var builder = new GrammarBuilder(); builder.Append( new Choices( config.Config.Verbs.ToArray() ) ); builder.Append( new Choices( config.Commands.ToArray() ) ); this.engine.RequestRecognizerUpdate(); this.engine.LoadGrammar( new Grammar( builder ) ); this.engine.SpeechRecognized += engine_SpeechRecognized; this.engine.SetInputToDefaultAudioDevice(); this.engine.RecognizeAsync( RecognizeMode.Multiple ); }
public void InitTimer(int interval, int delay, ITimerHandler handler) { if (_IsStarted) { return; } _FirstTime = true; _Handler = handler; _Interval = interval; _Delay = delay; _InternalTimer = new System.Timers.Timer(); _InternalTimer.Elapsed += new ElapsedEventHandler(OnInternalTimedEvent); _Random = new Random(); _RandomTimer = new System.Timers.Timer(); _RandomTimer.Elapsed += new ElapsedEventHandler(OnRandomTimedEvent); _RandomTimer.AutoReset = false; }
public static void Add(ITimerHandler timer) { Instance.AddTimer(timer); }
public Logging(ITimerHandler timerHandler) { this.timerHandler = timerHandler; }