Eine neue Console anlegen

main
Obai Albek 2025-06-20 17:46:28 +00:00
parent 4da955ac72
commit cd75933513
31 changed files with 883 additions and 360 deletions

50
.vscode/launch.json vendored
View File

@ -1,26 +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}/Async_Await/bin/Debug/net8.0/Async_Await.dll",
"args": [],
"cwd": "${workspaceFolder}/Async_Await",
// 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"
}
]
{
"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}/Async_Await/bin/Debug/net8.0/Async_Await.dll",
"args": [],
"cwd": "${workspaceFolder}/Async_Await",
// 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"
}
]
}

80
.vscode/tasks.json vendored
View File

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

View File

@ -1,66 +1,66 @@
{
"format": 1,
"restore": {
"/workspaces/CSharp/Async_Await/Async_Await.csproj": {}
},
"projects": {
"/workspaces/CSharp/Async_Await/Async_Await.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/workspaces/CSharp/Async_Await/Async_Await.csproj",
"projectName": "Async_Await",
"projectPath": "/workspaces/CSharp/Async_Await/Async_Await.csproj",
"packagesPath": "/root/.nuget/packages/",
"outputPath": "/workspaces/CSharp/Async_Await/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/root/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json"
}
}
}
}
{
"format": 1,
"restore": {
"/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj": {}
},
"projects": {
"/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj",
"projectName": "Async_Await",
"projectPath": "/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj",
"packagesPath": "/root/.nuget/packages/",
"outputPath": "/workspaces/CSharpProjekt/Async_Await/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/root/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Async_Await")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9d9bacd718b457b1e622e2000d7baf963457a871")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4da955ac721d824c4df4ad42acf0ae911ae167d1")]
[assembly: System.Reflection.AssemblyProductAttribute("Async_Await")]
[assembly: System.Reflection.AssemblyTitleAttribute("Async_Await")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
715df55e00865760b049b6999c3a198f53ad831234a2f70656b0a5d26a34b8f5
98ce089cd7e71c6006d86b916e9ec71a58ea1eeca75009d9cab046ac25ea77c5

View File

@ -1,71 +1,71 @@
{
"version": 3,
"targets": {
"net8.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net8.0": []
},
"packageFolders": {
"/root/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/workspaces/CSharp/Async_Await/Async_Await.csproj",
"projectName": "Async_Await",
"projectPath": "/workspaces/CSharp/Async_Await/Async_Await.csproj",
"packagesPath": "/root/.nuget/packages/",
"outputPath": "/workspaces/CSharp/Async_Await/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/root/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json"
}
}
}
{
"version": 3,
"targets": {
"net8.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net8.0": []
},
"packageFolders": {
"/root/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj",
"projectName": "Async_Await",
"projectPath": "/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj",
"packagesPath": "/root/.nuget/packages/",
"outputPath": "/workspaces/CSharpProjekt/Async_Await/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/root/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json"
}
}
}
}

View File

@ -1,8 +1,8 @@
{
"version": 2,
"dgSpecHash": "WpEPBuOGmH8=",
"success": true,
"projectFilePath": "/workspaces/CSharp/Async_Await/Async_Await.csproj",
"expectedPackageFiles": [],
"logs": []
{
"version": 2,
"dgSpecHash": "aGThoJrW9e4=",
"success": true,
"projectFilePath": "/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj",
"expectedPackageFiles": [],
"logs": []
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MQTTnet" Version="4.1.4" />
<PackageReference Include="System.Text.Json" Version="9.0.6" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,152 @@
// See https://aka.ms/new-console-template for more information
using MQTTnet;
using MQTTnet.Client;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MqttSensorApp
{
// LÖSUNG Aufgabe 3: SensorData-Klasse implementieren
public class SensorData
{
[JsonPropertyName("temperature")]
public double Temperature { get; set; }
[JsonPropertyName("humidity")]
public double Humidity { get; set; }
[JsonPropertyName("location")]
public string Location { get; set; } = string.Empty;
}
public class Program
{
private static List<double> receivedTemperatures = new List<double>();
public static async Task Main(string[] args)
{
Console.WriteLine("MQTT Sensor Data Processor gestartet...");
// MQTT Client Setup (bereits implementiert)
var factory = new MqttFactory();
var client = factory.CreateMqttClient();
// Event Handler für empfangene Nachrichten
client.ApplicationMessageReceivedAsync += async e =>
{
var payload = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
await ProcessMessage(payload);
};
// Verbindungsoptionen
var options = new MqttClientOptionsBuilder()
.WithTcpServer("broker.hivemq.com", 1883)
.WithClientId($"SensorClient_{Guid.NewGuid()}")
.WithCleanSession()
.Build();
try
{
// Verbindung aufbauen
await client.ConnectAsync(options);
Console.WriteLine("Mit MQTT Broker verbunden");
// Topic abonnieren
await client.SubscribeAsync("sensor/data/room1");
Console.WriteLine("Topic 'sensor/data/room1' abonniert");
// Simulierte Sensordaten senden (für Testing)
await SendTestData(client);
// Programm laufen lassen
Console.WriteLine("Drücken Sie eine Taste zum Beenden...");
Console.ReadKey();
// Verbindung trennen
await client.DisconnectAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Fehler: {ex.Message}");
}
}
private static async Task ProcessMessage(string jsonPayload)
{
try
{
Console.WriteLine($"Empfangen: {jsonPayload}");
// LÖSUNG Aufgabe 3: Deserialisieren des JSON zu SensorData
var sensorData = JsonSerializer.Deserialize<SensorData>(jsonPayload);
if (sensorData != null)
{
receivedTemperatures.Add(sensorData.Temperature);
// LÖSUNG Aufgabe 2: Pattern Matching anwenden
var analysis = AnalyzeMessage(sensorData.Temperature);
Console.WriteLine($"Analyse: {analysis}");
}
// Alle 5 Nachrichten: Hohe Temperaturen anzeigen
if (receivedTemperatures.Count % 5 == 0)
{
var highTemps = FilterHighTemperatures(receivedTemperatures);
Console.WriteLine($"Hohe Temperaturen (>25°C): {string.Join(", ", highTemps.Select(t => $"{t:F1}°C"))}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Fehler beim Verarbeiten der Nachricht: {ex.Message}");
}
}
// LÖSUNG Aufgabe 1: LINQ-Abfrage implementieren
private static IEnumerable<double> FilterHighTemperatures(List<double> temperatures)
{
// LINQ Where-Klausel verwenden, um Temperaturen > 25°C zu filtern
return temperatures.Where(temp => temp > 25.0);
}
// LÖSUNG Aufgabe 2: Pattern Matching implementieren
private static string AnalyzeMessage(object value)
{
// Switch expression mit Pattern Matching
return value switch
{
double temp when temp > 30.0 => "WARNUNG: Sehr hohe Temperatur!",
double temp when temp >= 25.0 && temp <= 30.0 => "Hohe Temperatur",
double temp when temp < 25.0 => "Normale Temperatur",
string text => "Text-Nachricht erhalten",
null => "Keine Daten",
_ => "Unbekannter Datentyp"
};
}
// Hilfsmethode: Testnachrichten senden
private static async Task SendTestData(IMqttClient client)
{
var testData = new[]
{
new { temperature = 22.5, humidity = 65.0, location = "Room1" },
new { temperature = 28.3, humidity = 58.2, location = "Room1" },
new { temperature = 19.8, humidity = 72.1, location = "Room1" },
new { temperature = 31.2, humidity = 45.3, location = "Room1" },
new { temperature = 26.7, humidity = 62.8, location = "Room1" }
};
foreach (var data in testData)
{
var json = JsonSerializer.Serialize(data);
var message = new MqttApplicationMessageBuilder()
.WithTopic("sensor/data/room1")
.WithPayload(json)
.Build();
await client.PublishAsync(message);
await Task.Delay(2000); // 2 Sekunden Pause
}
}
}
}

View File

@ -0,0 +1,76 @@
{
"format": 1,
"restore": {
"/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj": {}
},
"projects": {
"/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj",
"projectName": "BeispielTasks",
"projectPath": "/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj",
"packagesPath": "/root/.nuget/packages/",
"outputPath": "/workspaces/CSharpProjekt/Solution/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/root/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"MQTTnet": {
"target": "Package",
"version": "[4.1.4, )"
},
"System.Text.Json": {
"target": "Package",
"version": "[9.0.6, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/root/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/root/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.11.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/root/.nuget/packages/" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)system.text.json/9.0.6/buildTransitive/net8.0/System.Text.Json.targets" Condition="Exists('$(NuGetPackageRoot)system.text.json/9.0.6/buildTransitive/net8.0/System.Text.Json.targets')" />
</ImportGroup>
</Project>

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]

View File

@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("BeispielTasks")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4da955ac721d824c4df4ad42acf0ae911ae167d1")]
[assembly: System.Reflection.AssemblyProductAttribute("BeispielTasks")]
[assembly: System.Reflection.AssemblyTitleAttribute("BeispielTasks")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
620d207c41d80e36530c3c7988f0445044b33e4be22ae5f8eed29fa6c84257b0

View File

@ -0,0 +1,13 @@
is_global = true
build_property.TargetFramework = net8.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = BeispielTasks
build_property.ProjectDir = /workspaces/CSharpProjekt/Solution/
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =

View File

@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View File

@ -0,0 +1 @@
b04f23883cc95a305a38b87f5e338daa9d9a70aa391889b1c3b47713a68c2033

View File

@ -0,0 +1,42 @@
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/BeispielTasks
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/BeispielTasks.deps.json
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/BeispielTasks.runtimeconfig.json
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/BeispielTasks.dll
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/BeispielTasks.pdb
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.GeneratedMSBuildEditorConfig.editorconfig
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.AssemblyInfoInputs.cache
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.AssemblyInfo.cs
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.csproj.CoreCompileInputs.cache
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.dll
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/refint/BeispielTasks.dll
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.pdb
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.genruntimeconfig.cache
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/ref/BeispielTasks.dll
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/BeispielTasks.csproj.AssemblyReference.cache
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/MQTTnet.dll
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/System.IO.Pipelines.dll
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/System.Text.Encodings.Web.dll
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/System.Text.Json.dll
/workspaces/CSharpProjekt/BeispielTasks/bin/Debug/net8.0/runtimes/browser/lib/net8.0/System.Text.Encodings.Web.dll
/workspaces/CSharpProjekt/BeispielTasks/obj/Debug/net8.0/Beispiel.98D83876.Up2Date
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/BeispielTasks
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/BeispielTasks.deps.json
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/BeispielTasks.runtimeconfig.json
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/BeispielTasks.dll
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/BeispielTasks.pdb
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/MQTTnet.dll
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/System.IO.Pipelines.dll
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/System.Text.Encodings.Web.dll
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/System.Text.Json.dll
/workspaces/CSharpProjekt/Solution/bin/Debug/net8.0/runtimes/browser/lib/net8.0/System.Text.Encodings.Web.dll
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.csproj.AssemblyReference.cache
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.GeneratedMSBuildEditorConfig.editorconfig
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfoInputs.cache
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfo.cs
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.csproj.CoreCompileInputs.cache
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/Beispiel.98D83876.Up2Date
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.dll
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/refint/BeispielTasks.dll
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.pdb
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/BeispielTasks.genruntimeconfig.cache
/workspaces/CSharpProjekt/Solution/obj/Debug/net8.0/ref/BeispielTasks.dll

Binary file not shown.

View File

@ -0,0 +1 @@
949b3858502c0fd6c698ced674b2ca502e01b36f04519a83e504d0e264619b94

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,294 @@
{
"version": 3,
"targets": {
"net8.0": {
"MQTTnet/4.1.4.563": {
"type": "package",
"compile": {
"lib/net6.0/MQTTnet.dll": {}
},
"runtime": {
"lib/net6.0/MQTTnet.dll": {}
}
},
"System.IO.Pipelines/9.0.6": {
"type": "package",
"compile": {
"lib/net8.0/System.IO.Pipelines.dll": {}
},
"runtime": {
"lib/net8.0/System.IO.Pipelines.dll": {}
},
"build": {
"buildTransitive/net8.0/_._": {}
}
},
"System.Text.Encodings.Web/9.0.6": {
"type": "package",
"compile": {
"lib/net8.0/System.Text.Encodings.Web.dll": {}
},
"runtime": {
"lib/net8.0/System.Text.Encodings.Web.dll": {}
},
"build": {
"buildTransitive/net8.0/_._": {}
},
"runtimeTargets": {
"runtimes/browser/lib/net8.0/System.Text.Encodings.Web.dll": {
"assetType": "runtime",
"rid": "browser"
}
}
},
"System.Text.Json/9.0.6": {
"type": "package",
"dependencies": {
"System.IO.Pipelines": "9.0.6",
"System.Text.Encodings.Web": "9.0.6"
},
"compile": {
"lib/net8.0/System.Text.Json.dll": {}
},
"runtime": {
"lib/net8.0/System.Text.Json.dll": {}
},
"build": {
"buildTransitive/net8.0/System.Text.Json.targets": {}
}
}
}
},
"libraries": {
"MQTTnet/4.1.4.563": {
"sha512": "gO9segUcKyQJcjV7w7OOdoAIkec7cUN65vEhYutbdWcj4rbtz/oL/RDvQVVbameXc6ChkjKx7/HbO+R8ejAUZQ==",
"type": "package",
"path": "mqttnet/4.1.4.563",
"files": [
".nupkg.metadata",
".signature.p7s",
"lib/net452/MQTTnet.dll",
"lib/net461/MQTTnet.dll",
"lib/net5.0/MQTTnet.dll",
"lib/net6.0/MQTTnet.dll",
"lib/netcoreapp3.1/MQTTnet.dll",
"lib/netstandard1.3/MQTTnet.dll",
"lib/netstandard2.0/MQTTnet.dll",
"lib/netstandard2.1/MQTTnet.dll",
"lib/uap10.0.10240/MQTTnet.dll",
"lib/uap10.0.10240/MQTTnet.pri",
"mqttnet.4.1.4.563.nupkg.sha512",
"mqttnet.nuspec",
"nuget.png"
]
},
"System.IO.Pipelines/9.0.6": {
"sha512": "0nlr0reXrRmkZNKifKqh2DgGhQgfkT7Qa3gQxIn/JI7/y3WDiTz67M+Sq3vFhUqcG8O5zVrpqHvIHeGPGUBsEw==",
"type": "package",
"path": "system.io.pipelines/9.0.6",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"PACKAGE.md",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/net461/System.IO.Pipelines.targets",
"buildTransitive/net462/_._",
"buildTransitive/net8.0/_._",
"buildTransitive/netcoreapp2.0/System.IO.Pipelines.targets",
"lib/net462/System.IO.Pipelines.dll",
"lib/net8.0/System.IO.Pipelines.dll",
"lib/net9.0/System.IO.Pipelines.dll",
"lib/netstandard2.0/System.IO.Pipelines.dll",
"system.io.pipelines.9.0.6.nupkg.sha512",
"system.io.pipelines.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Text.Encodings.Web/9.0.6": {
"sha512": "uWRgViw2yJAUyGxrzDLCc6fkzE2dZIoXxs8V6YjCujKsJuP0pnpYSlbm2/7tKd0SjBnMtwfDQhLenk3bXonVOA==",
"type": "package",
"path": "system.text.encodings.web/9.0.6",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"PACKAGE.md",
"THIRD-PARTY-NOTICES.TXT",
"buildTransitive/net461/System.Text.Encodings.Web.targets",
"buildTransitive/net462/_._",
"buildTransitive/net8.0/_._",
"buildTransitive/netcoreapp2.0/System.Text.Encodings.Web.targets",
"lib/net462/System.Text.Encodings.Web.dll",
"lib/net8.0/System.Text.Encodings.Web.dll",
"lib/net9.0/System.Text.Encodings.Web.dll",
"lib/netstandard2.0/System.Text.Encodings.Web.dll",
"runtimes/browser/lib/net8.0/System.Text.Encodings.Web.dll",
"runtimes/browser/lib/net8.0/System.Text.Encodings.Web.xml",
"runtimes/browser/lib/net9.0/System.Text.Encodings.Web.dll",
"runtimes/browser/lib/net9.0/System.Text.Encodings.Web.xml",
"system.text.encodings.web.9.0.6.nupkg.sha512",
"system.text.encodings.web.nuspec",
"useSharedDesignerContext.txt"
]
},
"System.Text.Json/9.0.6": {
"sha512": "h+ZtYTyTnTh5Ju6mHCKb3FPGx4ylJZgm9W7Y2psUnkhQRPMOIxX+TCN0ZgaR/+Yea+93XHWAaMzYTar1/EHIPg==",
"type": "package",
"path": "system.text.json/9.0.6",
"files": [
".nupkg.metadata",
".signature.p7s",
"Icon.png",
"LICENSE.TXT",
"PACKAGE.md",
"THIRD-PARTY-NOTICES.TXT",
"analyzers/dotnet/roslyn3.11/cs/System.Text.Json.SourceGeneration.dll",
"analyzers/dotnet/roslyn3.11/cs/cs/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/de/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/es/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/fr/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/it/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/ja/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/ko/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/pl/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/pt-BR/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/ru/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/tr/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/zh-Hans/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn3.11/cs/zh-Hant/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/System.Text.Json.SourceGeneration.dll",
"analyzers/dotnet/roslyn4.0/cs/cs/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/de/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/es/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/fr/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/it/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/ja/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/ko/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/pl/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/pt-BR/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/ru/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/tr/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/zh-Hans/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.0/cs/zh-Hant/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/System.Text.Json.SourceGeneration.dll",
"analyzers/dotnet/roslyn4.4/cs/cs/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/de/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/es/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/fr/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/it/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/ja/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/ko/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/pl/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/pt-BR/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/ru/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/tr/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/zh-Hans/System.Text.Json.SourceGeneration.resources.dll",
"analyzers/dotnet/roslyn4.4/cs/zh-Hant/System.Text.Json.SourceGeneration.resources.dll",
"buildTransitive/net461/System.Text.Json.targets",
"buildTransitive/net462/System.Text.Json.targets",
"buildTransitive/net8.0/System.Text.Json.targets",
"buildTransitive/netcoreapp2.0/System.Text.Json.targets",
"buildTransitive/netstandard2.0/System.Text.Json.targets",
"lib/net462/System.Text.Json.dll",
"lib/net8.0/System.Text.Json.dll",
"lib/net9.0/System.Text.Json.dll",
"lib/netstandard2.0/System.Text.Json.dll",
"system.text.json.9.0.6.nupkg.sha512",
"system.text.json.nuspec",
"useSharedDesignerContext.txt"
]
}
},
"projectFileDependencyGroups": {
"net8.0": [
"MQTTnet >= 4.1.4",
"System.Text.Json >= 9.0.6"
]
},
"packageFolders": {
"/root/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj",
"projectName": "BeispielTasks",
"projectPath": "/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj",
"packagesPath": "/root/.nuget/packages/",
"outputPath": "/workspaces/CSharpProjekt/Solution/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/root/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net8.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"dependencies": {
"MQTTnet": {
"target": "Package",
"version": "[4.1.4, )"
},
"System.Text.Json": {
"target": "Package",
"version": "[9.0.6, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json"
}
}
},
"logs": [
{
"code": "NU1603",
"level": "Warning",
"warningLevel": 1,
"message": "BeispielTasks depends on MQTTnet (>= 4.1.4) but MQTTnet 4.1.4 was not found. An approximate best match of MQTTnet 4.1.4.563 was resolved.",
"libraryId": "MQTTnet",
"targetGraphs": [
"net8.0"
]
}
]
}

View File

@ -0,0 +1,24 @@
{
"version": 2,
"dgSpecHash": "+DKi8TX5UxE=",
"success": true,
"projectFilePath": "/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj",
"expectedPackageFiles": [
"/root/.nuget/packages/mqttnet/4.1.4.563/mqttnet.4.1.4.563.nupkg.sha512",
"/root/.nuget/packages/system.io.pipelines/9.0.6/system.io.pipelines.9.0.6.nupkg.sha512",
"/root/.nuget/packages/system.text.encodings.web/9.0.6/system.text.encodings.web.9.0.6.nupkg.sha512",
"/root/.nuget/packages/system.text.json/9.0.6/system.text.json.9.0.6.nupkg.sha512"
],
"logs": [
{
"code": "NU1603",
"level": "Warning",
"warningLevel": 1,
"message": "BeispielTasks depends on MQTTnet (>= 4.1.4) but MQTTnet 4.1.4 was not found. An approximate best match of MQTTnet 4.1.4.563 was resolved.",
"libraryId": "MQTTnet",
"targetGraphs": [
"net8.0"
]
}
]
}

View File

@ -1,151 +0,0 @@
using MQTTnet;
using MQTTnet.Client;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MqttSensorApp
{
// LÖSUNG Aufgabe 3: SensorData-Klasse implementieren
public class SensorData
{
[JsonPropertyName("temperature")]
public double Temperature { get; set; }
[JsonPropertyName("humidity")]
public double Humidity { get; set; }
[JsonPropertyName("location")]
public string Location { get; set; } = string.Empty;
}
public class Program
{
private static List<double> receivedTemperatures = new List<double>();
public static async Task Main(string[] args)
{
Console.WriteLine("MQTT Sensor Data Processor gestartet...");
// MQTT Client Setup (bereits implementiert)
var factory = new MqttFactory();
var client = factory.CreateMqttClient();
// Event Handler für empfangene Nachrichten
client.ApplicationMessageReceivedAsync += async e =>
{
var payload = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
await ProcessMessage(payload);
};
// Verbindungsoptionen
var options = new MqttClientOptionsBuilder()
.WithTcpServer("broker.hivemq.com", 1883)
.WithClientId($"SensorClient_{Guid.NewGuid()}")
.WithCleanSession()
.Build();
try
{
// Verbindung aufbauen
await client.ConnectAsync(options);
Console.WriteLine("Mit MQTT Broker verbunden");
// Topic abonnieren
await client.SubscribeAsync("sensor/data/room1");
Console.WriteLine("Topic 'sensor/data/room1' abonniert");
// Simulierte Sensordaten senden (für Testing)
await SendTestData(client);
// Programm laufen lassen
Console.WriteLine("Drücken Sie eine Taste zum Beenden...");
Console.ReadKey();
// Verbindung trennen
await client.DisconnectAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Fehler: {ex.Message}");
}
}
private static async Task ProcessMessage(string jsonPayload)
{
try
{
Console.WriteLine($"Empfangen: {jsonPayload}");
// LÖSUNG Aufgabe 3: Deserialisieren des JSON zu SensorData
var sensorData = JsonSerializer.Deserialize<SensorData>(jsonPayload);
if (sensorData != null)
{
receivedTemperatures.Add(sensorData.Temperature);
// LÖSUNG Aufgabe 2: Pattern Matching anwenden
var analysis = AnalyzeMessage(sensorData.Temperature);
Console.WriteLine($"Analyse: {analysis}");
}
// Alle 5 Nachrichten: Hohe Temperaturen anzeigen
if (receivedTemperatures.Count % 5 == 0)
{
var highTemps = FilterHighTemperatures(receivedTemperatures);
Console.WriteLine($"Hohe Temperaturen (>25°C): {string.Join(", ", highTemps.Select(t => $"{t:F1}°C"))}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Fehler beim Verarbeiten der Nachricht: {ex.Message}");
}
}
// LÖSUNG Aufgabe 1: LINQ-Abfrage implementieren
private static IEnumerable<double> FilterHighTemperatures(List<double> temperatures)
{
// LINQ Where-Klausel verwenden, um Temperaturen > 25°C zu filtern
return temperatures.Where(temp => temp > 25.0);
}
// LÖSUNG Aufgabe 2: Pattern Matching implementieren
private static string AnalyzeMessage(object value)
{
// Switch expression mit Pattern Matching
return value switch
{
double temp when temp > 30.0 => "WARNUNG: Sehr hohe Temperatur!",
double temp when temp >= 25.0 && temp <= 30.0 => "Hohe Temperatur",
double temp when temp < 25.0 => "Normale Temperatur",
string text => "Text-Nachricht erhalten",
null => "Keine Daten",
_ => "Unbekannter Datentyp"
};
}
// Hilfsmethode: Testnachrichten senden
private static async Task SendTestData(IMqttClient client)
{
var testData = new[]
{
new { temperature = 22.5, humidity = 65.0, location = "Room1" },
new { temperature = 28.3, humidity = 58.2, location = "Room1" },
new { temperature = 19.8, humidity = 72.1, location = "Room1" },
new { temperature = 31.2, humidity = 45.3, location = "Room1" },
new { temperature = 26.7, humidity = 62.8, location = "Room1" }
};
foreach (var data in testData)
{
var json = JsonSerializer.Serialize(data);
var message = new MqttApplicationMessageBuilder()
.WithTopic("sensor/data/room1")
.WithPayload(json)
.Build();
await client.PublishAsync(message);
await Task.Delay(2000); // 2 Sekunden Pause
}
}
}
}