|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IPFiltering.Configuration
{
public static class FilterFactory
{
/// <summary>
/// Creates the IPFilter
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <returns></returns>
public static IPFilter Create(FilterConfiguration configuration)
{
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}
IList<IPFilterItem> items = configuration.Filters.Select(f=> Create(f)).ToArray();
return new IPFilter(configuration.Name, items, configuration.DefaultBehavior);
}
/// <summary>
/// Creates a filter item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns></returns>
public static IPFilterItem Create(FilterConfigurationItem item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
if (item.FilterType == IPFilterType.NoMatch)
{
throw new ArgumentException("The item has an invalid FilterType : '" +
item.FilterType.ToString() + "'", "item");
}
if (string.IsNullOrEmpty(item.Hosts))
{
throw new ArgumentException("The item does not have any hosts set.", "item");
}
string[] hosts = item.Hosts.Split(',');
IList<IPRange> ipRanges = hosts.Select((s) => IPRange.Parse(s)).ToArray();
return new IPFilterItem(ipRanges, item.FilterType);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.