94 lines
2.5 KiB
C#
94 lines
2.5 KiB
C#
using Step.CmsConnectGateway.Builders;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Step.CmsConnectGateway
|
|
{
|
|
public class GatewayProxyConfigurationBuilder : iBuilder
|
|
{
|
|
private GatewayProxyConfiguration config;
|
|
|
|
public GatewayProxyConfigurationBuilder()
|
|
{
|
|
config = new GatewayProxyConfiguration();
|
|
}
|
|
|
|
public GatewayProxyConfigurationBuilder HasProxy(Boolean useProxy)
|
|
{
|
|
config.hasProxy = useProxy;
|
|
return this;
|
|
}
|
|
|
|
public GatewayProxyConfigurationBuilder Address(string address)
|
|
{
|
|
config.address = address;
|
|
return this;
|
|
}
|
|
|
|
public GatewayProxyConfigurationBuilder Address(IPAddress address)
|
|
{
|
|
CheckIpAddress(address);
|
|
config.address = address.ToString();
|
|
return this;
|
|
}
|
|
|
|
public GatewayProxyConfigurationBuilder Port(uint port)
|
|
{
|
|
config.port = port;
|
|
return this;
|
|
}
|
|
|
|
public GatewayProxyConfigurationBuilder Username(string username)
|
|
{
|
|
config.username = username;
|
|
return this;
|
|
}
|
|
|
|
public GatewayProxyConfigurationBuilder Password(string password)
|
|
{
|
|
config.password = password;
|
|
return this;
|
|
}
|
|
|
|
public GatewayProxyConfigurationBuilder NoproxyAddresses(IEnumerable<string> addresses)
|
|
{
|
|
config.noproxyAddresses = addresses;
|
|
return this;
|
|
}
|
|
|
|
public GatewayProxyConfiguration GenerateConfiguration()
|
|
{
|
|
|
|
//If DHCP enabled go out
|
|
if (!config.hasProxy)
|
|
{
|
|
config.address = null;
|
|
config.port = 0;
|
|
config.username = null;
|
|
config.password = null;
|
|
config.noproxyAddresses = null;
|
|
return config;
|
|
}
|
|
|
|
//Controls not NULL
|
|
CheckNotNull(config.address, "Address");
|
|
|
|
//Controls empty spaces
|
|
CheckNoEmptySpaces(config.address, "Address");
|
|
if(config.username != null)
|
|
CheckNoEmptySpaces(config.username, "Username");
|
|
if (config.password != null)
|
|
CheckNoEmptySpaces(config.password, "Password");
|
|
foreach (string str in config.noproxyAddresses)
|
|
CheckNoEmptySpaces(str, "NoproxyAddresses");
|
|
|
|
return config;
|
|
}
|
|
|
|
}
|
|
}
|