|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Web; |
|
using System.ComponentModel.DataAnnotations; |
|
|
|
namespace PcnWeb.Models |
|
{ |
|
public class IPAddress |
|
{ |
|
public IPAddress() |
|
{ |
|
this.UPSs = new List<UPS>(); |
|
} |
|
public virtual ICollection<UPS> UPSs { get; set; } |
|
|
|
[Key] |
|
public int ipAddressRecId { get; set; } |
|
|
|
[Required] |
|
[NotMapped] |
|
[RegularExpression(@"(?:(?: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]?)|DHCP", ErrorMessage = "IP Address must be in the form of four octets 0-255: 255.255.255.255 or DHCP")] |
|
public string IP_Address |
|
{ |
|
get |
|
{ |
|
if (ipOctet1 == null | ipOctet2 == null | ipOctet3 == null | ipOctet4 == null) |
|
return "DHCP"; |
|
return ipOctet1 + "." + ipOctet2 + "." + ipOctet3 + "." + ipOctet4; |
|
} |
|
set |
|
{ |
|
if (value == "DHCP") |
|
{ |
|
ipOctet1 = null; |
|
ipOctet2 = null; |
|
ipOctet3 = null; |
|
ipOctet4 = null; |
|
return; |
|
} |
|
|
|
//@todo Parseing could throw a number of errors: ArgumentNullException, FormatException, Exception |
|
byte[] temp = System.Net.IPAddress.Parse(value).GetAddressBytes(); |
|
ipOctet1 = temp[0]; |
|
ipOctet2 = temp[1]; |
|
ipOctet3 = temp[2]; |
|
ipOctet4 = temp[3]; |
|
} |
|
} |
|
[NotMapped] //@todo check if this is needed. Don't want an extra database entry. |
|
public long ipTotal |
|
{ |
|
get |
|
{ |
|
if (ipOctet1 == null || ipOctet2 == null || ipOctet3 == null || ipOctet4 == null) |
|
return 0; |
|
//(first octet * 2^24) + (second octet * 2^16) + (third octet * 2^8) + (fourth octet) |
|
return ((long)ipOctet1 * 16777216) + ((long)ipOctet2 * 65536) + ((long)ipOctet3 * 256) + (long)ipOctet4; |
|
} |
|
} |
|
|
|
public Nullable<int> ipOctet1 { get; set; } |
|
public Nullable<int> ipOctet2 { get; set; } |
|
public Nullable<int> ipOctet3 { get; set; } |
|
public Nullable<int> ipOctet4 { get; set; } |
|
|
|
|
|
[Required] |
|
[NotMapped] |
|
[RegularExpression(@"(?:(?: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]?)|DHCP", ErrorMessage = "Subnet Mask must be in the form of four octets 0-255: 255.255.255.255 or DHCP")] |
|
public string Subnet_Mask |
|
{ |
|
get |
|
{ |
|
if (smOctet1 == null || smOctet2 == null || smOctet3 == null || smOctet4 == null) |
|
return "DHCP"; |
|
return smOctet1 + "." + smOctet2 + "." + smOctet3 + "." + smOctet4; |
|
} |
|
set |
|
{ |
|
if (value == "DHCP") |
|
{ |
|
smOctet1 = null; |
|
smOctet2 = null; |
|
smOctet3 = null; |
|
smOctet4 = null; |
|
return; |
|
} |
|
|
|
//@todo Parseing could throw a number of errors: ArgumentNullException, FormatException, Exception |
|
byte[] temp = System.Net.IPAddress.Parse(value).GetAddressBytes(); |
|
smOctet1 = temp[0]; |
|
smOctet2 = temp[1]; |
|
smOctet3 = temp[2]; |
|
smOctet4 = temp[3]; |
|
} |
|
} |
|
[NotMapped] //@todo check if this is needed. Don't want an extra database entry. |
|
public long smTotal |
|
{ |
|
get |
|
{ |
|
if (smOctet1 == null || smOctet2 == null || smOctet3 == null || smOctet4 == null) |
|
return 0; |
|
//(first octet * 2^24) + (second octet * 2^16) + (third octet * 2^8) + (fourth octet) |
|
return ((long)smOctet1 * 16777216) + ((long)smOctet2 * 65536) + ((long)smOctet3 * 256) + (long)smOctet4; |
|
} |
|
} |
|
|
|
public Nullable<int> smOctet1 { get; set; } |
|
public Nullable<int> smOctet2 { get; set; } |
|
public Nullable<int> smOctet3 { get; set; } |
|
public Nullable<int> smOctet4 { get; set; } |
|
} |
|
} |