/// <summary> /// add /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimerAddButton_Click(object sender, RoutedEventArgs e) { //if text matches an amount of time if (timeRegex.IsMatch(TimerAmount.Text)) { //take input string[] s = timeRegex.Match(TimerAmount.Text).Value.Split(splitChArr, 3); int[] values = new int[s.Length]; for (int i = 0; i < s.Length; i++) { values[i] = Convert.ToInt32(s[i]); } //create timespan with input TimeSpan ts = new TimeSpan(values[0], values[1], values[2]); //if a timer is selected add the TimeSpan to it if (TimerListBox.SelectedIndex >= 0) { timerList[TimerListBox.SelectedIndex].Add(ts); TimerListBox.Items[TimerListBox.SelectedIndex] = timerList[TimerListBox.SelectedIndex].TimerFormat(); } //else create a new timer with the TimeSpan else if (TimerListBox.SelectedIndex == -1) { TimerClock temp = new TimerClock(ts); timerList.Add(temp); TimerListBox.Items.Add(temp.TimerFormat()); } } }
public Form1() { InitializeComponent(); TimerClock.Interval = 1000; TimerClock.Start(); // Create a timer that will call the ShowTime method every second. // 윈폼 타이틀바에 시계표시 //var timer = new System.Threading.Timer( ShowTime, null, 0, 1000 ); watcher.Path = @"C:\Temp"; watcher.Filter = "*.txt"; watcher.EnableRaisingEvents = true; // 텍스트 박스 //watcher.Renamed += new RenamedEventHandler( ( o, e ) => { UpdateTextBox( Environment.NewLine + e.Name + " : is Renamed" ); } ); //watcher.Changed += new FileSystemEventHandler( ( o, e ) => { UpdateTextBox( Environment.NewLine + e.Name + " : is Changed" ); } ); //watcher.Created += new FileSystemEventHandler( ( o, e ) => { UpdateTextBox( Environment.NewLine + e.Name + " : is Created" ); } ); //watcher.Deleted += new FileSystemEventHandler( ( o, e ) => { UpdateTextBox( Environment.NewLine + e.Name + " : is Deleted" ); } ); // 리스트 박스 //watcher.Changed += new FileSystemEventHandler( ( o, e ) => { UpdateListBox( e.Name + " : is Changed" ); } ); watcher.Created += new FileSystemEventHandler((o, e) => { UpdateListBox(e.Name + " : is Created"); }); watcher.Deleted += new FileSystemEventHandler((o, e) => { UpdateListBox(e.Name + " : is Deleted"); }); watcher.Renamed += new RenamedEventHandler((o, e) => { UpdateListBox(e.Name + " : is Renamed"); }); }
public override void PregameSetup() { SoundManager.Instance.ChangeAmbientSound(ambientSound); foodPanel.DeactivateGameObject(); if (skipTutorial) { GameManager.Instance.CompleteTutorial(DataType.Minigame.Brainbow); } difficultyLevel = GameManager.Instance.GetLevel(DataType.Minigame.Brainbow); timer = TimerClock.Instance; scoreGauge = ScoreGauge.Instance; scoreGauge.gameObject.SetActive(false); timer.gameObject.SetActive(false); scoreGoal = GetLevelConfig().scoreGoal; waterManager.waterTimeBoost = GetLevelConfig().waterTimeBoost; monsterObject = monsterCreator.SpawnMonster( GameManager.Instance.GetPlayerMonsterObject()); monsterObject.transform.localPosition = monsterCreator.transform.position; monsterObject.transform.localScale = Vector3.one * 0.4f; monsterObject.spriteRenderer.sortingOrder = 0; monsterObject.ChangeEmotions(DataType.MonsterEmotions.Joyous); if (GameManager.Instance.GetPendingTutorial(DataType.Minigame.Brainbow)) { tutorialManager.gameObject.SetActive(true); tutorialManager.StartTutorial(); } else { StartGame(); } }
public void When_scheduling_multiple_actions_to_execute_at_every_interval() { using (var clockA = new TimerClock(500.Milliseconds())) using (var clockB = new TimerClock(100.Milliseconds())) { var counter = 0; clockA.Tick += (sender, args) => Interlocked.Increment(ref counter); clockA.Enabled = true; Thread.Sleep(900.Milliseconds()); var snapshotA = counter; snapshotA.ShouldBe(1); clockB.Tick += (sender, args) => Interlocked.Increment(ref counter); clockB.Enabled = true; Thread.Sleep(1.Seconds()); var snapshotB = counter; snapshotB.ShouldBeInRange(7, 20); } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { timer = TimerClock.IntervalMultiSeconds(timer, 1, RefreshSlider); controlTimer = TimerClock.IntervalMultiSeconds(controlTimer, 3, ControlPopupIsShow); //mediaElement.MouseLeftButtonUp += MediaElement_MouseLeftButtonUp; MouseDoubleClick += UserMediaView_MouseDoubleClick; }
/// <summary> /// Event supported after creating anaglyph. /// </summary> /// <param name="sender"> sender </param> /// <param name="e"> anaglyph created event </param> public void EventImageFinished(object sender, BitmapEventArgs e) { Dispatcher.Invoke(delegate { this.SetImageOnForm(ImageVersion.ANAGLYPH_IMAGE, e.anaglyphImage); // set anaglyph image on form this.historyLabel.Content = TimerClock.GetTime().ToString() + " [ms]"; // set time measured on form e.anaglyphImage.Save("anaglyph.bmp"); // save anaglyph on project folder this.buttonGenerateAnaglyph.IsEnabled = true; }); }
public void TimerClock_ClockTicksEqualThreadTimerTicks(int sleepSeconds) { var ticks = 0; var clock = new TimerClock(1000, args => ticks++); clock.Start(); Thread.Sleep(sleepSeconds * 1000); //=== Manual Step : Check CPU to see processor efficiency. clock.Stop(); Console.WriteLine(ticks); }
static void Main(string[] args) { TimerClock timer = new TimerClock(); AlarmClock alarm = new AlarmClock(); alarm.Subscribe(timer); Phone phone = new Phone(); phone.Subscribe(timer); timer.Start(10); Console.ReadKey(); }
public IClockUserCtrl GetTimerClockUserControl(Dispatcher dispatcher) { var dispatcherForPlayer = new DispatcherTimerImpl(new DispatcherTimer(DispatcherPriority.Normal, dispatcher)); var clockForPlayer = new TimerClock(_config, _logger, dispatcherForPlayer); var stream = Utils.GetResourceStream(_config.RingtoneFilename); var player = new LoopSoundPlayer(stream, _config, clockForPlayer); var dispatcherTimer = new DispatcherTimerImpl(new DispatcherTimer(DispatcherPriority.Normal, dispatcher)); var clock = new TimerClock(_config, _logger, dispatcherTimer); var ctrl = new ClockUserCtrl("_timer"); var vm = new TimerViewModel(ctrl, player, clock, _config, _logger); ctrl.SetViewModel(vm); return(ctrl); }
public void When_scheduling_an_action_to_execute_at_every_interval() { var counter = 0; using var clock = new TimerClock(10.Milliseconds()); clock.Tick += (sender, args) => Interlocked.Increment(ref counter); clock.Enabled.ShouldBeFalse(); clock.Enabled = true; Thread.Sleep(1.Seconds()); var snapshot = counter; snapshot.ShouldBeInRange(10, 200); clock.Enabled.ShouldBeTrue(); clock.Enabled = false; clock.Enabled.ShouldBeFalse(); }
public void When_scheduling_an_action_to_execute_after_a_timeout() { using var clock = new TimerClock(300.Milliseconds()); var counter = 0; clock.Tick += (sender, args) => { var clockCopy = sender as TimerClock; // ReSharper disable once PossibleNullReferenceException clockCopy.Enabled = false; counter += 666; }; clock.Enabled = true; Thread.Sleep(100.Milliseconds()); Assert.AreEqual(0, counter); Thread.Sleep(1.Seconds()); Assert.AreEqual(666, counter); }
private void TimerAddTimerButton_Click(object sender, RoutedEventArgs e) { //if text matches an amount of time if (timeRegex.IsMatch(TimerAmount.Text)) { string[] s = timeRegex.Match(TimerAmount.Text).Value.Split(splitChArr, 3); int[] values = new int[s.Length]; for (int i = 0; i < s.Length; i++) { values[i] = Convert.ToInt32(s[i]); } //create timespan with input TimeSpan ts = new TimeSpan(values[0], values[1], values[2]); //create a new timer with the TimeSpan and add it to the ListBox TimerClock temp = new TimerClock(ts); timerList.Add(temp); TimerListBox.Items.Add(temp.TimerFormat()); } }
public Raindrops() { LoopClock = new TimerClock(1 //refresh interval , args => SendColors(ColorsToSend)); //, 0); //drift threshold }
/// <summary> /// Called after pressing the button responsible for creating anaglyph. Runs the method from the object instance responsible for creating anaglyph. /// </summary> /// <param name="sender"> object sender </param> /// <param name="e"> RoutedEventArgs </param> private void OnClickButtonGenerateAnaglyph(object sender, RoutedEventArgs e) { if (radioAsm.IsChecked.Value) // assembler dll selected { this.dllVersion = DllVersion.ASM_DLL; } else if (radioC.IsChecked.Value) // C++ dll selected { this.dllVersion = DllVersion.CPP_DLL; } else // no dll selected { this.dllVersion = DllVersion.VOID; } if (radioTrue.IsChecked.Value) // true anaglyph filter selected { this.anaglyphVersion = AnaglyphVersion.TRUE_ANAGLYPH; } else if (radioGray.IsChecked.Value) // gray anaglyph filter selected { this.anaglyphVersion = AnaglyphVersion.GRAY_ANAGLYPH; } else if (radioColor.IsChecked.Value) // color anaglyph filter selected { this.anaglyphVersion = AnaglyphVersion.COLOR_ANAGLYPH; } else if (radioHalfColor.IsChecked.Value) // half color anaglyph filter selected { this.anaglyphVersion = AnaglyphVersion.HALF_COLOR_ANAGLYPH; } else if (radioOptimized.IsChecked.Value) // optimized anaglyph filter selected { this.anaglyphVersion = AnaglyphVersion.OPTIMIZED_ANAGLYPH; } else // no anaglyph filter selected { this.anaglyphVersion = AnaglyphVersion.VOID; } if (this.anaglyphVersion == AnaglyphVersion.VOID || this.dllVersion == DllVersion.VOID) // if anaglyph filter is no selected or dll is no selected display message to user { MessageBox.Show("You must select the DLL and anaglyph type choice!", "Anaglyph Creator Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // checking if the images are the same size if (this.leftImage.GetImageInformation().imageSizeX != this.rightImage.GetImageInformation().imageSizeX || this.leftImage.GetImageInformation().imageSizeY != this.rightImage.GetImageInformation().imageSizeY) { MessageBox.Show("Left and right images must be the same size!", "Wrong image sizes", MessageBoxButton.OK, MessageBoxImage.Error); return; } // checking if there are dll files if (this.dllVersion == DllVersion.CPP_DLL && !File.Exists("DLL_C.dll")) { MessageBox.Show("No DLL found for the C++ algorithm!", "C++ DLL missing", MessageBoxButton.OK, MessageBoxImage.Error); return; } else if (this.dllVersion == DllVersion.ASM_DLL && !File.Exists("DLL_ASM.dll")) { MessageBox.Show("No DLL found for the assembler algorithm!", "Asm DLL missing", MessageBoxButton.OK, MessageBoxImage.Error); return; } TimerClock.ResetTimer(); // reset timer that measures algorithm time int threadsAmount = (int)this.threadsBar.Value; // getting the number of threads this.buttonGenerateAnaglyph.IsEnabled = false; // turning off the generate button while creating anaglyph new Thread(() => { Thread.CurrentThread.IsBackground = true; anaglyph.CreateAnaglyph(this.dllVersion, this.anaglyphVersion, rightImage.GetImageInformation(), leftImage.GetImageInformation(), threadsAmount); }).Start(); // invoke method that creates anaglyph }
/// <summary> /// Subscribes the timer. /// </summary> /// <param name="timer">The clock.</param> public void Subscribe(TimerClock timer) => timer.TimeIsOver += OnTimeIsOver_Handler;
/// <summary> /// A method that creates anaglyph from the left and right image. /// </summary> /// <param name="dllVersion"> The dll version selected by the user. </param> /// <param name="anaglyphVersion"> User selection of anaglyph version. </param> /// <param name="leftImageInformation"> An instance of the class that stores information about the left image. </param> /// <param name="rightImageInformation"> An instance of the class that stores information about the right image. </param> /// <param name="threadAmount"> Number of threads selected by the user. </param> public void CreateAnaglyph(DllVersion dllVersion, AnaglyphVersion anaglyphVersion, ImageInformation leftImageInformation, ImageInformation rightImageInformation, int threadAmount) { int amountOfPixels = leftImageInformation.imagePixelArray.Length / 4; // the number of pixels that will be modified pixelsForThread = amountOfPixels / threadAmount; // the number of pixels to modify per thread if (pixelsForThread * threadAmount != leftImageInformation.imagePixelArray.Length / 4) // condition checking if the same number of pixels can be processed in each thread (different number of pixels) { int delta = amountOfPixels - (pixelsForThread * threadAmount); // number of pixels remaining PrepareThreads(threadAmount - 1); // prepare tables for the number of threads selected by the user minus one int start = pixelsForThread * (threadAmount - 1); // start index for a thread that modifies the rest of the pixels this.coords.Add(start); // start index for the last thread this.coords.Add(leftImageInformation.imagePixelArray.Length / 4); // end index for the last thread } else // the same number of pixels in each thread { PrepareThreads(threadAmount); // prepare a table of coordinates } anaglyphFilters = new float[12]; // creating an array that stores an anaglyph filter switch (anaglyphVersion) // choosing the right anaglyph filter depending on the user's choice { case AnaglyphVersion.TRUE_ANAGLYPH: anaglyphFilters = AnaglyphOptions._true; break; case AnaglyphVersion.GRAY_ANAGLYPH: anaglyphFilters = AnaglyphOptions._gray; break; case AnaglyphVersion.COLOR_ANAGLYPH: anaglyphFilters = AnaglyphOptions._color; break; case AnaglyphVersion.HALF_COLOR_ANAGLYPH: anaglyphFilters = AnaglyphOptions._halfColor; break; case AnaglyphVersion.OPTIMIZED_ANAGLYPH: anaglyphFilters = AnaglyphOptions._optimized; break; } tmpLeftImagePixelArray = new float[leftImageInformation.imagePixelArray.Length]; // creating a temporary array storing the pixels of the left image for (int i = 0; i < tmpLeftImagePixelArray.Length; i++) // loop that copies the pixel values of the left image into a temporary table { tmpLeftImagePixelArray[i] = leftImageInformation.imagePixelArray[i]; // copy the pixel color value from the left image to a temporary table } switch (dllVersion) // choice of dll depending on the user's choice { case DllVersion.ASM_DLL: // assembler dll choice for (int i = 0; i < this.coords.Count; i += 2) // loop calling as many times as there are coordinates (start and end) for each thread { int[] imageCoords = { this.coords[i] * 4, this.coords[i + 1] * 4 }; // get start and start index for the current thread var th = new Thread(() => // thread creation { AnaglyphAlgorithmAsm(leftImageInformation.imagePixelArray, imageCoords, anaglyphFilters, rightImageInformation.imagePixelArray); }); this.threads.Add(th); // adding a newly created thread to the list of threads } break; case DllVersion.CPP_DLL: // C++ dll choice for (int i = 0; i < this.coords.Count; i += 2) // loop calling as many times as there are coordinates(start and end) for each thread { int[] imageCoords = { this.coords[i] * 4, this.coords[i + 1] * 4 }; // get start and start index for the current thread var th = new Thread(() => // thread creation { AnaglyphAlgorithm(leftImageInformation.imagePixelArray, imageCoords, anaglyphFilters, rightImageInformation.imagePixelArray); }); this.threads.Add(th); // adding a newly created thread to the list of threads } break; } TimerClock.StartTimer(); // counting the time it takes for threads to finish foreach (Thread th in threads) // start all threads { th.Start(); } foreach (Thread th in threads) // waiting for the end of each thread { th.Join(); } TimerClock.StopTimer(); // stop counting time threads.Clear(); // clear the list of threads coords.Clear(); // clearing the list of start and end indexes leftImageInformation.finishConversion(); // creating an image based on returned pixels for (int i = 0; i < tmpLeftImagePixelArray.Length; i++) // copying the pixel color values from the previously created table to the table storing the pixel values of the left image { leftImageInformation.imagePixelArray[i] = tmpLeftImagePixelArray[i]; } EventImageFinished(leftImageInformation.imageBitmap); // reporting an event about the end of anaglyph creation }
/// <summary> /// Unsubscribes the timer. /// </summary> /// <param name="timer">The clock.</param> public void Unsubscribe(TimerClock timer) => timer.TimeIsOver -= OnTimeIsOver_Handler;
public void Test_TimerViewModel_HappyPath() { //arrange string startAt = "02"; string initialText = ""; string stoppedText = ""; string afterTick = ""; string finalText = ""; string afterReset = ""; Mock <IUserInterface> ui = new Mock <IUserInterface>(); Mock <ILogger> logger = new Mock <ILogger>(); Mock <ILoopSoundPlayer> player = new Mock <ILoopSoundPlayer>(); var config = new ConfigurationValues(); var timer = CreateDispatcherTimer(config); TimerClock clock = new TimerClock(config, logger.Object, timer.Object); TimerViewModel timervm = new TimerViewModel(ui.Object, player.Object, clock, config, logger.Object); //act timervm.Text = startAt; MethodInfo dynMethod = timervm.GetType().GetMethod("Ui_UiEventHappened", BindingFlags.NonPublic | BindingFlags.Instance); dynMethod.Invoke(timervm, new object[] { new object(), new UIEventArgs(UIEventArgs.UIEventType.BtnStartClicked) }); initialText = timervm.Text; timer.Raise(x => x.Tick += null, this, new EventArgs() { }); afterTick = timervm.Text; dynMethod.Invoke(timervm, new object[] { new object(), new UIEventArgs(UIEventArgs.UIEventType.BtnStartClicked) }); timer.Raise(x => x.Tick += null, this, new EventArgs() { }); stoppedText = timervm.Text; dynMethod.Invoke(timervm, new object[] { new object(), new UIEventArgs(UIEventArgs.UIEventType.BtnStartClicked) }); timer.Raise(x => x.Tick += null, this, new EventArgs() { }); finalText = timervm.Text; dynMethod.Invoke(timervm, new object[] { new object(), new UIEventArgs(UIEventArgs.UIEventType.BtnResetClicked) }); afterReset = timervm.Text; timervm.Dispose(); //assert Assert.Equal("00:00:02", initialText); Assert.Equal("00:00:01", afterTick); Assert.Equal("00:00:01", stoppedText); Assert.Equal("00:00:00", finalText); Assert.Equal("00:00:01", afterReset); logger.Verify(x => x.LogError(It.IsAny <string>()), Times.Never); logger.Verify(x => x.LogError(It.IsAny <string>(), It.IsAny <Exception>()), Times.Never); player.Verify(x => x.Play(It.IsAny <int>()), Times.Once); }
public void Setup() { _uut = new TimerClock(10); }