Skip to content

Instantly share code, notes, and snippets.

@epetrie
Created April 27, 2012 16:18
Show Gist options
  • Save epetrie/2510520 to your computer and use it in GitHub Desktop.
Save epetrie/2510520 to your computer and use it in GitHub Desktop.
String Enum Replacement
/// <summary>
/// Represents all Service types.
/// </summary>
public class ServiceType
{
#region Values
/// <remarks/>
public static readonly ServiceType AlarmArrayConfiguration = "urn:schemas-pelco-com:service:AlarmArrayConfiguration:1";
/// <remarks/>
public static readonly ServiceType AudioInput = "urn:schemas-pelco-com:service:AudioInput:1";
/// <remarks/>
public static readonly ServiceType AudioInputRtsp = "urn:schemas-pelco-com:service:AudioInputRTSP:1";
/// <remarks/>
public static readonly ServiceType AudioOutput = "urn:schemas-pelco-com:service:AudioOutput:1";
/// <remarks/>
public static readonly ServiceType CameraConfiguration = "urn:schemas-pelco-com:service:CameraConfiguration:1";
/// <remarks/>
public static readonly ServiceType DeviceCapability = "http://www.pelco.com/api/DeviceCapability/1";
/// <remarks/>
public static readonly ServiceType DeviceRegistry = "urn:schemas-pelco-com:service:DeviceRegistry:1";
/// <remarks/>
public static readonly ServiceType ImagingConfiguration = "urn:schemas-pelco-com:service:ImagingConfiguration:1";
/// <remarks/>
public static readonly ServiceType LensControl = "urn:schemas-pelco-com:service:LensControl:1";
/// <remarks/>
public static readonly ServiceType MetaData = "urn:schemas-pelco-com:service:MetaData:1";
/// <remarks/>
public static readonly ServiceType MonitorConfiguration = "urn:schemas-pelco-com:service:MonitorConfiguration:1";
/// <remarks/>
public static readonly ServiceType MotionDetection = "urn:schemas-pelco-com:service:MotionDetection:1";
/// <remarks/>
public static readonly ServiceType PelcoConfiguration = "urn:schemas-pelco-com:service:PelcoConfiguration:1";
/// <remarks/>
public static readonly ServiceType PositioningControl = "urn:schemas-pelco-com:service:PositioningControl:1";
/// <remarks/>
public static readonly ServiceType PresetControl = "urn:schemas-pelco-com:service:PresetControl:2";
/// <remarks/>
public static readonly ServiceType RelayArrayConfiguration = "urn:schemas-pelco-com:service:RelayArrayConfiguration:1";
/// <remarks/>
public static readonly ServiceType ScriptControl = "urn:schemas-pelco-com:service:ScriptControl:1";
/// <remarks/>
public static readonly ServiceType SoftwareUpdate = "urn:schemas-pelco-com:service:SoftwareUpdate:1";
/// <remarks/>
public static readonly ServiceType StreamConfiguration = "urn:schemas-pelco-com:service:StreamConfiguration:1";
/// <remarks/>
public static readonly ServiceType StreamControl = "urn:schemas-pelco-com:service:StreamControl:1";
/// <remarks/>
public static readonly ServiceType StreamDiscovery = "urn:schemas-pelco-com:service:StreamDiscovery:1";
/// <remarks/>
public static readonly ServiceType SystemManagerLocator = "urn:schemas-pelco-com:service:SystemManagerLocator:1";
/// <remarks/>
public static readonly ServiceType UserAndRole = "urn:schemas-pelco-com:service:UserAndRole:1";
/// <remarks/>
public static readonly ServiceType VideoInput = "urn:schemas-pelco-com:service:VideoInput:1";
/// <remarks/>
public static readonly ServiceType VideoOutput = "urn:schemas-pelco-com:service:VideoOutput:1";
// services which are currently 'protected' status:
//public static readonly ServiceType DiagnosticReporting = "urn:schemas-pelco-com:service:DiagnosticReporting:1";
//public static readonly ServiceType EncoderConfiguration = "urn:schemas-pelco-com:service:EncoderConfiguration:1";
//public static readonly ServiceType DecoderConfiguration = "urn:schemas-pelco-com:service:DecoderConfiguration:1";
//public static readonly ServiceType NVRRecordingSchedule = "urn:schemas-pelco-com:service:RecordingSchedule:1";//1.3 NVR
//public static readonly ServiceType NVRRecordingSchedule2 = "urn:schemas-pelco-com:service:RecordingSchedule:2";//1.4 NVR and NSM
//public static readonly ServiceType DVRRecordingSchedule = "urn:schemas-pelco-com:service:RecordingSchedule:NVR";
//public static readonly ServiceType NVRConfig = "urn:schemas-pelco-com:service:NVRConfiguration:1";
//public static readonly ServiceType DVRNVRConfig = "urn:schemas-pelco-com:service:NVRConfiguration:NVR";
//public static readonly ServiceType DVR5100Registration = "urn:schemas-pelco-com:service:DVR5100Registration:1";
//public static readonly ServiceType VideoAnalytics = "urn:schemas-pelco-com:service:VideoAnalytics:1";
//public static readonly ServiceType VideoAnalytics2 = "urn:schemas-pelco-com:service:VideoAnalytics:2";
#endregion
#region Properties
/// <summary>
/// Gets the value.
/// </summary>
public string Value { get; private set; }
#endregion
#region Operator Overloads
/// <summary>
/// Performs an implicit conversion from <see cref="PelcoAPI.Integration.Common.ServiceType"/> to <see cref="System.String"/>.
/// </summary>
/// <param name="s">The service type.</param>
/// <returns>
/// The result of the conversion.
/// </returns>
public static implicit operator string(ServiceType s)
{
return s.Value;
}
/// <summary>
/// Performs an implicit conversion from <see cref="System.String"/> to <see cref="PelcoAPI.Integration.Common.ServiceType"/>.
/// </summary>
/// <param name="s">The string.</param>
/// <returns>
/// The result of the conversion.
/// </returns>
public static implicit operator ServiceType(string s)
{
return new ServiceType() { Value = s };
}
/// <summary>
/// Implements the operator ==.
/// </summary>
/// <param name="t1">The t1.</param>
/// <param name="t2">The t2.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator ==(ServiceType t1, ServiceType t2)
{
// If both are null, or both are same instance, return true.
if (ReferenceEquals(t1, t2))
{
return true;
}
// If one is null, but not both, return false.
if (((object)t1 == null) || ((object)t2 == null))
{
return false;
}
return t1.Value == t2.Value;
}
/// <summary>
/// Implements the operator !=.
/// </summary>
/// <param name="t1">The t1.</param>
/// <param name="t2">The t2.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator !=(ServiceType t1, ServiceType t2)
{
return !(t1 == t2);
}
#endregion
#region Overrides
/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
/// <exception cref="T:System.NullReferenceException">
/// The <paramref name="obj"/> parameter is null.
/// </exception>
public override bool Equals(object obj)
{
if (obj is ServiceType)
return this.Value.Equals(((ServiceType)obj).Value);
if (obj is String)
return this.Value.Equals((string)obj);
throw new ArgumentException("object is not a ServiceType or String.");
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
return this.Value.GetHashCode();
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString()
{
return this.Value;
}
#endregion
#region Helpers
/// <summary>
/// Gets the relative service type from the serviceType.
/// </summary>
/// <param name="serviceType">Type of the service.</param>
/// <returns></returns>
public static ServiceType GetRelativeServiceType(ServiceType serviceType)
{
try
{
var str = serviceType.Value;
var filters = new List<string>();
if (str.Contains("http://www.pelco.com/api/"))
filters.AddRange(new string[] {"http://www.pelco.com/api/", "/1"});
else
filters.AddRange(new string[] {"urn:schemas-pelco-com:service:", str.Contains(":2") ? ":2" : ":1"});
string[] split = str.Split(filters.ToArray(), StringSplitOptions.RemoveEmptyEntries);
if (split.Length > 0)
return split[0];
}
catch (ArgumentException)
{
}
return null;
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment