public void It_should_stop_timer_by_param() { results.Clear(); using (var timer = new MultiTimer <long>(MultiTimerCalback, 256, true)) { long[] param = new long[6]; int id1 = timer.Add(700, param[0] = Environment.TickCount + 700); int id2 = timer.Add(500, param[1] = Environment.TickCount + 500); int id3 = timer.Add(200, param[2] = Environment.TickCount + 200); int id4 = timer.Add(600, param[3] = Environment.TickCount + 600); int id5 = timer.Add(300, param[4] = Environment.TickCount + 300); int id6 = timer.Add(100, param[5] = Environment.TickCount + 100); timer.Remove(param[0]); timer.Remove(param[2]); timer.Remove(param[4]); Validate(3); Assert.AreEqual((int)param[5], results[0].Expected); Assert.AreEqual((int)param[1], results[1].Expected); Assert.AreEqual((int)param[3], results[2].Expected); } }
public TimerViewModel(MultiTimer timer) { this.timer = timer; timer.PropertyChanged += OnTimerPropertyChanged; ToggleState = new ToggleTimerStateCommand(timer); }
public void It_should_corect_work_when_internal_state_reused() { results.Clear(); using (var timer = new MultiTimer <int>(MultiTimerCalback, 256)) { int id1 = timer.Add(300, Environment.TickCount + 300); int id2 = timer.Add(300, Environment.TickCount + 300); int id3 = timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Remove(id1); timer.Remove(id2); timer.Remove(id3); timer.Add(600, Environment.TickCount + 600); timer.Add(600, Environment.TickCount + 600); timer.Add(600, Environment.TickCount + 600); Validate(6); } }
public void It_should_stop_timer_by_param() { results.Clear(); using (var timer = new MultiTimer<long>(MultiTimerCalback, 256, true)) { long[] param = new long[6]; int id1 = timer.Add(700, param[0] = Environment.TickCount + 700); int id2 = timer.Add(500, param[1] = Environment.TickCount + 500); int id3 = timer.Add(200, param[2] = Environment.TickCount + 200); int id4 = timer.Add(600, param[3] = Environment.TickCount + 600); int id5 = timer.Add(300, param[4] = Environment.TickCount + 300); int id6 = timer.Add(100, param[5] = Environment.TickCount + 100); timer.Remove(param[0]); timer.Remove(param[2]); timer.Remove(param[4]); Validate(3); Assert.AreEqual((int)param[5], results[0].Expected); Assert.AreEqual((int)param[1], results[1].Expected); Assert.AreEqual((int)param[3], results[2].Expected); } }
public LocationService() { this.ContactAddedHandler = ContactAddedHandlerInternal; this.ContactRemovedHandler = ContactRemovedHandlerInternal; this.scheme = System.Text.Encoding.UTF8.GetBytes(@"sip"); this.timer = new MultiTimer <ByteArrayPart>(RemoveExpiredBindings, 16384, false, ByteArrayPartEqualityComparer.GetStaticInstance()); this.bindingsByAor = new Dictionary <ByteArrayPart, Bindings>(); this.bindingsByConnectionId = new ThreadSafe.Dictionary <int, ByteArrayPart>(16384); this.sync = timer; }
public LocationService() { this.ContactAddedHandler = ContactAddedHandlerInternal; this.ContactRemovedHandler = ContactRemovedHandlerInternal; this.scheme = System.Text.Encoding.UTF8.GetBytes(@"sip"); this.timer = new MultiTimer<ByteArrayPart>(RemoveExpiredBindings, 16384, false, ByteArrayPartEqualityComparer.GetStaticInstance()); this.bindingsByAor = new Dictionary<ByteArrayPart, Bindings>(); this.bindingsByConnectionId = new ThreadSafe.Dictionary<int, ByteArrayPart>(16384); this.sync = timer; }
private void InitializeTimers() { timerA = new MultiTimer <int>(TimerA, capacity); timerB = new MultiTimer <int>(TimerB, capacity, 64 * T1); timerD = new MultiTimer <int>(TimerD, capacity, 32000); timerE = new MultiTimer <int>(TimerE, capacity); timerF = new MultiTimer <int>(TimerF, capacity, 64 * T1); timerG = new MultiTimer <int>(TimerG, capacity); timerH = new MultiTimer <int>(TimerH, capacity, 64 * T1); timerI = new MultiTimer <int>(TimerI, capacity, T4); timerJ = new MultiTimer <int>(TimerJ, capacity, 64 * T1); timerK = new MultiTimer <int>(TimerK, capacity, T4); }
public void It_should_call_remove_by_id_if_T_is_int() { results.Clear(); using (var timer = new MultiTimer <int>(MultiTimerCalback, 256, true)) { int id = timer.Add(100, 12345); timer.RemoveByParam(12345); Thread.Sleep(200); Assert.AreEqual(0, results.Count); } }
public async void CountRemainingTimeCorrectly(int[] intervals, long expectedRemaining) { var precision = 100; var multiTimer = new MultiTimer(new HeartBit(precision), intervals); Assert.Null(multiTimer.RemainingTicks); var evt = new ManualResetEvent(false); Exception ex = null; multiTimer.PropertyChanged += (o, e) => { if (e.PropertyName == nameof(multiTimer.RemainingTicks) && multiTimer.State != TimerState.Stopped) { try { Assert.True(multiTimer.RemainingTicks >= 0); Assert.Equal(expectedRemaining--, multiTimer.RemainingTicks); Assert.Equal(TimerState.Running, multiTimer.State); } catch (Exception ae) { ex = ae; } } else if (e.PropertyName == nameof(multiTimer.State)) { if (multiTimer.State == TimerState.Stopped) { Assert.Equal(0, multiTimer.RemainingTicks); evt.Set(); } } }; multiTimer.Start(); var result = evt.WaitOne(TimeSpan.FromMilliseconds(precision * (expectedRemaining + 1) * 10)); if (ex != null) { throw ex; } Assert.Null(ex); Assert.True(result); await Task.Delay(precision); Assert.Null(multiTimer.RemainingTicks); Assert.Equal(-1, expectedRemaining); }
public void It_should_callback_after_due_time_for_same_delay() { results.Clear(); using (var timer = new MultiTimer<int>(MultiTimerCalback, 256)) { timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); Validate(6); } }
public void It_should_callback_after_due_time() { results.Clear(); using (var timer = new MultiTimer<int>(MultiTimerCalback, 256)) { timer.Add(700, Environment.TickCount + 700); timer.Add(500, Environment.TickCount + 500); timer.Add(200, Environment.TickCount + 200); timer.Add(600, Environment.TickCount + 600); timer.Add(300, Environment.TickCount + 300); timer.Add(100, Environment.TickCount + 100); Validate(6); } }
public void It_should_callback_after_due_time() { results.Clear(); using (var timer = new MultiTimer <int>(MultiTimerCalback, 256)) { timer.Add(700, Environment.TickCount + 700); timer.Add(500, Environment.TickCount + 500); timer.Add(200, Environment.TickCount + 200); timer.Add(600, Environment.TickCount + 600); timer.Add(300, Environment.TickCount + 300); timer.Add(100, Environment.TickCount + 100); Validate(6); } }
public void It_should_callback_after_due_time_for_same_delay() { results.Clear(); using (var timer = new MultiTimer <int>(MultiTimerCalback, 256)) { timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); Validate(6); } }
public SimpleModule(IEqualityComparer <string> comparer) { int capacity = 16384; InvalidEtag = int.MinValue; publications = new ThreadSafe.Dictionary <string, Publication>( new Dictionary <string, Publication>(comparer)); publicationTimer = new MultiTimer <PublicationExpiresKey>( PulicationExpired, capacity, true, new PublicationExpiresKeyEqualityComparer()); subscriptionTimer = new MultiTimer <SubscriptionExpiresKey>( SubscriptionExpired, capacity, true, new SubscriptionExpiresKeyEqualityComparer()); }
public AccountFiles(string fileName, Action <int, string> readFile) : base(fileName) { this.readFile = readFile; this.files = new HashSet <string>(); this.timer = new MultiTimer <int>(Timer_Elapsed, 256, true, 500); this.ignoreWatcher = new HashSet <int>(); this.watcher = new FileSystemWatcher(RootDirectory); this.watcher.Changed += Watcher_Changed; this.watcher.Created += Watcher_Changed; this.watcher.Deleted += Watcher_Changed; this.watcher.Renamed += Watcher_Renamed; this.watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.FileName | NotifyFilters.DirectoryName; this.watcher.IncludeSubdirectories = true; this.watcher.EnableRaisingEvents = true; }
public void It_should_stop_timer_by_id() { results.Clear(); using (var timer = new MultiTimer <int>(MultiTimerCalback, 256)) { int id1 = timer.Add(700, Environment.TickCount + 700); int id2 = timer.Add(500, Environment.TickCount + 500); int id3 = timer.Add(200, Environment.TickCount + 200); int id4 = timer.Add(600, Environment.TickCount + 600); int id5 = timer.Add(300, Environment.TickCount + 300); int id6 = timer.Add(100, Environment.TickCount + 100); timer.Remove(id1); timer.Remove(id3); timer.Remove(id5); Validate(3); } }
public void It_should_stop_timer_by_id() { results.Clear(); using (var timer = new MultiTimer<int>(MultiTimerCalback, 256)) { int id1 = timer.Add(700, Environment.TickCount + 700); int id2 = timer.Add(500, Environment.TickCount + 500); int id3 = timer.Add(200, Environment.TickCount + 200); int id4 = timer.Add(600, Environment.TickCount + 600); int id5 = timer.Add(300, Environment.TickCount + 300); int id6 = timer.Add(100, Environment.TickCount + 100); timer.Remove(id1); timer.Remove(id3); timer.Remove(id5); Validate(3); } }
public AccountFiles(string fileName, Action<int, string> readFile) : base(fileName) { this.readFile = readFile; this.files = new HashSet<string>(); this.timer = new MultiTimer<int>(Timer_Elapsed, 256, true, 500); this.ignoreWatcher = new HashSet<int>(); this.watcher = new FileSystemWatcher(RootDirectory); this.watcher.Changed += Watcher_Changed; this.watcher.Created += Watcher_Changed; this.watcher.Deleted += Watcher_Changed; this.watcher.Renamed += Watcher_Renamed; this.watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.FileName | NotifyFilters.DirectoryName; this.watcher.IncludeSubdirectories = true; this.watcher.EnableRaisingEvents = true; }
public async void RaiseProperTimeouts(int[] intervals, TimeoutKind[] expectedKinds) { var precision = 100; var actualKinds = new List <TimeoutKind>(); var multiTimer = new MultiTimer(new HeartBit(precision), intervals); multiTimer.TimeoutOccured += (o, e) => actualKinds.Add(e); multiTimer.Start(); Assert.Equal(TimerState.Running, multiTimer.State); await Task.Delay(intervals.Select(x => (x + 1) * precision).Sum() + precision); Assert.Equal(TimerState.Stopped, multiTimer.State); string Contact <T>(IEnumerable <T> source) { return(source.Aggregate(new StringBuilder(), (sb, x) => sb.AppendFormat("{0} ", x)).ToString()); } Assert.Equal(Contact(expectedKinds), Contact(actualKinds)); }
public App() { InitializeComponent(); var botherer = new Botherer(Tizen.System.Vibrator.Vibrators[0]); var timer = new MultiTimer(new HeartBit(1000), intervals); timer.TimeoutOccured += async(o, kind) => { switch (kind) { case TimeoutKind.First: await botherer.Disturb(); break; case TimeoutKind.Subsequent: await botherer.Bother(); break; case TimeoutKind.Last: await botherer.Disturb(); break; default: throw new ArgumentOutOfRangeException(nameof(kind), kind, "Unexpected timeout kind!"); } }; MainPage = new TimerView() { BindingContext = new TimerViewModel(timer) }; }
public AjaxWebsocket() { sessions = new ThreadSafeDictionary<int, Session>(); timer = new MultiTimer<int>(KeepConnectionTimer, 1024, 20000); }
public AjaxWebsocket() { sessions = new ThreadSafeDictionary <int, Session>(); timer = new MultiTimer <int>(KeepConnectionTimer, 1024, 20000); }
public void It_should_call_remove_by_id_if_T_is_int() { results.Clear(); using (var timer = new MultiTimer<int>(MultiTimerCalback, 256, true)) { int id = timer.Add(100, 12345); timer.RemoveByParam(12345); Thread.Sleep(200); Assert.AreEqual(0, results.Count); } }
public ToggleTimerStateCommand(MultiTimer timer) { this.timer = timer; this.timer.PropertyChanged += TimerOnPropertyChanged; UpdateTitle(); }
public void It_should_corect_work_when_internal_state_reused() { results.Clear(); using (var timer = new MultiTimer<int>(MultiTimerCalback, 256)) { int id1 = timer.Add(300, Environment.TickCount + 300); int id2 = timer.Add(300, Environment.TickCount + 300); int id3 = timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Add(300, Environment.TickCount + 300); timer.Remove(id1); timer.Remove(id2); timer.Remove(id3); timer.Add(600, Environment.TickCount + 600); timer.Add(600, Environment.TickCount + 600); timer.Add(600, Environment.TickCount + 600); Validate(6); } }