Skip to content

Commit

Permalink
Refresh analyse result
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeans committed Jan 3, 2017
1 parent c4491c0 commit 027c325
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,4 @@ _Pvt_Extensions/
ModelManifest.xml
img/icons/Thumbs.db
img/Thumbs.db
img/Thumbs.db
4 changes: 3 additions & 1 deletion SimpleDnsCrypt/Tools/AnalyseProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ public static class AnalyseProxy
public static DnsCryptProxyEntryExtra Analyse(DnsCryptProxyEntry dnsCryptProxyEntry)
{
var dnsCryptProxyEntryExtra = new DnsCryptProxyEntryExtra();

try
{
var address = "";
string address;
var port = 443;
if (dnsCryptProxyEntry.ResolverAddress.Contains(":"))
{
if (dnsCryptProxyEntry.ResolverAddress.StartsWith("[")) return null;
var t = dnsCryptProxyEntry.ResolverAddress.Split(':');
address = t[0];
port = Convert.ToInt32(t[1]);
Expand Down
21 changes: 11 additions & 10 deletions SimpleDnsCrypt/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public sealed class MainViewModel : Screen, IShell
private List<string> _plugins;
private DnsCryptProxyEntry _primaryResolver;
private string _primaryResolverTitle;
private List<DnsCryptProxyEntry> _resolvers;
private ObservableCollection<DnsCryptProxyEntry> _resolvers;
private DnsCryptProxyEntry _secondaryResolver;
private string _secondaryResolverTitle;
private Language _selectedLanguage;
Expand Down Expand Up @@ -119,7 +119,7 @@ private MainViewModel(IWindowManager windowManager, IEventAggregator eventAggreg
LocalizationEx.GetUiString("global_ipv6_disabled", Thread.CurrentThread.CurrentCulture));
}

_resolvers = new List<DnsCryptProxyEntry>();
_resolvers = new ObservableCollection<DnsCryptProxyEntry>();
_updateResolverListOnStart = _userData.UpdateResolverListOnStart;
_isWorkingOnPrimaryService = false;
_isWorkingOnSecondaryService = false;
Expand Down Expand Up @@ -164,7 +164,7 @@ private MainViewModel(IWindowManager windowManager, IEventAggregator eventAggreg
}

var dnsProxyList =
DnsCryptProxyListManager.ReadProxyList(proxyList, proxyListSignature, _userData.UseIpv6);
DnsCryptProxyListManager.ReadProxyList(proxyList, proxyListSignature, !_userData.UseIpv6);
if (dnsProxyList != null && dnsProxyList.Any())
{
foreach (var dnsProxy in dnsProxyList)
Expand Down Expand Up @@ -355,7 +355,7 @@ public bool IsOverlayVisible
/// <summary>
/// The list of loaded resolvers.
/// </summary>
public List<DnsCryptProxyEntry> Resolvers
public ObservableCollection<DnsCryptProxyEntry> Resolvers
{
get { return _resolvers; }
set
Expand Down Expand Up @@ -854,21 +854,22 @@ public async void AnalyseResolvers()
IsAnalysing = true;
await Task.Run(() =>
{
for (var r = 0; r < _resolvers.Count; r++)
var tmpResolvers = _resolvers.ToList();
for (var r = 0; r < tmpResolvers.Count; r++)
{
var dnsCryptProxyEntryExtra = AnalyseProxy.Analyse(_resolvers[r]);
var dnsCryptProxyEntryExtra = AnalyseProxy.Analyse(tmpResolvers[r]);
if (dnsCryptProxyEntryExtra != null)
{
_resolvers[r].Extra = dnsCryptProxyEntryExtra;
tmpResolvers[r].Extra = dnsCryptProxyEntryExtra;
if (!dnsCryptProxyEntryExtra.Succeeded)
{
_resolvers.RemoveAt(r);
tmpResolvers.RemoveAt(r);
}
}
}
_resolvers.Sort((a, b) => a.Extra.ResponseTime.CompareTo(b.Extra.ResponseTime));
tmpResolvers.Sort((a, b) => a.Extra.ResponseTime.CompareTo(b.Extra.ResponseTime));
Resolvers = new ObservableCollection<DnsCryptProxyEntry>(tmpResolvers);
}).ConfigureAwait(false);
NotifyOfPropertyChange(() => Resolvers);
IsAnalysing = false;
}
catch (Exception)
Expand Down
2 changes: 1 addition & 1 deletion SimpleDnsCrypt/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
Width="35" VerticalAlignment="Top" Cursor="Hand" IsEnabled="{Binding IsAnalysing, Converter={StaticResource ReverseBoolToEnabledConverter}}"
x:Name="AnalyseResolvers" HorizontalAlignment="Right"
ToolTip="{lex:Loc Key=default_settings_analyse_button_tooltip}"
Style="{DynamicResource MetroCircleButtonStyle}">
Style="{DynamicResource MetroCircleButtonStyle}" Margin="3,0,0,0">
<Rectangle Fill="#FF8ab329" Width="12" Height="12">
<Rectangle.OpacityMask>
<VisualBrush Visual="{DynamicResource appbar_clock}"
Expand Down
Loading

0 comments on commit 027c325

Please sign in to comment.