76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Thermo.Active.CmsConnectGateway.Builders
|
|
{
|
|
public abstract class iBuilder
|
|
{
|
|
//------------------------------------ To Implement ------------------------------------
|
|
#region ToImplement_Functions
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
//------------------------------------ Controls ------------------------------------
|
|
#region Control_Functions
|
|
|
|
internal void CheckIpAddress(IPAddress ipAddress)
|
|
{
|
|
byte[] byteIP = ipAddress.GetAddressBytes();
|
|
|
|
//IP must be NE 0.0.0.0
|
|
if (byteIP[0] == 0 && byteIP[1] == 0 && byteIP[2] == 0 && byteIP[3] == 0)
|
|
throw new ArgumentException("IP must be different from 0.0.0.0");
|
|
|
|
}
|
|
|
|
internal void CheckNetmaskAddress(IPAddress netmaskAddress)
|
|
{
|
|
byte[] byteIP = netmaskAddress.GetAddressBytes();
|
|
|
|
//NETMASK must be NE 0.0.0.0
|
|
if (byteIP[0] == 0 && byteIP[1] == 0 && byteIP[2] == 0 && byteIP[3] == 0)
|
|
throw new ArgumentException("NETMASK must be different from 0.0.0.0");
|
|
|
|
//NETMASK first number must be NE 0
|
|
if (byteIP[0] == 0)
|
|
throw new ArgumentException("NETMASK starting address must be different from 0. Eg: xx.0.0.0 ");
|
|
|
|
}
|
|
|
|
internal void CheckNotNull(object objToCheck, string paramName)
|
|
{
|
|
if (objToCheck == null)
|
|
throw new FormatException("BAD FORMAT - param \"" + paramName + "\" is mandatory");
|
|
|
|
}
|
|
|
|
internal void CheckNoEmptySpaces(string strToCheck, string paramName)
|
|
{
|
|
if (strToCheck.Contains(" "))
|
|
throw new FormatException("BAD FORMAT - param \"" + paramName + "\" must be without empty spaces");
|
|
|
|
}
|
|
|
|
|
|
private bool EvaluateIPV4(string stringValue, out IPAddress address)
|
|
{
|
|
Regex rgx = new Regex(@"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
|
|
|
|
if (rgx.IsMatch(stringValue))
|
|
{
|
|
IPAddress.TryParse(stringValue, out address);
|
|
return true;
|
|
}
|
|
|
|
address = new IPAddress(0);
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|