-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from IvanValadezCastaneda/master
Two new pages added in the data type and server monitoring section
- Loading branch information
Showing
6 changed files
with
364 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
@page | ||
@model WinCCOAOutsideInfoRepo.Pages.InputTypeValidationModel | ||
@{ | ||
ViewData["Title"] = "Advanced Input Validation in WinCC OA"; | ||
} | ||
|
||
<h1>@ViewData["Title"]</h1> | ||
|
||
<article> | ||
<h2>Introduction to Input Validation</h2> | ||
<p> | ||
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. | ||
</p> | ||
</article> | ||
|
||
<article> | ||
<h2>Implementing Integer Input Validation</h2> | ||
<p> | ||
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. | ||
</p> | ||
<pre><code>// 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; | ||
} | ||
}</code></pre> | ||
<p>Trigger this validation by connecting the input field's event to the function:</p> | ||
<pre><code>// Event Handler for an Integer Input Field | ||
main(mapping event) { | ||
string newText = event["newText"]; | ||
validateIntegerInput(newText, this.refName()); | ||
}</code></pre> | ||
</article> | ||
|
||
<article> | ||
<h2>Validating String Inputs for Alphabetic Characters</h2> | ||
<p> | ||
String inputs often require validation to ensure they contain alphabetic characters only. The following function demonstrates string input validation, excluding numerical digits effectively. | ||
</p> | ||
<pre><code>// 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; | ||
} | ||
}</code></pre> | ||
<p>Invoke this validation in the input field's event handling:</p> | ||
<pre><code>// Event Handler for a String Input Field | ||
main(mapping event) { | ||
string newText = event["newText"]; | ||
validateStringInput(newText, this.refName()); | ||
}</code></pre> | ||
</article> | ||
|
||
<article> | ||
<h2>Handling Validation States with Global Flags</h2> | ||
<p> | ||
A global flag, such as <code>NoSaveAllowed</code>, helps manage the application's state based on input validity. This approach ensures critical operations proceed only with valid inputs across the board. | ||
</p> | ||
</article> | ||
|
||
<article> | ||
<h2>Conclusion</h2> | ||
<p> | ||
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. | ||
</p> | ||
</article> | ||
|
||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 20px; | ||
} | ||
h1 { | ||
color: #4a90e2; | ||
border-bottom: 2px solid #e6e6e6; | ||
padding-bottom: 10px; | ||
} | ||
h3, h4, h5 { | ||
color: #4a90e2; | ||
} | ||
form { | ||
background-color: #f5f7f9; | ||
padding: 20px; | ||
border-radius: 8px; | ||
margin-top: 20px; | ||
margin-bottom: 20px; | ||
} | ||
label { | ||
display: block; | ||
margin-top: 10px; | ||
color: #4a90e2; | ||
} | ||
input[type="text"] { | ||
padding: 8px 12px; | ||
border-radius: 4px; | ||
border: 1px solid #ccc; | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
input[type="button"] { | ||
margin-top: 20px; | ||
background-color: #4a90e2; | ||
color: white; | ||
padding: 10px 15px; | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
transition: background-color 0.3s; | ||
} | ||
input[type="button"]:hover { | ||
background-color: #357ab7; | ||
} | ||
pre { | ||
background-color: #e6e6e6; | ||
padding: 10px; | ||
border-radius: 4px; | ||
} | ||
.warning { | ||
background-color: #ffcccb; | ||
padding: 10px; | ||
} | ||
.note { | ||
background-color: #e6e6e6; | ||
padding: 10px; | ||
} | ||
.info { | ||
background-color: #d1ecf1; | ||
padding: 10px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace WinCCOAOutsideInfoRepo.Pages | ||
{ | ||
public class InputTypeValidationModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
@page | ||
@model WinCCOAOutsideInfoRepo.Pages.SystemInternalStorageModel | ||
@{ | ||
ViewData["Title"] = "System Resources Monitoring"; | ||
} | ||
|
||
<h1>System Resources Monitoring</h1> | ||
|
||
<section class="resource-monitoring"> | ||
<article> | ||
<h2>Implementation Details</h2> | ||
<p> | ||
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. | ||
</p> | ||
<p class="warning"> | ||
<strong>Important:</strong> 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. | ||
</p> | ||
<pre><code> | ||
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 + " %"); | ||
} | ||
</code></pre> | ||
</article> | ||
<article> | ||
<h2>Considerations for Redundant and Distributed Systems</h2> | ||
<p> | ||
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. | ||
</p> | ||
<p class="note"> | ||
<strong>Note:</strong> The approach outlined is primarily suited for redundant systems but can be adapted for distributed systems with appropriate modifications to the server identification logic. | ||
</p> | ||
</article> | ||
|
||
<article> | ||
<h2>Caveats and Additional Information</h2> | ||
<p class="info"> | ||
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. | ||
</p> | ||
</article> | ||
|
||
</section> | ||
|
||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 20px; | ||
} | ||
h1 { | ||
color: #4a90e2; | ||
border-bottom: 2px solid #e6e6e6; | ||
padding-bottom: 10px; | ||
} | ||
h3, h4, h5 { | ||
color: #4a90e2; | ||
} | ||
form { | ||
background-color: #f5f7f9; | ||
padding: 20px; | ||
border-radius: 8px; | ||
margin-top: 20px; | ||
margin-bottom: 20px; | ||
} | ||
label { | ||
display: block; | ||
margin-top: 10px; | ||
color: #4a90e2; | ||
} | ||
input[type="text"] { | ||
padding: 8px 12px; | ||
border-radius: 4px; | ||
border: 1px solid #ccc; | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
input[type="button"] { | ||
margin-top: 20px; | ||
background-color: #4a90e2; | ||
color: white; | ||
padding: 10px 15px; | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
transition: background-color 0.3s; | ||
} | ||
input[type="button"]:hover { | ||
background-color: #357ab7; | ||
} | ||
pre { | ||
background-color: #e6e6e6; | ||
padding: 10px; | ||
border-radius: 4px; | ||
} | ||
.warning | ||
{ | ||
background-color: #ffcccb; padding: 10px; | ||
} | ||
.note | ||
{ | ||
background-color: #e6e6e6; padding: 10px; | ||
} | ||
.info | ||
{ | ||
background-color: #d1ecf1; padding: 10px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace WinCCOAOutsideInfoRepo.Pages | ||
{ | ||
public class SystemInternalStorageModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
} | ||
} | ||
} |