Skip to content

Commit

Permalink
Added scheduled tests (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Dec 28, 2023
1 parent dc73464 commit 97d6a0b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion InternetTest/InternetTest/Pages/DownDetectorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
Text="{x:Static lang:Resources.SecondsLower}" />
</StackPanel>
<StackPanel
x:Name="TimerPanel"
Grid.Row="3"
VerticalAlignment="Center"
Visibility="Collapsed">
Expand Down Expand Up @@ -221,6 +222,7 @@
</TextBlock.Triggers>
</TextBlock>
<TextBlock
x:Name="TimeTxt"
Width="200"
HorizontalAlignment="Center"
FontSize="11"
Expand All @@ -238,7 +240,7 @@
VerticalAlignment="Center"
Background="{Binding Source={StaticResource AccentColor}}"
BorderThickness="0"
Click="TestBtn_Click"
Click="LaunchTimerBtn_Click"
Content="{x:Static lang:Resources.LaunchScheduledTest}"
Cursor="Hand"
FontWeight="ExtraBold"
Expand Down
45 changes: 45 additions & 0 deletions InternetTest/InternetTest/Pages/DownDetectorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ MIT License
using InternetTest.Classes;
using InternetTest.UserControls;
using Synethia;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;

namespace InternetTest.Pages
{
Expand All @@ -39,6 +41,8 @@ public partial class DownDetectorPage : Page
{
bool codeInjected = !Global.Settings.UseSynethia;

DispatcherTimer timer = new() { Interval = TimeSpan.FromSeconds(1) }; // Create a new timer

public DownDetectorPage()
{
InitializeComponent();
Expand Down Expand Up @@ -71,13 +75,15 @@ private void AddBtn_Click(object sender, RoutedEventArgs e)

private void TestBtn_Click(object sender, RoutedEventArgs e)
{
LaunchTimerBtn.IsEnabled = false;
for (int i = 0; i < WebsiteDisplayer.Children.Count; i++)
{
if (WebsiteDisplayer.Children[i] is WebsiteItem websiteItem)
{
websiteItem.LaunchTestAsync();
}
}
LaunchTimerBtn.IsEnabled = true;
}

private void IntervalTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
Expand All @@ -93,5 +99,44 @@ private void WebsiteTxt_KeyUp(object sender, KeyEventArgs e)
AddBtn_Click(sender, e);
}
}

int secondsRemaining = 0;
int interval = 0;
bool timerStarted = false;
private void LaunchTimerBtn_Click(object sender, RoutedEventArgs e)
{
timerStarted = !timerStarted;
if (timerStarted)
{
secondsRemaining = int.Parse(IntervalTxt.Text); // Get the seconds
interval = int.Parse(IntervalTxt.Text); // Get the seconds
timer = new() { Interval = TimeSpan.FromSeconds(1) }; // Create a new timer
timer.Tick += (o, e) =>
{
if (secondsRemaining >= 0) secondsRemaining--;
TimeTxt.Text = string.Format(Properties.Resources.ScheduledTestInterval, secondsRemaining);
if (secondsRemaining < 0)
{
TestBtn_Click(sender, null);
secondsRemaining = interval;
TimeTxt.Text = string.Format(Properties.Resources.ScheduledTestInterval, secondsRemaining);
}
};
TimeTxt.Text = string.Format(Properties.Resources.ScheduledTestInterval, secondsRemaining);
timer.Start();
TimerPanel.Visibility = Visibility.Visible;
TestBtn.IsEnabled = false;
AddBtn.IsEnabled = false;
LaunchTimerBtn.Content = Properties.Resources.StopScheduledTests;
}
else
{
timer.Stop();
TimerPanel.Visibility = Visibility.Collapsed;
TestBtn.IsEnabled = true;
AddBtn.IsEnabled = true;
LaunchTimerBtn.Content = Properties.Resources.LaunchScheduledTest;
}
}
}
}

0 comments on commit 97d6a0b

Please sign in to comment.