Compare commits

..

21 commits

Author SHA1 Message Date
1ac34c7625 Drop use of CallerMemberName 2024-03-22 02:35:19 +01:00
a872555f93 Drop use of discard symbol 2024-03-22 02:26:17 +01:00
724e95bc57 Fix incorrect file name 2024-03-22 02:24:31 +01:00
bedbe2ea84 Split logic and design 2024-03-22 02:23:46 +01:00
7241a265e6 Fix incorrect execution order 2024-03-22 02:16:21 +01:00
cad81ce7f1 Implement data bindings using DependencyPropertys 2024-03-22 02:00:04 +01:00
08f6288f91 Run URL check using a task 2024-03-22 00:56:40 +01:00
94cb10b3df Refactor design for the second task 2024-03-22 00:43:26 +01:00
f130b631fc Implement URL inspection 2024-03-22 00:25:00 +01:00
af51421b63 Fix calls to nullable events 2024-03-22 00:23:43 +01:00
b67f9953de Create design for first task 2024-03-22 00:08:20 +01:00
9cdb89e033 Fix incorrect namespaces 2024-03-21 23:43:09 +01:00
1eee51205d Create basic design for application 2024-03-21 23:42:32 +01:00
a6967fd942 Fix incorrect namespace 2024-03-21 23:42:08 +01:00
d518c74e77 Make WPF project bootable 2024-03-21 23:35:44 +01:00
da89471f75 Create settings for debugging projects 2024-03-21 23:29:38 +01:00
a7d18f56e9 Initialize new WPF application 2024-03-21 23:24:29 +01:00
80a8817143 Implement the INotifyPropertyChanged interface 2024-03-21 23:15:24 +01:00
12a7fe3c17 Add required dependency 2024-03-21 23:08:59 +01:00
ea670fdc3c Add files for task 3 2024-03-21 22:56:48 +01:00
972d364963 Rename projects based on topic 2024-03-21 22:55:54 +01:00
21 changed files with 663 additions and 298 deletions

1
.gitignore vendored
View file

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

View file

@ -0,0 +1,26 @@
{
"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

@ -0,0 +1,41 @@
{
"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,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
</Project>

26
Tasks/UrlTester/.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,26 @@
{
"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"
}
]
}

41
Tasks/UrlTester/.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,41 @@
{
"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"
}
]
}

9
Tasks/UrlTester/App.xaml Normal file
View file

@ -0,0 +1,9 @@
<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

@ -0,0 +1,12 @@
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

@ -0,0 +1,10 @@
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

@ -88,16 +88,16 @@ namespace DT2 {
}
public int GetUrlSync(string url) {
PageStart(url);
PageStart?.Invoke(url);
int size = GetPageSize(url);
PageLoaded(url, size);
PageLoaded?.Invoke(url, size);
return size;
}
public async Task<int> GetUrlAsync(string url) {
PageStart(url);
PageStart?.Invoke(url);
int size = await Task.Run(() => GetPageSize(url));
PageLoaded(url, size);
PageLoaded?.Invoke(url, size);
return size;
}
@ -108,7 +108,7 @@ namespace DT2 {
try {
size = await task.WaitAsync(TimeSpan.FromMilliseconds(millis));
PageLoaded(url, size);
PageLoaded?.Invoke(url, size);
}
catch (TimeoutException)
{
@ -149,6 +149,7 @@ namespace DT2 {
LoadSummary("Total", totalSize, (int)sw.Elapsed.TotalMilliseconds);
}
#if DT2
public static void Main(string[] args) {
Console.WriteLine("Starting ...");
UrlTester urlTester = new UrlTester();
@ -161,5 +162,6 @@ namespace DT2 {
Console.Write("Press any key to continue ...\n");
Console.ReadKey(true);
}
#endif
}
}

View file

@ -0,0 +1,69 @@
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));
}
}
}
}

BIN
Tasks/UrlTester/DT3/DT3.pdf Normal file

Binary file not shown.

View file

@ -0,0 +1,80 @@
<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

@ -0,0 +1,27 @@
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

@ -0,0 +1,20 @@
<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>

14
zhaw-dnet2.code-workspace Normal file
View file

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