// A packed function to call before a timer is built. // 这里的switchbuilder有很大的问题,类的特性表现的比较差。应该改为Timer中统一的接口来处理。 private static Timer TimerBuildSwitcher(string path) { TimerConfigure tc = new TimerConfigure(path); // The timer configure to build from Timer T = null; // The timer to build switch (tc.timerOption) { case TimerOption.Normal: T = new Timer(path); break; case TimerOption.Cycle: T = new CycleTimer(path); break; case TimerOption.Timing: T = new TimingTimer(path); break; case TimerOption.CycleCount: T = new CycleCountTimer(path); break; case TimerOption.Interval: T = new IntervalCycleTimer(path); break; default: Console.WriteLine("Timer type not chosen, it's set to default now."); T = new Timer(path); // Build a default timer. break; } return(T); }
// Overload private static Timer TimerBuildSwitcher(System.TimeSpan OriginTimeSpan, TimerOption timeroption, int cycle_limit = 0) { Timer T = null; switch (timeroption) { case TimerOption.Normal: T = new Timer(OriginTimeSpan, timeroption); break; case TimerOption.Cycle: T = new CycleTimer(OriginTimeSpan, timeroption); break; case TimerOption.Timing: // This might go wrong. T = new TimingTimer(OriginTimeSpan, timeroption); break; case TimerOption.CycleCount: // Here need to be modified, the limit should be sent from UI. // Fixed T = new CycleCountTimer(OriginTimeSpan, timeroption, cycle_limit); break; case TimerOption.Interval: T = new IntervalCycleTimer(OriginTimeSpan, timeroption, cycle_limit); break; default: Console.WriteLine("Timer type not chosen, it's set to default now."); T = new Timer(OriginTimeSpan, TimerOption.Normal); // Build a default timer. break; } return(T); }