diff --git a/Async_Await/obj/Async_Await.csproj.nuget.dgspec.json b/Async_Await/obj/Async_Await.csproj.nuget.dgspec.json index fcb4047..b4188e2 100644 --- a/Async_Await/obj/Async_Await.csproj.nuget.dgspec.json +++ b/Async_Await/obj/Async_Await.csproj.nuget.dgspec.json @@ -58,7 +58,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json" } } } diff --git a/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfo.cs b/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfo.cs index bd1a522..0588597 100644 --- a/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfo.cs +++ b/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfo.cs @@ -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+4da955ac721d824c4df4ad42acf0ae911ae167d1")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cd7593351362efbc0ee81bbfb2c1c49fb0d4a4d1")] [assembly: System.Reflection.AssemblyProductAttribute("Async_Await")] [assembly: System.Reflection.AssemblyTitleAttribute("Async_Await")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfoInputs.cache b/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfoInputs.cache index 9f4ad83..cf0ce50 100644 --- a/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfoInputs.cache +++ b/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfoInputs.cache @@ -1 +1 @@ -98ce089cd7e71c6006d86b916e9ec71a58ea1eeca75009d9cab046ac25ea77c5 +445627bd860633fe081918fd049f41b1231fc74fc9d98398e02e01b85ee36027 diff --git a/Async_Await/obj/Debug/net8.0/Async_Await.csproj.CoreCompileInputs.cache b/Async_Await/obj/Debug/net8.0/Async_Await.csproj.CoreCompileInputs.cache index 2784c70..69e2614 100644 --- a/Async_Await/obj/Debug/net8.0/Async_Await.csproj.CoreCompileInputs.cache +++ b/Async_Await/obj/Debug/net8.0/Async_Await.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -f56eca8a218035aaee0739bd26bba4d23e0f75fd08331f478a25b9179244fa4b +f56eca8a218035aaee0739bd26bba4d23e0f75fd08331f478a25b9179244fa4b diff --git a/Async_Await/obj/Debug/net8.0/Async_Await.csproj.FileListAbsolute.txt b/Async_Await/obj/Debug/net8.0/Async_Await.csproj.FileListAbsolute.txt index 23223c6..9c68375 100644 --- a/Async_Await/obj/Debug/net8.0/Async_Await.csproj.FileListAbsolute.txt +++ b/Async_Await/obj/Debug/net8.0/Async_Await.csproj.FileListAbsolute.txt @@ -1,14 +1,28 @@ -/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await -/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.deps.json -/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.runtimeconfig.json -/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.dll -/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.pdb -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.GeneratedMSBuildEditorConfig.editorconfig -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfoInputs.cache -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfo.cs -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.csproj.CoreCompileInputs.cache -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.dll -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/refint/Async_Await.dll -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.pdb -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.genruntimeconfig.cache -/workspaces/CSharp/Async_Await/obj/Debug/net8.0/ref/Async_Await.dll +/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await +/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.deps.json +/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.runtimeconfig.json +/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.dll +/workspaces/CSharp/Async_Await/bin/Debug/net8.0/Async_Await.pdb +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.GeneratedMSBuildEditorConfig.editorconfig +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfoInputs.cache +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfo.cs +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.csproj.CoreCompileInputs.cache +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.dll +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/refint/Async_Await.dll +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.pdb +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/Async_Await.genruntimeconfig.cache +/workspaces/CSharp/Async_Await/obj/Debug/net8.0/ref/Async_Await.dll +/workspaces/CSharpProjekt/Async_Await/bin/Debug/net8.0/Async_Await +/workspaces/CSharpProjekt/Async_Await/bin/Debug/net8.0/Async_Await.deps.json +/workspaces/CSharpProjekt/Async_Await/bin/Debug/net8.0/Async_Await.runtimeconfig.json +/workspaces/CSharpProjekt/Async_Await/bin/Debug/net8.0/Async_Await.dll +/workspaces/CSharpProjekt/Async_Await/bin/Debug/net8.0/Async_Await.pdb +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/Async_Await.GeneratedMSBuildEditorConfig.editorconfig +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfoInputs.cache +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/Async_Await.AssemblyInfo.cs +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/Async_Await.csproj.CoreCompileInputs.cache +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/Async_Await.dll +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/refint/Async_Await.dll +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/Async_Await.pdb +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/Async_Await.genruntimeconfig.cache +/workspaces/CSharpProjekt/Async_Await/obj/Debug/net8.0/ref/Async_Await.dll diff --git a/Async_Await/obj/Debug/net8.0/Async_Await.dll b/Async_Await/obj/Debug/net8.0/Async_Await.dll index afa1275..5ba16b4 100644 Binary files a/Async_Await/obj/Debug/net8.0/Async_Await.dll and b/Async_Await/obj/Debug/net8.0/Async_Await.dll differ diff --git a/Async_Await/obj/Debug/net8.0/Async_Await.genruntimeconfig.cache b/Async_Await/obj/Debug/net8.0/Async_Await.genruntimeconfig.cache index c9e9627..07bdd73 100644 --- a/Async_Await/obj/Debug/net8.0/Async_Await.genruntimeconfig.cache +++ b/Async_Await/obj/Debug/net8.0/Async_Await.genruntimeconfig.cache @@ -1 +1 @@ -735e7f2d774271d1780a96fe641c2f5ec6cf42f9b6bbfa8ed546e26d04a0fe35 +5e790f0d1b03a5f5093b7d5892a37e2a027e6814cb7daf8584b26f45bc87a335 diff --git a/Async_Await/obj/Debug/net8.0/Async_Await.pdb b/Async_Await/obj/Debug/net8.0/Async_Await.pdb index 230b3d2..294a1fa 100644 Binary files a/Async_Await/obj/Debug/net8.0/Async_Await.pdb and b/Async_Await/obj/Debug/net8.0/Async_Await.pdb differ diff --git a/Async_Await/obj/Debug/net8.0/ref/Async_Await.dll b/Async_Await/obj/Debug/net8.0/ref/Async_Await.dll index 2ef5e72..fedfe58 100644 Binary files a/Async_Await/obj/Debug/net8.0/ref/Async_Await.dll and b/Async_Await/obj/Debug/net8.0/ref/Async_Await.dll differ diff --git a/Async_Await/obj/Debug/net8.0/refint/Async_Await.dll b/Async_Await/obj/Debug/net8.0/refint/Async_Await.dll index 2ef5e72..fedfe58 100644 Binary files a/Async_Await/obj/Debug/net8.0/refint/Async_Await.dll and b/Async_Await/obj/Debug/net8.0/refint/Async_Await.dll differ diff --git a/Async_Await/obj/project.assets.json b/Async_Await/obj/project.assets.json index aabb35b..eb94d51 100644 --- a/Async_Await/obj/project.assets.json +++ b/Async_Await/obj/project.assets.json @@ -64,7 +64,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json" } } } diff --git a/Async_Await/obj/project.nuget.cache b/Async_Await/obj/project.nuget.cache index 4f1eede..083c56a 100644 --- a/Async_Await/obj/project.nuget.cache +++ b/Async_Await/obj/project.nuget.cache @@ -1,6 +1,6 @@ { "version": 2, - "dgSpecHash": "aGThoJrW9e4=", + "dgSpecHash": "D3gTvPK0/Io=", "success": true, "projectFilePath": "/workspaces/CSharpProjekt/Async_Await/Async_Await.csproj", "expectedPackageFiles": [], diff --git a/C# PR3 SS25.pdf b/C# PR3 SS25.pdf new file mode 100644 index 0000000..423c2cd Binary files /dev/null and b/C# PR3 SS25.pdf differ diff --git a/README.md b/README.md index 5c016e9..2d62477 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # CSharpProjekt +Devcontainer und Repository: Obai Albek (3009594) +Überblick: Bohdana Illiuk (3013009) +Tooling: Devran Cakici (3009694) +Basics: David Werner (2121694) +Standard Library: Antonio Junakovic (3006354) +Asynchrone Programmierung: Florin Küppers (3015901) +Spezielle Konzepte: Lennart Streveld (3011294) + +Folien überarbeiten: Florin Küppers (3015901) \ No newline at end of file diff --git a/Solution/obj/BeispielTasks.csproj.nuget.dgspec.json b/Solution/obj/BeispielTasks.csproj.nuget.dgspec.json index b7ed360..6ff6ad5 100644 --- a/Solution/obj/BeispielTasks.csproj.nuget.dgspec.json +++ b/Solution/obj/BeispielTasks.csproj.nuget.dgspec.json @@ -68,7 +68,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json" } } } diff --git a/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfo.cs b/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfo.cs index 448f7db..e56f46e 100644 --- a/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfo.cs +++ b/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfo.cs @@ -13,7 +13,7 @@ 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.AssemblyInformationalVersionAttribute("1.0.0+cd7593351362efbc0ee81bbfb2c1c49fb0d4a4d1")] [assembly: System.Reflection.AssemblyProductAttribute("BeispielTasks")] [assembly: System.Reflection.AssemblyTitleAttribute("BeispielTasks")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfoInputs.cache b/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfoInputs.cache index 8acd6b8..1dc62f7 100644 --- a/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfoInputs.cache +++ b/Solution/obj/Debug/net8.0/BeispielTasks.AssemblyInfoInputs.cache @@ -1 +1 @@ -620d207c41d80e36530c3c7988f0445044b33e4be22ae5f8eed29fa6c84257b0 +43bee51014acdb8b04a0b500e4b24fda6a5ca7028c80fd13f6ccae844bad65aa diff --git a/Solution/obj/Debug/net8.0/BeispielTasks.csproj.CoreCompileInputs.cache b/Solution/obj/Debug/net8.0/BeispielTasks.csproj.CoreCompileInputs.cache index 7733d11..749f861 100644 --- a/Solution/obj/Debug/net8.0/BeispielTasks.csproj.CoreCompileInputs.cache +++ b/Solution/obj/Debug/net8.0/BeispielTasks.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -b04f23883cc95a305a38b87f5e338daa9d9a70aa391889b1c3b47713a68c2033 +6c522ee2758e63ae92db243f9519a8207ef0cfe0064c0f5f62889a36444a5977 diff --git a/Solution/obj/Debug/net8.0/BeispielTasks.dll b/Solution/obj/Debug/net8.0/BeispielTasks.dll index c04bf1d..e592a9e 100644 Binary files a/Solution/obj/Debug/net8.0/BeispielTasks.dll and b/Solution/obj/Debug/net8.0/BeispielTasks.dll differ diff --git a/Solution/obj/Debug/net8.0/BeispielTasks.pdb b/Solution/obj/Debug/net8.0/BeispielTasks.pdb index a63a60a..bccf30e 100644 Binary files a/Solution/obj/Debug/net8.0/BeispielTasks.pdb and b/Solution/obj/Debug/net8.0/BeispielTasks.pdb differ diff --git a/Solution/obj/Debug/net8.0/apphost b/Solution/obj/Debug/net8.0/apphost old mode 100644 new mode 100755 index d071b47..5d668ec Binary files a/Solution/obj/Debug/net8.0/apphost and b/Solution/obj/Debug/net8.0/apphost differ diff --git a/Solution/obj/Debug/net8.0/ref/BeispielTasks.dll b/Solution/obj/Debug/net8.0/ref/BeispielTasks.dll index f083bcb..7749334 100644 Binary files a/Solution/obj/Debug/net8.0/ref/BeispielTasks.dll and b/Solution/obj/Debug/net8.0/ref/BeispielTasks.dll differ diff --git a/Solution/obj/Debug/net8.0/refint/BeispielTasks.dll b/Solution/obj/Debug/net8.0/refint/BeispielTasks.dll index f083bcb..7749334 100644 Binary files a/Solution/obj/Debug/net8.0/refint/BeispielTasks.dll and b/Solution/obj/Debug/net8.0/refint/BeispielTasks.dll differ diff --git a/Solution/obj/project.assets.json b/Solution/obj/project.assets.json index 80d7788..4602f6e 100644 --- a/Solution/obj/project.assets.json +++ b/Solution/obj/project.assets.json @@ -275,7 +275,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.411/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "/usr/share/dotnet/sdk/8.0.410/PortableRuntimeIdentifierGraph.json" } } }, diff --git a/Solution/obj/project.nuget.cache b/Solution/obj/project.nuget.cache index 05a2d24..591d246 100644 --- a/Solution/obj/project.nuget.cache +++ b/Solution/obj/project.nuget.cache @@ -1,6 +1,6 @@ { "version": 2, - "dgSpecHash": "+DKi8TX5UxE=", + "dgSpecHash": "n7Bg6jO44+4=", "success": true, "projectFilePath": "/workspaces/CSharpProjekt/Solution/BeispielTasks.csproj", "expectedPackageFiles": [ diff --git a/Task/Task.csproj b/Task/Task.csproj new file mode 100644 index 0000000..c1dda92 --- /dev/null +++ b/Task/Task.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/mqtt_task_pr3_solution.cs b/Task/code.cs similarity index 100% rename from mqtt_task_pr3_solution.cs rename to Task/code.cs diff --git a/Task/code.java b/Task/code.java new file mode 100644 index 0000000..e69de29 diff --git a/mqtt_task_pr3.cs b/Task/mqtt_task_pr3.cs similarity index 97% rename from mqtt_task_pr3.cs rename to Task/mqtt_task_pr3.cs index c460a00..6eb0ce4 100644 --- a/mqtt_task_pr3.cs +++ b/Task/mqtt_task_pr3.cs @@ -1,151 +1,151 @@ -using MQTTnet; -using MQTTnet.Client; -using System.Text.Json; - -namespace MqttSensorApp -{ - // TODO: Aufgabe 3: Implementieren Sie die SensorData-Klasse - public class SensorData - { - // TODO: Ergänzen Sie Properties für Temperature, Humidity und Location - // Nutzen Sie JsonPropertyName-Attribute für die JSON-Deserialisierung - - } - - public class Program - { - private static List receivedTemperatures = new List(); - - 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}"); - - // TODO: Aufgabe 3: Deserialisieren Sie den JSON zu SensorData - // var sensorData = JsonSerializer.Deserialize(jsonPayload); - - // Temporäre Lösung für Aufgabe 1 und 2 - var data = JsonSerializer.Deserialize>(jsonPayload); - - if (data != null && data.ContainsKey("temperature")) - { - var temp = Convert.ToDouble(data["temperature"].ToString()); - receivedTemperatures.Add(temp); - - // Nachricht analysieren - var analysis = AnalyzeMessage(temp); - 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}"); - } - } - - // TODO: Aufgabe 1: LINQ-Abfrage implementieren - private static IEnumerable FilterHighTemperatures(List temperatures) - { - // TODO: Verwenden Sie LINQ (Where-Klausel), um alle Temperaturen > 25°C zu filtern - // Beispiel: return temperatures.Where(...); - - return new List(); // Platzhalter, ersetzen Sie diese Zeile - } - - // TODO: Aufgabe 2: Pattern Matching implementieren - private static string AnalyzeMessage(object value) - { - // TODO: Implementieren Sie Pattern Matching mit switch expression - // Behandeln Sie folgende Fälle: - // - double über 30: "WARNUNG: Sehr hohe Temperatur!" - // - double zwischen 25-30: "Hohe Temperatur" - // - double unter 25: "Normale Temperatur" - // - string: "Text-Nachricht erhalten" - // - null: "Keine Daten" - // - default: "Unbekannter Datentyp" - - return "TODO: Pattern Matching implementieren"; // Platzhalter - } - - // 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 - } - } - } +using MQTTnet; +using MQTTnet.Client; +using System.Text.Json; + +namespace MqttSensorApp +{ + // TODO: Aufgabe 3: Implementieren Sie die SensorData-Klasse + public class SensorData + { + // TODO: Ergänzen Sie Properties für Temperature, Humidity und Location + // Nutzen Sie JsonPropertyName-Attribute für die JSON-Deserialisierung + + } + + public class Program + { + private static List receivedTemperatures = new List(); + + 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}"); + + // TODO: Aufgabe 3: Deserialisieren Sie den JSON zu SensorData + // var sensorData = JsonSerializer.Deserialize(jsonPayload); + + // Temporäre Lösung für Aufgabe 1 und 2 + var data = JsonSerializer.Deserialize>(jsonPayload); + + if (data != null && data.ContainsKey("temperature")) + { + var temp = Convert.ToDouble(data["temperature"].ToString()); + receivedTemperatures.Add(temp); + + // Nachricht analysieren + var analysis = AnalyzeMessage(temp); + 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}"); + } + } + + // TODO: Aufgabe 1: LINQ-Abfrage implementieren + private static IEnumerable FilterHighTemperatures(List temperatures) + { + // TODO: Verwenden Sie LINQ (Where-Klausel), um alle Temperaturen > 25°C zu filtern + // Beispiel: return temperatures.Where(...); + + return new List(); // Platzhalter, ersetzen Sie diese Zeile + } + + // TODO: Aufgabe 2: Pattern Matching implementieren + private static string AnalyzeMessage(object value) + { + // TODO: Implementieren Sie Pattern Matching mit switch expression + // Behandeln Sie folgende Fälle: + // - double über 30: "WARNUNG: Sehr hohe Temperatur!" + // - double zwischen 25-30: "Hohe Temperatur" + // - double unter 25: "Normale Temperatur" + // - string: "Text-Nachricht erhalten" + // - null: "Keine Daten" + // - default: "Unbekannter Datentyp" + + return "TODO: Pattern Matching implementieren"; // Platzhalter + } + + // 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 + } + } + } } \ No newline at end of file diff --git a/Task/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs b/Task/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs new file mode 100644 index 0000000..2217181 --- /dev/null +++ b/Task/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")] diff --git a/Task/obj/Debug/net8.0/Task.AssemblyInfo.cs b/Task/obj/Debug/net8.0/Task.AssemblyInfo.cs new file mode 100644 index 0000000..b5f3a72 --- /dev/null +++ b/Task/obj/Debug/net8.0/Task.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("Task")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+cd7593351362efbc0ee81bbfb2c1c49fb0d4a4d1")] +[assembly: System.Reflection.AssemblyProductAttribute("Task")] +[assembly: System.Reflection.AssemblyTitleAttribute("Task")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// Generated by the MSBuild WriteCodeFragment class. + diff --git a/Task/obj/Debug/net8.0/Task.AssemblyInfoInputs.cache b/Task/obj/Debug/net8.0/Task.AssemblyInfoInputs.cache new file mode 100644 index 0000000..e916a67 --- /dev/null +++ b/Task/obj/Debug/net8.0/Task.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +31b55a850cac75ab4034ec174f82920fdaa49a7335913764ad2b66b48a4490d3 diff --git a/Task/obj/Debug/net8.0/Task.GeneratedMSBuildEditorConfig.editorconfig b/Task/obj/Debug/net8.0/Task.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..14d4b51 --- /dev/null +++ b/Task/obj/Debug/net8.0/Task.GeneratedMSBuildEditorConfig.editorconfig @@ -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 = Task +build_property.ProjectDir = /workspaces/CSharpProjekt/Task/ +build_property.EnableComHosting = +build_property.EnableGeneratedComInterfaceComImportInterop = diff --git a/Task/obj/Debug/net8.0/Task.GlobalUsings.g.cs b/Task/obj/Debug/net8.0/Task.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/Task/obj/Debug/net8.0/Task.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +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; diff --git a/Task/obj/Debug/net8.0/Task.assets.cache b/Task/obj/Debug/net8.0/Task.assets.cache new file mode 100644 index 0000000..63856a8 Binary files /dev/null and b/Task/obj/Debug/net8.0/Task.assets.cache differ diff --git a/Task/obj/Debug/net8.0/Task.csproj.AssemblyReference.cache b/Task/obj/Debug/net8.0/Task.csproj.AssemblyReference.cache new file mode 100644 index 0000000..04420fe Binary files /dev/null and b/Task/obj/Debug/net8.0/Task.csproj.AssemblyReference.cache differ diff --git a/Task/obj/Debug/net8.0/Task.csproj.CoreCompileInputs.cache b/Task/obj/Debug/net8.0/Task.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..03785cf --- /dev/null +++ b/Task/obj/Debug/net8.0/Task.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +d29642cf35b28a758071260be4d61fce4bf86363728ef9dd4f8fe3a44e585bfc diff --git a/Task/obj/Debug/net8.0/Task.csproj.FileListAbsolute.txt b/Task/obj/Debug/net8.0/Task.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..3c07165 --- /dev/null +++ b/Task/obj/Debug/net8.0/Task.csproj.FileListAbsolute.txt @@ -0,0 +1,17 @@ +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.GeneratedMSBuildEditorConfig.editorconfig +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.AssemblyInfoInputs.cache +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.AssemblyInfo.cs +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.csproj.CoreCompileInputs.cache +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.csproj.AssemblyReference.cache +/workspaces/CSharpProjekt/Task/bin/Debug/net8.0/Task +/workspaces/CSharpProjekt/Task/bin/Debug/net8.0/Task.deps.json +/workspaces/CSharpProjekt/Task/bin/Debug/net8.0/Task.runtimeconfig.json +/workspaces/CSharpProjekt/Task/bin/Debug/net8.0/Task.dll +/workspaces/CSharpProjekt/Task/bin/Debug/net8.0/Task.pdb +/workspaces/CSharpProjekt/Task/bin/Debug/net8.0/MQTTnet.dll +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.csproj.Up2Date +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.dll +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/refint/Task.dll +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.pdb +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/Task.genruntimeconfig.cache +/workspaces/CSharpProjekt/Task/obj/Debug/net8.0/ref/Task.dll diff --git a/Task/obj/Debug/net8.0/Task.csproj.Up2Date b/Task/obj/Debug/net8.0/Task.csproj.Up2Date new file mode 100644 index 0000000..e69de29 diff --git a/Task/obj/Debug/net8.0/Task.dll b/Task/obj/Debug/net8.0/Task.dll new file mode 100644 index 0000000..8558042 Binary files /dev/null and b/Task/obj/Debug/net8.0/Task.dll differ diff --git a/Task/obj/Debug/net8.0/Task.genruntimeconfig.cache b/Task/obj/Debug/net8.0/Task.genruntimeconfig.cache new file mode 100644 index 0000000..5b6f0dc --- /dev/null +++ b/Task/obj/Debug/net8.0/Task.genruntimeconfig.cache @@ -0,0 +1 @@ +3d0da4a8604357aef0ae0dd967df15ba5ad639f3c048513f32eb6b0be41bc94a diff --git a/Task/obj/Debug/net8.0/Task.pdb b/Task/obj/Debug/net8.0/Task.pdb new file mode 100644 index 0000000..b90db4a Binary files /dev/null and b/Task/obj/Debug/net8.0/Task.pdb differ diff --git a/Task/obj/Debug/net8.0/apphost b/Task/obj/Debug/net8.0/apphost new file mode 100755 index 0000000..123b04e Binary files /dev/null and b/Task/obj/Debug/net8.0/apphost differ diff --git a/Task/obj/Debug/net8.0/ref/Task.dll b/Task/obj/Debug/net8.0/ref/Task.dll new file mode 100644 index 0000000..4a217d7 Binary files /dev/null and b/Task/obj/Debug/net8.0/ref/Task.dll differ diff --git a/Task/obj/Debug/net8.0/refint/Task.dll b/Task/obj/Debug/net8.0/refint/Task.dll new file mode 100644 index 0000000..4a217d7 Binary files /dev/null and b/Task/obj/Debug/net8.0/refint/Task.dll differ diff --git a/Task/obj/Task.csproj.nuget.dgspec.json b/Task/obj/Task.csproj.nuget.dgspec.json new file mode 100644 index 0000000..93ded04 --- /dev/null +++ b/Task/obj/Task.csproj.nuget.dgspec.json @@ -0,0 +1,72 @@ +{ + "format": 1, + "restore": { + "/workspaces/CSharpProjekt/Task/Task.csproj": {} + }, + "projects": { + "/workspaces/CSharpProjekt/Task/Task.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/workspaces/CSharpProjekt/Task/Task.csproj", + "projectName": "Task", + "projectPath": "/workspaces/CSharpProjekt/Task/Task.csproj", + "packagesPath": "/root/.nuget/packages/", + "outputPath": "/workspaces/CSharpProjekt/Task/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.*, )" + } + }, + "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" + } + } + } + } +} \ No newline at end of file diff --git a/Task/obj/Task.csproj.nuget.g.props b/Task/obj/Task.csproj.nuget.g.props new file mode 100644 index 0000000..112d2bb --- /dev/null +++ b/Task/obj/Task.csproj.nuget.g.props @@ -0,0 +1,15 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + /root/.nuget/packages/ + /root/.nuget/packages/ + PackageReference + 6.11.1 + + + + + \ No newline at end of file diff --git a/Task/obj/Task.csproj.nuget.g.targets b/Task/obj/Task.csproj.nuget.g.targets new file mode 100644 index 0000000..3dc06ef --- /dev/null +++ b/Task/obj/Task.csproj.nuget.g.targets @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Task/obj/project.assets.json b/Task/obj/project.assets.json new file mode 100644 index 0000000..0333673 --- /dev/null +++ b/Task/obj/project.assets.json @@ -0,0 +1,114 @@ +{ + "version": 3, + "targets": { + "net8.0": { + "MQTTnet/4.3.7.1207": { + "type": "package", + "compile": { + "lib/net7.0/MQTTnet.dll": {} + }, + "runtime": { + "lib/net7.0/MQTTnet.dll": {} + } + } + } + }, + "libraries": { + "MQTTnet/4.3.7.1207": { + "sha512": "ah7aHXoedWp5m5a4zy2u4phOEVj0QFYzOb5tFKQeV8RRBrxp+1QREF4ymZuG8D+hzB2dhtrrG81WxTFv0PzOeQ==", + "type": "package", + "path": "mqttnet/4.3.7.1207", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "lib/net452/MQTTnet.dll", + "lib/net461/MQTTnet.dll", + "lib/net48/MQTTnet.dll", + "lib/net5.0/MQTTnet.dll", + "lib/net6.0/MQTTnet.dll", + "lib/net7.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.3.7.1207.nupkg.sha512", + "mqttnet.nuspec", + "nuget.png" + ] + } + }, + "projectFileDependencyGroups": { + "net8.0": [ + "MQTTnet >= 4.*" + ] + }, + "packageFolders": { + "/root/.nuget/packages/": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "/workspaces/CSharpProjekt/Task/Task.csproj", + "projectName": "Task", + "projectPath": "/workspaces/CSharpProjekt/Task/Task.csproj", + "packagesPath": "/root/.nuget/packages/", + "outputPath": "/workspaces/CSharpProjekt/Task/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.*, )" + } + }, + "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" + } + } + } +} \ No newline at end of file diff --git a/Task/obj/project.nuget.cache b/Task/obj/project.nuget.cache new file mode 100644 index 0000000..4e7ddc7 --- /dev/null +++ b/Task/obj/project.nuget.cache @@ -0,0 +1,10 @@ +{ + "version": 2, + "dgSpecHash": "XnxQkDuwRFU=", + "success": true, + "projectFilePath": "/workspaces/CSharpProjekt/Task/Task.csproj", + "expectedPackageFiles": [ + "/root/.nuget/packages/mqttnet/4.3.7.1207/mqttnet.4.3.7.1207.nupkg.sha512" + ], + "logs": [] +} \ No newline at end of file