Skip to content

Commit

Permalink
Merge pull request #6 from IvanValadezCastaneda/master
Browse files Browse the repository at this point in the history
Two new pages added in the data type and server monitoring section
  • Loading branch information
IvanValadezCastaneda authored Apr 12, 2024
2 parents 8e4dbe7 + db2a17e commit 0e82785
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,23 @@
</div>
</div>
</div>
<div class="col-md-3 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">System Resources Monitoring</h5>
<p class="card-text">Check and Display the Internal Storage of the System in which the Application is Running</p>
<a asp-area="" asp-page="/SystemInternalStorage" class="btn btn-primary">Learn More</a>
</div>
</div>
</div>
<div class="col-md-3 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Validate the Data Type of Input Objects</h5>
<p class="card-text">With this code you can check the Data Type of an Input and set parameters to characters</p>
<a asp-area="" asp-page="/InputTypeValidation" class="btn btn-primary">Learn More</a>
</div>
</div>
</div>
</div>
</div>
167 changes: 167 additions & 0 deletions Pages/InputTypeValidation.cshtml
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 &lt; newText.length(); i++) {
if (newText[i] &lt; '0' || newText[i] &gt; '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 &lt; newText.length(); i++) {
if ('0' &lt;= newText[i] && newText[i] &lt;= '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>
12 changes: 12 additions & 0 deletions Pages/InputTypeValidation.cshtml.cs
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()
{
}
}
}
2 changes: 2 additions & 0 deletions Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<a class="dropdown-item" asp-area="" asp-page="/TimeConversionJSON">Time Conversion from JSON Trick</a>
<a class="dropdown-item" asp-area="" asp-page="/GetterandSetterProperties">Getters and Setters for Properties in Panels</a>
<a class="dropdown-item" asp-area="" asp-page="/GetDistandReduSystems">Get Redundant and Distributed System Status</a>
<a class="dropdown-item" asp-area="" asp-page="/SystemInternalStorage">System Resources Monitoring</a>
<a class="dropdown-item" asp-area="" asp-page="/InputTypeValidation">Validate the Data Type of Inputs</a>
</div>
</li>
<a class="nav-link text-dark" id="categoriesDropdown" role="button" asp-page="/MiscFacts">
Expand Down
153 changes: 153 additions & 0 deletions Pages/SystemInternalStorage.cshtml
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>
12 changes: 12 additions & 0 deletions Pages/SystemInternalStorage.cshtml.cs
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()
{
}
}
}

0 comments on commit 0e82785

Please sign in to comment.