using System; using System.Diagnostics.Contracts; using System.Globalization; namespace Inspectron.HawkEye.RTSP.Messages { /// /// Describe a couple of port used to transfer video and command. /// public class PortCouple { /// /// Gets or sets the first port number. /// /// The first port. public int First { get; set; } /// /// Gets or sets the second port number. /// /// If not present the value is 0 /// The second port. public int Second { get; set; } /// /// Initializes a new instance of the class. /// public PortCouple() { } /// /// Initializes a new instance of the class. /// /// The first port. public PortCouple(int first) { First = first; Second = 0; } /// /// Initializes a new instance of the class. /// /// The first port. /// The second port. public PortCouple(int first, int second) { First = first; Second = second; } /// /// Gets a value indicating whether this instance has second port. /// /// /// true if this instance has second port; otherwise, false. /// public bool IsSecondPortPresent { get { return Second != 0; } } /// /// Parses the int values of port. /// /// A string value. /// The port couple public static PortCouple Parse(string stringValue) { if (stringValue == null) throw new ArgumentNullException("stringValue"); Contract.Requires(!string.IsNullOrEmpty(stringValue)); string[] values = stringValue.Split('-'); int tempValue; int.TryParse(values[0], out tempValue); PortCouple result = new PortCouple(tempValue); tempValue = 0; if (values.Length > 1) int.TryParse(values[1], out tempValue); result.Second = tempValue; return result; } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { if (IsSecondPortPresent) return First.ToString(CultureInfo.InvariantCulture) + "-" + Second.ToString(CultureInfo.InvariantCulture); else return First.ToString(CultureInfo.InvariantCulture); } } }