Compare commits

..

No commits in common. "1ac34c7625696d6affecb207cd474d7f786a1a54" and "d22de337329b2ab04ef176989a3f48859b1d868b" have entirely different histories.

21 changed files with 298 additions and 663 deletions

1
.gitignore vendored
View file

@ -383,6 +383,7 @@ FodyWeavers.xsd
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/

View file

@ -1,26 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0/AdvancedConcepts.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

View file

@ -1,41 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/AdvancedConcepts.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/AdvancedConcepts.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/AdvancedConcepts.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View file

@ -1,122 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DT1 {
public delegate double GradeCalc(List<int> s);
public enum GradeLevel { FirstYear = 1, SecondYear, ThirdYear, FourthYear };
public class Student {
public string FirstName { get; set; }
public string LastName { get; set; }
public int ID { get; set; }
public GradeLevel Year;
public List<int> ExamScores;
public double Grade { get; set; }
}
public class StudentClass {
public Func<Student, string, bool> studentSelector = (student, surname) =>
{
return string.Compare(student.LastName, surname, true) == 0;
};
public GradeCalc gradeCalculator = (grades) =>
{
return Math.Round(((grades.Average() / 100 * 5) + 1) * 2, MidpointRounding.AwayFromZero) / 2;
};
public Func<Student, bool> passedSelector = (student) =>
{
return student.Year == GradeLevel.FourthYear && student.Grade >= 4;
};
#region data
public List<Student> students = new List<Student> {
new Student {FirstName = "Terry", LastName = "Adams", ID = 120,
Year = GradeLevel.SecondYear,
ExamScores = new List<int>{ 99, 82, 81, 79}},
new Student {FirstName = "Fadi", LastName = "Fakhouri", ID = 116,
Year = GradeLevel.ThirdYear,
ExamScores = new List<int>{ 99, 86, 90, 94}},
new Student {FirstName = "Hanying", LastName = "Feng", ID = 117,
Year = GradeLevel.FirstYear,
ExamScores = new List<int>{ 93, 92, 80, 87}},
new Student {FirstName = "Cesar", LastName = "Garcia", ID = 114,
Year = GradeLevel.FourthYear,
ExamScores = new List<int>{ 97, 89, 85, 82}},
new Student {FirstName = "Debra", LastName = "Garcia", ID = 115,
Year = GradeLevel.ThirdYear,
ExamScores = new List<int>{ 35, 72, 91, 70}},
new Student {FirstName = "Hugo", LastName = "Garcia", ID = 118,
Year = GradeLevel.SecondYear,
ExamScores = new List<int>{ 92, 90, 83, 78}},
new Student {FirstName = "Sven", LastName = "Mortensen", ID = 113,
Year = GradeLevel.FirstYear,
ExamScores = new List<int>{ 88, 94, 65, 91}},
new Student {FirstName = "Claire", LastName = "O'Donnell", ID = 112,
Year = GradeLevel.FourthYear,
ExamScores = new List<int>{ 75, 84, 91, 39}},
new Student {FirstName = "Svetlana", LastName = "Omelchenko", ID = 111,
Year = GradeLevel.SecondYear,
ExamScores = new List<int>{ 97, 92, 81, 60}},
new Student {FirstName = "Lance", LastName = "Tucker", ID = 119,
Year = GradeLevel.ThirdYear,
ExamScores = new List<int>{ 68, 79, 88, 92}},
new Student {FirstName = "Michael", LastName = "Tucker", ID = 122,
Year = GradeLevel.FirstYear,
ExamScores = new List<int>{ 94, 92, 91, 91}},
new Student {FirstName = "Eugene", LastName = "Zabokritski", ID = 121,
Year = GradeLevel.FourthYear,
ExamScores = new List<int>{ 96, 85, 91, 60}}
};
#endregion
public List<Student> AddGrades(GradeCalc calc) {
foreach (Student s in students) {
s.Grade = calc(s.ExamScores);
}
return students;
}
public List<Student> SearchStudent(Func<Student, string, bool> select, String lastName) {
List<Student> result = new() { };
foreach (Student s in students) {
if (select(s, lastName)) result.Add(s);
}
return result;
}
public IEnumerable<Student> QueryPassed(Func<Student,bool> passed)
{
return students.Where(passed);
}
static void show(String titel, List<Student> students) {
Console.WriteLine(titel);
foreach (var item in students) {
Console.WriteLine(String.Format("{0} {1} {2}", item.FirstName, item.LastName, item.Grade));
}
}
public static void Main(string[] args) {
StudentClass sc = new StudentClass();
show("Grades", sc.AddGrades(sc.gradeCalculator));
show("\nStudent Carcia",sc.SearchStudent(sc.studentSelector, "Garcia"));
show("\nPassed 4th", sc.QueryPassed(sc.passedSelector).ToList<Student>());
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
public static class ListUtils {
public static IEnumerable<T> What<T>(this IList<T> list, Func<T, bool> selector)
{
return list.Where(selector);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DT1 {
public delegate double GradeCalc(List<int> s);
public enum GradeLevel { FirstYear = 1, SecondYear, ThirdYear, FourthYear };
public class Student {
public string FirstName { get; set; }
public string LastName { get; set; }
public int ID { get; set; }
public GradeLevel Year;
public List<int> ExamScores;
public double Grade { get; set; }
}
public class StudentClass {
public Func<Student, string, bool> studentSelector = (student, surname) =>
{
return string.Compare(student.LastName, surname, true) == 0;
};
public GradeCalc gradeCalculator = (grades) =>
{
return Math.Round(((grades.Average() / 100 * 5) + 1) * 2, MidpointRounding.AwayFromZero) / 2;
};
public Func<Student, bool> passedSelector = (student) =>
{
return student.Year == GradeLevel.FourthYear && student.Grade >= 4;
};
#region data
public List<Student> students = new List<Student> {
new Student {FirstName = "Terry", LastName = "Adams", ID = 120,
Year = GradeLevel.SecondYear,
ExamScores = new List<int>{ 99, 82, 81, 79}},
new Student {FirstName = "Fadi", LastName = "Fakhouri", ID = 116,
Year = GradeLevel.ThirdYear,
ExamScores = new List<int>{ 99, 86, 90, 94}},
new Student {FirstName = "Hanying", LastName = "Feng", ID = 117,
Year = GradeLevel.FirstYear,
ExamScores = new List<int>{ 93, 92, 80, 87}},
new Student {FirstName = "Cesar", LastName = "Garcia", ID = 114,
Year = GradeLevel.FourthYear,
ExamScores = new List<int>{ 97, 89, 85, 82}},
new Student {FirstName = "Debra", LastName = "Garcia", ID = 115,
Year = GradeLevel.ThirdYear,
ExamScores = new List<int>{ 35, 72, 91, 70}},
new Student {FirstName = "Hugo", LastName = "Garcia", ID = 118,
Year = GradeLevel.SecondYear,
ExamScores = new List<int>{ 92, 90, 83, 78}},
new Student {FirstName = "Sven", LastName = "Mortensen", ID = 113,
Year = GradeLevel.FirstYear,
ExamScores = new List<int>{ 88, 94, 65, 91}},
new Student {FirstName = "Claire", LastName = "O'Donnell", ID = 112,
Year = GradeLevel.FourthYear,
ExamScores = new List<int>{ 75, 84, 91, 39}},
new Student {FirstName = "Svetlana", LastName = "Omelchenko", ID = 111,
Year = GradeLevel.SecondYear,
ExamScores = new List<int>{ 97, 92, 81, 60}},
new Student {FirstName = "Lance", LastName = "Tucker", ID = 119,
Year = GradeLevel.ThirdYear,
ExamScores = new List<int>{ 68, 79, 88, 92}},
new Student {FirstName = "Michael", LastName = "Tucker", ID = 122,
Year = GradeLevel.FirstYear,
ExamScores = new List<int>{ 94, 92, 91, 91}},
new Student {FirstName = "Eugene", LastName = "Zabokritski", ID = 121,
Year = GradeLevel.FourthYear,
ExamScores = new List<int>{ 96, 85, 91, 60}}
};
#endregion
public List<Student> AddGrades(GradeCalc calc) {
foreach (Student s in students) {
s.Grade = calc(s.ExamScores);
}
return students;
}
public List<Student> SearchStudent(Func<Student, string, bool> select, String lastName) {
List<Student> result = new() { };
foreach (Student s in students) {
if (select(s, lastName)) result.Add(s);
}
return result;
}
public IEnumerable<Student> QueryPassed(Func<Student,bool> passed)
{
return students.Where(passed);
}
static void show(String titel, List<Student> students) {
Console.WriteLine(titel);
foreach (var item in students) {
Console.WriteLine(String.Format("{0} {1} {2}", item.FirstName, item.LastName, item.Grade));
}
}
public static void Main(string[] args) {
StudentClass sc = new StudentClass();
show("Grades", sc.AddGrades(sc.gradeCalculator));
show("\nStudent Carcia",sc.SearchStudent(sc.studentSelector, "Garcia"));
show("\nPassed 4th", sc.QueryPassed(sc.passedSelector).ToList<Student>());
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
public static class ListUtils {
public static IEnumerable<T> What<T>(this IList<T> list, Func<T, bool> selector)
{
return list.Where(selector);
}
}
}

View file

@ -1,167 +1,165 @@
/*
* Created by SharpDevelop.
* User: Karl Rege
* Date: 26.02.2021
* Time: 16:15
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Net.Security;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Threading;
using System.Buffers;
namespace DT2 {
public enum CallMode { Sync, Async, AsyncTimeout };
public class UrlTester {
public event Action<string> PageStart;
public event Action<string, int> PageLoaded;
public event Action<string, int, int> LoadSummary;
public event Action<string> Timeout;
public void SetupEvents() {
IDictionary<string, Stopwatch> sw = new Dictionary<string, Stopwatch>();
PageStart = url => { Console.WriteLine(url + " ..."); sw.Add(url, Stopwatch.StartNew()); };
PageLoaded += (url, size) => {
sw[url].Stop();
Console.WriteLine(url + " " + size + " bytes " + (int)sw[url].Elapsed.TotalMilliseconds + " ms");
sw.Remove(url);
};
Timeout = (url) => {
sw[url].Stop(); Console.WriteLine(url + " Timeout"); sw.Remove(url);
};
LoadSummary += (s, size, time) => { Console.WriteLine(s + ": " + size + " bytes " + time + " ms"); };
}
public List<string> UrlList = new List<string> {
"https://www.zhaw.ch",
"https://waikiki.zhaw.ch/~rege",
"https://www.zhaw.ch/de/linguistik/",
"https://www.zhaw.ch/de/psychologie/",
"https://www.zhaw.ch/de/archbau/",
"https://www.zhaw.ch/de/gesundheit/",
"https://www.zhaw.ch/de/lsfm/",
// very slow sites
/*
"http://www.airkoryo.com.kp/",
"http://www.manmulsang.com.kp/",
"http://tourismdprk.gov.kp/",
"http://www.kut.edu.kp/"
*/
};
public void IgnoreCertificateValidation() {
System.Net.ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => true);
}
public virtual int GetPageSize(string url) {
// The downloaded resource ends up in the variable named content.
byte[] byteContent;
// Initialize an HttpWebRequest for the current URL.
var webReq = (HttpWebRequest)WebRequest.Create(url);
//if (PageStart != null) PageStart (url);
Stopwatch sw = Stopwatch.StartNew();
// Send the request to the Internet resource and wait for
// the response.
using (WebResponse response = webReq.GetResponse()) {
// Get the stream that is associated with the response.
using (Stream responseStream = response.GetResponseStream()) {
using (StreamReader sr = new StreamReader(responseStream)) {
String content = sr.ReadToEnd();
byteContent = Encoding.UTF8.GetBytes(content);
}
}
}
return byteContent.Length;
}
public int GetUrlSync(string url) {
PageStart?.Invoke(url);
int size = GetPageSize(url);
PageLoaded?.Invoke(url, size);
return size;
}
public async Task<int> GetUrlAsync(string url) {
PageStart?.Invoke(url);
int size = await Task.Run(() => GetPageSize(url));
PageLoaded?.Invoke(url, size);
return size;
}
public async Task<int> GetUrlAsyncTimeout(string url, int millis) {
int size;
PageStart(url);
Task<int> task = Task.Run(() => GetPageSize(url));
try {
size = await task.WaitAsync(TimeSpan.FromMilliseconds(millis));
PageLoaded?.Invoke(url, size);
}
catch (TimeoutException)
{
Timeout(url);
size = 0;
}
return size;
}
public void GetAllUrls(List<string> urlList, CallMode callMode) {
// get a list of web addresses.
int totalSize = 0;
Stopwatch sw = Stopwatch.StartNew();
Action<Func<string, Task<int>>> asyncRunner = (implementation) =>
{
Task<int[]> task = Task.WhenAll(urlList.Select((url) => implementation(url)));
task.Wait();
totalSize = task.Result.Sum();
};
if (callMode == CallMode.Sync) {
Console.WriteLine("\nCalling Sync");
foreach (var url in urlList) {
totalSize += GetUrlSync(url);
}
}
else if (callMode == CallMode.Async) {
Console.WriteLine("\nCalling Async");
asyncRunner.Invoke(GetUrlAsync);
}
else if (callMode == CallMode.AsyncTimeout) {
Console.WriteLine("\nCalling Async Timeout");
asyncRunner.Invoke((url) => GetUrlAsyncTimeout(url, 100));
}
LoadSummary("Total", totalSize, (int)sw.Elapsed.TotalMilliseconds);
}
#if DT2
public static void Main(string[] args) {
Console.WriteLine("Starting ...");
UrlTester urlTester = new UrlTester();
urlTester.IgnoreCertificateValidation();
ThreadPool.SetMinThreads(urlTester.UrlList.Count * 2, urlTester.UrlList.Count * 2);
urlTester.SetupEvents();
urlTester.GetAllUrls(urlTester.UrlList, CallMode.Sync);
urlTester.GetAllUrls(urlTester.UrlList, CallMode.Async);
urlTester.GetAllUrls(urlTester.UrlList, CallMode.AsyncTimeout);
Console.Write("Press any key to continue ...\n");
Console.ReadKey(true);
}
#endif
}
/*
* Created by SharpDevelop.
* User: Karl Rege
* Date: 26.02.2021
* Time: 16:15
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Net.Security;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Threading;
using System.Buffers;
namespace DT2 {
public enum CallMode { Sync, Async, AsyncTimeout };
public class UrlTester {
public event Action<string> PageStart;
public event Action<string, int> PageLoaded;
public event Action<string, int, int> LoadSummary;
public event Action<string> Timeout;
public void SetupEvents() {
IDictionary<string, Stopwatch> sw = new Dictionary<string, Stopwatch>();
PageStart = url => { Console.WriteLine(url + " ..."); sw.Add(url, Stopwatch.StartNew()); };
PageLoaded += (url, size) => {
sw[url].Stop();
Console.WriteLine(url + " " + size + " bytes " + (int)sw[url].Elapsed.TotalMilliseconds + " ms");
sw.Remove(url);
};
Timeout = (url) => {
sw[url].Stop(); Console.WriteLine(url + " Timeout"); sw.Remove(url);
};
LoadSummary += (s, size, time) => { Console.WriteLine(s + ": " + size + " bytes " + time + " ms"); };
}
public List<string> UrlList = new List<string> {
"https://www.zhaw.ch",
"https://waikiki.zhaw.ch/~rege",
"https://www.zhaw.ch/de/linguistik/",
"https://www.zhaw.ch/de/psychologie/",
"https://www.zhaw.ch/de/archbau/",
"https://www.zhaw.ch/de/gesundheit/",
"https://www.zhaw.ch/de/lsfm/",
// very slow sites
/*
"http://www.airkoryo.com.kp/",
"http://www.manmulsang.com.kp/",
"http://tourismdprk.gov.kp/",
"http://www.kut.edu.kp/"
*/
};
public void IgnoreCertificateValidation() {
System.Net.ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => true);
}
public virtual int GetPageSize(string url) {
// The downloaded resource ends up in the variable named content.
byte[] byteContent;
// Initialize an HttpWebRequest for the current URL.
var webReq = (HttpWebRequest)WebRequest.Create(url);
//if (PageStart != null) PageStart (url);
Stopwatch sw = Stopwatch.StartNew();
// Send the request to the Internet resource and wait for
// the response.
using (WebResponse response = webReq.GetResponse()) {
// Get the stream that is associated with the response.
using (Stream responseStream = response.GetResponseStream()) {
using (StreamReader sr = new StreamReader(responseStream)) {
String content = sr.ReadToEnd();
byteContent = Encoding.UTF8.GetBytes(content);
}
}
}
return byteContent.Length;
}
public int GetUrlSync(string url) {
PageStart(url);
int size = GetPageSize(url);
PageLoaded(url, size);
return size;
}
public async Task<int> GetUrlAsync(string url) {
PageStart(url);
int size = await Task.Run(() => GetPageSize(url));
PageLoaded(url, size);
return size;
}
public async Task<int> GetUrlAsyncTimeout(string url, int millis) {
int size;
PageStart(url);
Task<int> task = Task.Run(() => GetPageSize(url));
try {
size = await task.WaitAsync(TimeSpan.FromMilliseconds(millis));
PageLoaded(url, size);
}
catch (TimeoutException)
{
Timeout(url);
size = 0;
}
return size;
}
public void GetAllUrls(List<string> urlList, CallMode callMode) {
// get a list of web addresses.
int totalSize = 0;
Stopwatch sw = Stopwatch.StartNew();
Action<Func<string, Task<int>>> asyncRunner = (implementation) =>
{
Task<int[]> task = Task.WhenAll(urlList.Select((url) => implementation(url)));
task.Wait();
totalSize = task.Result.Sum();
};
if (callMode == CallMode.Sync) {
Console.WriteLine("\nCalling Sync");
foreach (var url in urlList) {
totalSize += GetUrlSync(url);
}
}
else if (callMode == CallMode.Async) {
Console.WriteLine("\nCalling Async");
asyncRunner.Invoke(GetUrlAsync);
}
else if (callMode == CallMode.AsyncTimeout) {
Console.WriteLine("\nCalling Async Timeout");
asyncRunner.Invoke((url) => GetUrlAsyncTimeout(url, 100));
}
LoadSummary("Total", totalSize, (int)sw.Elapsed.TotalMilliseconds);
}
public static void Main(string[] args) {
Console.WriteLine("Starting ...");
UrlTester urlTester = new UrlTester();
urlTester.IgnoreCertificateValidation();
ThreadPool.SetMinThreads(urlTester.UrlList.Count * 2, urlTester.UrlList.Count * 2);
urlTester.SetupEvents();
urlTester.GetAllUrls(urlTester.UrlList, CallMode.Sync);
urlTester.GetAllUrls(urlTester.UrlList, CallMode.Async);
urlTester.GetAllUrls(urlTester.UrlList, CallMode.AsyncTimeout);
Console.Write("Press any key to continue ...\n");
Console.ReadKey(true);
}
}
}

11
Tasks/DT2/DT2.csproj Normal file
View file

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
</Project>

View file

@ -1,26 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0-windows/UrlTester.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

View file

@ -1,41 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/UrlTester.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/UrlTester.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/UrlTester.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View file

@ -1,9 +0,0 @@
<Application x:Class="UrlTester.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UrlTester"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View file

@ -1,12 +0,0 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace UrlTester;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View file

@ -1,10 +0,0 @@
using System.Windows;
[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View file

@ -1,69 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using DT2;
namespace DT3 {
public class UrlTesterModel : INotifyPropertyChanged {
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; }
set
{
size = value;
NotifyPropertyChanged(nameof(Size));
}
}
public int Time {
get { return time; }
set
{
time = value;
NotifyPropertyChanged(nameof(Time));
}
}
public string Url {
get { return url; }
set
{
url = value;
NotifyPropertyChanged(nameof(Url));
var _ = urlTester.GetUrlAsync(Url);
}
}
protected void NotifyPropertyChanged(string memberName)
{
if (PropertyChanged != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(memberName));
}
}
}
}

Binary file not shown.

View file

@ -1,80 +0,0 @@
<Window x:Class="UrlTester.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DT3"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="800">
<Window.Resources>
<Style x:Key="CommonStyle" TargetType="FrameworkElement">
<Setter Property="Margin" Value="10" />
</Style>
<Style TargetType="Button" BasedOn="{StaticResource CommonStyle}">
<Setter Property="Padding"
Value="15,0,15,0" />
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource CommonStyle}" />
<Style TargetType="TextBlock" BasedOn="{StaticResource CommonStyle}" />
<Style TargetType="ProgressBar" BasedOn="{StaticResource CommonStyle}">
<Setter Property="Height"
Value="20" />
</Style>
</Window.Resources>
<Border>
<Grid>
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Content="GetUrl"
IsDefault="true" />
<TextBox Grid.Column="2"
Text="{Binding Url, Mode=OneWayToSource}" />
</Grid>
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource CommonStyle}">
<Setter Property="Background"
Value="LightGray" />
<Setter Property="Width"
Value="150" />
<Setter Property="Padding"
Value="5"/>
</Style>
</StackPanel.Resources>
<TextBlock Text="{Binding Size, StringFormat={}{0} bytes}" />
<TextBlock Text="{Binding Time, StringFormat={}{0} ms}" />
</StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ProgressBar x:Name="timeBar"
Minimum="0"
Maximum="1000"
Value="{Binding Time}"
Grid.ColumnSpan="3" />
<TextBlock Grid.Row="1"
Grid.Column="1"
TextAlignment="Center"
Text="500 ms" />
<TextBlock Grid.Row="1"
Grid.Column="2"
TextAlignment="Right"
Text="1000 ms" />
</Grid>
</StackPanel>
</Grid>
</Border>
</Window>

View file

@ -1,27 +0,0 @@
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DT2;
using DT3;
namespace UrlTester;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new UrlTesterModel();
}
}

View file

@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);DT3</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ObjectModel" Version="4.3.0" />
</ItemGroup>
</Project>

View file

@ -1,14 +0,0 @@
{
"folders": [
{
"name": "Solution Items",
"path": "."
},
{
"path": "./Tasks/AdvancedConcepts"
},
{
"path": "./Tasks/UrlTester"
}
]
}