Implemented auto proxy refresh every x minutes (configurable).

This commit is contained in:
ruri
2019-10-01 14:34:31 +02:00
parent 9447e8c46d
commit 81b60e64b4
3 changed files with 25 additions and 7 deletions
@@ -17,8 +17,8 @@
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0" Margin="5">
@@ -38,7 +38,7 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="Global Ban Keys:" />
<Label Grid.Row="0" Content="Global Ban Keys:" />
<RichTextBox x:Name="globalBanKeysTextbox" Grid.Row="1" Background="{DynamicResource BackgroundSecondary}" Foreground="{DynamicResource ForegroundMain}" FontFamily="Consolas" TextChanged="globalBanKeysTextbox_TextChanged">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
@@ -61,6 +61,10 @@
<StackPanel>
<Label Content="Reloading"/>
<CheckBox Content="Reload proxies when all banned" IsChecked="{Binding Reload}" VerticalContentAlignment="Center"/>
<DockPanel DockPanel.Dock="Top">
<Label Content="Reload interval in minutes (0 = only reload when all banned):" />
<xctk:IntegerUpDown Background="Transparent" Width="70" Margin="10 0 0 0" Value="{Binding ReloadInterval}" Foreground="{DynamicResource ForegroundMain}" HorizontalAlignment="Right"/>
</DockPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Source:"/>
+14 -4
View File
@@ -524,11 +524,21 @@ namespace RuriLib.Runner
return;
}
// Write progress to DB every 2 minutes
// Useful if we cannot save it upon work completion (e.g. for a crash or power outage)
if (Timer.IsRunning && (int)Timer.Elapsed.TotalSeconds != 0 && (int)Timer.Elapsed.TotalSeconds % 120 == 0)
// Periodic actions
if (Timer.IsRunning && (int)Timer.Elapsed.TotalSeconds != 0)
{
RaiseSaveProgress();
// Write progress to DB every 2 minutes
// Useful if we cannot save it upon work completion (e.g. for a crash or power outage)
if ((int)Timer.Elapsed.TotalSeconds % 120 == 0)
{
RaiseSaveProgress();
}
// Reload proxies if a reload interval was set
if (Settings.Proxies.ReloadInterval > 0 && (int)Timer.Elapsed.TotalSeconds % (Settings.Proxies.ReloadInterval * 60) == 0)
{
LoadProxies();
}
}
// If we are above the CPM limit, go to the wait (use cpm NOT CPM so it doesn't calculate it uselessly when it checks the IF conditions)
@@ -55,6 +55,10 @@ namespace RuriLib.ViewModels
private ProxyType reloadType = ProxyType.Http;
/// <summary>The Type of the proxies to load.</summary>
public ProxyType ReloadType { get { return reloadType; } set { reloadType = value; OnPropertyChanged(); } }
private int reloadInterval = 0;
/// <summary>The amount of time between reloads in minutes (0 to only reload when all proxies are banned).</summary>
public int ReloadInterval { get { return reloadInterval; } set { reloadInterval = value; OnPropertyChanged(); } }
#endregion
#region Cloudflare