97 lines
2.7 KiB
C#
97 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using Thermo.Active.CmsConnectGateway.Builders;
|
|
|
|
namespace Thermo.Active.CmsConnectGateway
|
|
{
|
|
public class GatewayNetworkConfigurationBuilder : iBuilder
|
|
{
|
|
private GatewayNetworkConfiguration config;
|
|
|
|
public GatewayNetworkConfigurationBuilder()
|
|
{
|
|
config = new GatewayNetworkConfiguration();
|
|
}
|
|
|
|
public GatewayNetworkConfigurationBuilder HasDhcp(Boolean useDhcp)
|
|
{
|
|
config.hasDhcp = useDhcp;
|
|
return this;
|
|
}
|
|
|
|
public GatewayNetworkConfigurationBuilder IpAddress(IPAddress ipAddress)
|
|
{
|
|
config.ipAddress = ipAddress;
|
|
return this;
|
|
}
|
|
|
|
public GatewayNetworkConfigurationBuilder NetMaskAddress(IPAddress netMask)
|
|
{
|
|
config.netMaskAddress = netMask;
|
|
return this;
|
|
}
|
|
|
|
public GatewayNetworkConfigurationBuilder DefaultGatewayAddress(IPAddress gateway)
|
|
{
|
|
config.defaultGatewayAddress = gateway;
|
|
return this;
|
|
}
|
|
|
|
public GatewayNetworkConfigurationBuilder DnsAddresses(IEnumerable<IPAddress> dns)
|
|
{
|
|
config.dnsAddresses = dns;
|
|
return this;
|
|
}
|
|
|
|
public GatewayNetworkConfigurationBuilder DnsPrefixes(IEnumerable<string> dnsPrefixes)
|
|
{
|
|
config.dnsPrefixes = dnsPrefixes;
|
|
return this;
|
|
}
|
|
|
|
public GatewayNetworkConfiguration GenerateConfiguration()
|
|
{
|
|
|
|
//If DHCP enabled go out
|
|
if (config.hasDhcp)
|
|
{
|
|
config.ipAddress = null;
|
|
config.netMaskAddress = null;
|
|
config.defaultGatewayAddress = null;
|
|
}
|
|
else
|
|
{
|
|
//Controls not NULL
|
|
CheckNotNull(config.ipAddress, "IpAddress");
|
|
CheckNotNull(config.netMaskAddress, "NetMaskAddress");
|
|
CheckNotNull(config.defaultGatewayAddress, "DefaultGatewayAddress");
|
|
|
|
//Controls address
|
|
CheckIpAddress(config.ipAddress);
|
|
CheckNetmaskAddress(config.netMaskAddress);
|
|
CheckIpAddress(config.defaultGatewayAddress);
|
|
|
|
}
|
|
|
|
//Controls DNS Address
|
|
if (config.dnsAddresses != null)
|
|
{
|
|
foreach (IPAddress addr in config.dnsAddresses)
|
|
CheckIpAddress(addr);
|
|
}
|
|
|
|
//Controls empty spaces
|
|
if (config.dnsPrefixes != null)
|
|
{
|
|
foreach (string str in config.dnsPrefixes)
|
|
CheckNoEmptySpaces(str, "DnsPrefixes");
|
|
}
|
|
|
|
return config;
|
|
}
|
|
|
|
|
|
}
|
|
}
|