From 03bc9cd3824260e4cbfe2e9ae18dd571ad75eeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Valadez=20Casta=C3=B1eda?= Date: Tue, 9 Apr 2024 09:34:34 -0600 Subject: [PATCH 1/4] Server Details Pages Added --- Pages/Index.cshtml | 9 ++++ Pages/Shared/_Layout.cshtml | 1 + Pages/SystemInternalStorage.cshtml | 65 +++++++++++++++++++++++++++ Pages/SystemInternalStorage.cshtml.cs | 12 +++++ 4 files changed, 87 insertions(+) create mode 100644 Pages/SystemInternalStorage.cshtml create mode 100644 Pages/SystemInternalStorage.cshtml.cs diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index 538736d..47b985a 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -243,5 +243,14 @@ +
+
+
+
System Internal Storage
+

Check and Display the Internal Storage of the System in which the Application is Running

+ Learn More +
+
+
diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index 73630fa..d3bd1b2 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -52,6 +52,7 @@ Time Conversion from JSON Trick Getters and Setters for Properties in Panels Get Redundant and Distributed System Status + System Internal Storage diff --git a/Pages/SystemInternalStorage.cshtml b/Pages/SystemInternalStorage.cshtml new file mode 100644 index 0000000..5c5820e --- /dev/null +++ b/Pages/SystemInternalStorage.cshtml @@ -0,0 +1,65 @@ +@page +@model WinCCOAOutsideInfoRepo.Pages.SystemInternalStorageModel +@{ + ViewData["Title"] = "System Internal Storage"; +} + + \ No newline at end of file diff --git a/Pages/SystemInternalStorage.cshtml.cs b/Pages/SystemInternalStorage.cshtml.cs new file mode 100644 index 0000000..3266388 --- /dev/null +++ b/Pages/SystemInternalStorage.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WinCCOAOutsideInfoRepo.Pages +{ + public class SystemInternalStorageModel : PageModel + { + public void OnGet() + { + } + } +} From f8e4159c3a56ffb759e2bea4c9152ea54964333b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Valadez=20Casta=C3=B1eda?= Date: Tue, 9 Apr 2024 10:04:34 -0600 Subject: [PATCH 2/4] System Monitoring Page Complete --- Pages/Index.cshtml | 2 +- Pages/Shared/_Layout.cshtml | 2 +- Pages/SystemInternalStorage.cshtml | 90 +++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index 47b985a..a35e4d2 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -246,7 +246,7 @@
diff --git a/Pages/SystemInternalStorage.cshtml b/Pages/SystemInternalStorage.cshtml index 5c5820e..d04d385 100644 --- a/Pages/SystemInternalStorage.cshtml +++ b/Pages/SystemInternalStorage.cshtml @@ -1,9 +1,82 @@ @page @model WinCCOAOutsideInfoRepo.Pages.SystemInternalStorageModel @{ - ViewData["Title"] = "System Internal Storage"; + ViewData["Title"] = "System Resources Monitoring"; } +

System Resources Monitoring

+ +
+
+

Implementation Details

+

+ The following code snippet illustrates the approach to querying the system for HDD capacity and RAM usage. It accounts for redundant servers by accepting the server number as input and adjusting the data point references accordingly. +

+

+ Important: It's imperative to handle internal data points with caution. Any unintended modification might lead to critical issues, potentially requiring a system reinstallation. Ensure that you are familiar with the data points you intend to monitor. Note that the HDD space monitored is specific to the drive where the project is installed, and the available RAM is just a snapshot of the current usage. +

+

+int HDDCapacityInt;
+int RamMemoryInt;
+int ServerNum = $iNumber;
+
+void initialize()
+{
+    ...
+    if (Server == nullptr){
+        DebugN("Failed to get server instance for:", ReceivedDollarParam);
+    }
+    string SystemNameServer = getSystemName();
+    string HDD;
+    string RAM;
+    if(ServerNum != 2)
+    {
+        HDD = "_ArchivDisk.AvailPerc";
+        RAM = "_MemoryCheck.FreePerc";
+    }
+    else
+    {
+        HDD = "_ArchivDisk_2.AvailPerc";
+        RAM = "_MemoryCheck_2.FreePerc";
+    }
+    dpConnect("getHDDCapacity",SystemNameServer + HDD);
+    dpConnect("getMemory", SystemNameServer + RAM);
+}
+
+void getHDDCapacity(string dpe, int percentage)
+{
+    int ProxyCapacityPercentage;
+    dpGet(dpe,ProxyCapacityPercentage);
+    HDDCapacity.setTxt((string)ProxyCapacityPercentage + " %");
+}
+
+void getMemory(string dpe, int percentage)
+{
+    int ProxyRamPercentage;
+    dpGet(dpe,ProxyRamPercentage);
+    RamMemory.setTxt((string)ProxyRamPercentage + " %");
+}
+        
+
+
+

Considerations for Redundant and Distributed Systems

+

+ The code differentiates between servers in a redundant setup by adjusting the data point strings based on the server number. This flexibility is crucial for systems with multiple servers, enabling targeted resource monitoring across different machine instances. +

+

+ Note: The approach outlined is primarily suited for redundant systems but can be adapted for distributed systems with appropriate modifications to the server identification logic. +

+
+ +
+

Caveats and Additional Information

+

+ For comprehensive monitoring, consider exploring additional system metrics and incorporating external tools or scripts that can provide a broader overview of system health and resource utilization. +

+
+ +
+ \ No newline at end of file From 06e70e6430b94e4c1ac09b61524715707ce1d5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Valadez=20Casta=C3=B1eda?= Date: Thu, 11 Apr 2024 10:29:04 -0600 Subject: [PATCH 3/4] Input Type Validation Added --- Pages/Index.cshtml | 9 ++++ Pages/InputTypeValidation.cshtml | 80 +++++++++++++++++++++++++++++ Pages/InputTypeValidation.cshtml.cs | 12 +++++ Pages/Shared/_Layout.cshtml | 1 + 4 files changed, 102 insertions(+) create mode 100644 Pages/InputTypeValidation.cshtml create mode 100644 Pages/InputTypeValidation.cshtml.cs diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index a35e4d2..e6d9e1c 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -252,5 +252,14 @@
+
+ +
diff --git a/Pages/InputTypeValidation.cshtml b/Pages/InputTypeValidation.cshtml new file mode 100644 index 0000000..c87154f --- /dev/null +++ b/Pages/InputTypeValidation.cshtml @@ -0,0 +1,80 @@ +@page +@model WinCCOAOutsideInfoRepo.Pages.InputTypeValidationModel +@{ +} + + \ No newline at end of file diff --git a/Pages/InputTypeValidation.cshtml.cs b/Pages/InputTypeValidation.cshtml.cs new file mode 100644 index 0000000..e712011 --- /dev/null +++ b/Pages/InputTypeValidation.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WinCCOAOutsideInfoRepo.Pages +{ + public class InputTypeValidationModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index 67e1cc6..4d4f177 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -53,6 +53,7 @@ Getters and Setters for Properties in Panels Get Redundant and Distributed System Status System Resources Monitoring + Validate the Data Type of Inputs From db2a17e081d4a564f6fe469e672cd172a9f50c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Valadez=20Casta=C3=B1eda?= Date: Thu, 11 Apr 2024 11:36:16 -0600 Subject: [PATCH 4/4] Input Type Validation Added --- Pages/InputTypeValidation.cshtml | 87 ++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/Pages/InputTypeValidation.cshtml b/Pages/InputTypeValidation.cshtml index c87154f..8d2f6ab 100644 --- a/Pages/InputTypeValidation.cshtml +++ b/Pages/InputTypeValidation.cshtml @@ -1,8 +1,95 @@ @page @model WinCCOAOutsideInfoRepo.Pages.InputTypeValidationModel @{ + ViewData["Title"] = "Advanced Input Validation in WinCC OA"; } +

@ViewData["Title"]

+ +
+

Introduction to Input Validation

+

+ Input validation is a cornerstone of robust application development in WinCC OA, ensuring data integrity and system stability. This section details implementing input validation mechanisms that distinguish between integer and string inputs, enhancing user experience and system safety. +

+
+ +
+

Implementing Integer Input Validation

+

+ Integer input validation ensures the acceptance of numerical values only. The following example illustrates a method to validate integer inputs, verifying each character against numeric criteria. This method should reside within the event handler of the panel, triggered upon user interaction. +

+
// Integer Input Validation Function
+void validateIntegerInput(string newText, string objectName) {
+    bool isValid = true;
+    for (int i = 0; i < newText.length(); i++) {
+        if (newText[i] < '0' || newText[i] > '9') {
+            isValid = false;
+            break;
+        }
+    }
+
+    if (!isValid) {
+        setValue(objectName, "backCol", "BackgroundRed"); // Error state
+        NoSaveAllowed = TRUE;
+    } else {
+        setValue(objectName, "backCol", "BackgroundGreen"); // Normal state
+        NoSaveAllowed = FALSE;
+    }
+}
+

Trigger this validation by connecting the input field's event to the function:

+
// Event Handler for an Integer Input Field
+main(mapping event) {
+    string newText = event["newText"];
+    validateIntegerInput(newText, this.refName());
+}
+
+ +
+

Validating String Inputs for Alphabetic Characters

+

+ String inputs often require validation to ensure they contain alphabetic characters only. The following function demonstrates string input validation, excluding numerical digits effectively. +

+
// String Input Validation Function
+void validateStringInput(string newText, string objectName) {
+    bool hasInvalidChar = false;
+    // Validate against numeric characters
+    for (int i = 0; i < newText.length(); i++) {
+        if ('0' <= newText[i] && newText[i] <= '9') {
+            hasInvalidChar = true;
+            break;
+        }
+    }
+
+    if (hasInvalidChar) {
+        setValue(objectName, "backCol", "BackgroundRed"); // Error state
+        NoSaveAllowed = TRUE;
+    } else {
+        setValue(objectName, "backCol", "BackgroundGreen"); // Normal state
+        NoSaveAllowed = FALSE;
+    }
+}
+

Invoke this validation in the input field's event handling:

+
// Event Handler for a String Input Field
+main(mapping event) {
+    string newText = event["newText"];
+    validateStringInput(newText, this.refName());
+}
+
+ +
+

Handling Validation States with Global Flags

+

+ A global flag, such as NoSaveAllowed, helps manage the application's state based on input validity. This approach ensures critical operations proceed only with valid inputs across the board. +

+
+ +
+

Conclusion

+

+ Through these examples, we've outlined how to effectively implement and manage input validation within WinCC OA panels. Remember, the key to successful input validation is integrating these checks seamlessly into your panel's event handling, ensuring data integrity and enhancing user experience. +

+
+