2024-03-21 21:56:48 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Diagnostics;
|
2024-03-21 22:15:24 +00:00
|
|
|
using System.Runtime.CompilerServices;
|
2024-03-21 21:56:48 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows;
|
|
|
|
using DT2;
|
|
|
|
|
|
|
|
namespace DT3 {
|
|
|
|
|
2024-03-21 22:15:24 +00:00
|
|
|
public class UrlTesterModel : INotifyPropertyChanged {
|
2024-03-21 21:56:48 +00:00
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
int size;
|
|
|
|
int time;
|
|
|
|
string url;
|
|
|
|
DT2.UrlTester urlTester;
|
|
|
|
|
|
|
|
public UrlTesterModel() {
|
|
|
|
urlTester = new DT2.UrlTester();
|
|
|
|
IDictionary<string, Stopwatch> sw = new Dictionary<string, Stopwatch>();
|
|
|
|
urlTester.PageStart += url => { sw.Add(url, Stopwatch.StartNew()); };
|
|
|
|
urlTester.PageLoaded += (url, size) => {
|
|
|
|
sw[url].Stop();
|
|
|
|
int time = (int)sw[url].Elapsed.TotalMilliseconds;
|
|
|
|
Size = size;
|
|
|
|
Time = time;
|
|
|
|
sw.Remove(url);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Size {
|
|
|
|
get { return size; }
|
2024-03-21 22:15:24 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
size = value;
|
2024-03-22 01:16:21 +00:00
|
|
|
NotifyPropertyChanged();
|
2024-03-21 22:15:24 +00:00
|
|
|
}
|
2024-03-21 21:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Time {
|
|
|
|
get { return time; }
|
2024-03-21 22:15:24 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
time = value;
|
2024-03-22 01:16:21 +00:00
|
|
|
NotifyPropertyChanged();
|
2024-03-21 22:15:24 +00:00
|
|
|
}
|
2024-03-21 21:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string Url {
|
|
|
|
get { return url; }
|
2024-03-21 22:15:24 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
url = value;
|
2024-03-22 01:16:21 +00:00
|
|
|
NotifyPropertyChanged();
|
2024-03-22 01:26:17 +00:00
|
|
|
var _ = urlTester.GetUrlAsync(Url);
|
2024-03-21 22:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void NotifyPropertyChanged([CallerMemberName] string memberName = null)
|
|
|
|
{
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName));
|
2024-03-21 21:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|