using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SCJMapper_V2.SC { /// /// Defines a single activation mode /// public class ActivationMode : ICloneable { private const string c_DefaultActModeName = "Use Profile"; #region Static parts /// /// The default ActivationMode /// static public ActivationMode Default = new ActivationMode( c_DefaultActModeName ); /// /// Returns true if the given name matches the default name /// /// Name to test /// True if the name matches the default name static public bool IsDefault( string activationName ) { return ( activationName == Default.Name ); } #endregion /// /// The name of the ActivationMode /// public string Name { get; set; } /// /// Number of 'multitaps' defined (1..) /// public int MultiTap { get; set; } /// /// Clone this object /// /// A deep Clone of this object public object Clone( ) { var am = (ActivationMode)this.MemberwiseClone(); // more objects to deep copy return am; } /// /// cTor: empty constructor /// public ActivationMode( ) { this.Name = Default.Name; this.MultiTap = Default.MultiTap; } /// /// cTor: copy constructor /// /// public ActivationMode( ActivationMode other ) { this.Name = other.Name; this.MultiTap = other.MultiTap; } /// /// cTor: with init arguments, try to find the multiTap from the Instance list /// /// The Name public ActivationMode( string name ) { Name = name; // if the name is default - multitap is valid else it should be 0 and is given by the mode list if ( Name == c_DefaultActModeName ) { MultiTap = 1; } else { // try to get the one from the list (if the list is available..) try { MultiTap = ActivationModes.Instance.MultiTapFor( Name ); } catch { // not in list - set to 1 MultiTap = 1; } } } /// /// cTor: with init arguments /// /// The Name /// The multiTap number public ActivationMode( string name, int mTaps ) { Name = name; MultiTap = mTaps; } /// /// Returns true if multiTap is more than 1 /// public bool IsDoubleTap { get { return ( MultiTap > 1 ); } } public static bool operator ==( ActivationMode a, ActivationMode b ) { // If both are null, or both are same instance, return true. if ( System.Object.ReferenceEquals( a, b ) ) { return true; } // If one is null, but not both, return false. if ( ( ( object )a == null ) || ( ( object )b == null ) ) { return false; } // Return true if the fields match: return a.Equals( b ); } public static bool operator !=( ActivationMode a, ActivationMode b ) { return !( a == b ); } public override bool Equals( System.Object obj ) { // If parameter is null return false. if ( obj == null ) { return false; } // If parameter cannot be cast to Point return false. ActivationMode p = obj as ActivationMode; if ( ( System.Object )p == null ) { return false; } // Return true if the fields match: return ( this.Equals( p ) ); } /// /// Returns true if they are the same /// /// ActivationMode to compare with /// True if both are the same, else false public bool Equals( ActivationMode p ) { // If parameter is null return false: if ( ( object )p == null ) { return false; } // Return true if the fields match: return ( Name == p.Name ) && ( MultiTap == p.MultiTap ); } public override int GetHashCode( ) { return Name.GetHashCode( ) ^ MultiTap.GetHashCode( ); } }// end class /// /// Contains the ActivationMode from SC /// can be: /// "Default" using the defActivationMode setting of the profile /// any of the List of profileDefined ones /// public sealed class ActivationModes : List { private static readonly ActivationModes instance = new ActivationModes( ActivationMode.Default ); public static ActivationModes Instance { get { return instance; } } /// /// cTor: Empty - hidden /// private ActivationModes( ) { } /// /// cTor: create one with a first item only /// /// public ActivationModes( ActivationMode firstItem ) { this.Clear( ); this.Add( firstItem ); } /// /// cTor: create one with a default and an attached one /// /// The default ActivationMode /// The attached ActivationMode public ActivationModes( ActivationMode defaultMode, ActivationMode attachedMode ) { this.Clear( ); this.Add( defaultMode ); this.Add( attachedMode ); } /// /// Returns the multitap number for an item /// /// /// public int MultiTapFor( string actModeName ) { try { ActivationMode fAm = this.Find( am => am.Name == actModeName ); return fAm.MultiTap; } catch { return 1; } } /// /// Returns the list of ActivationMode names /// /// A list of names public IList Names { get { ListretVal = new List(); foreach ( ActivationMode am in this ) retVal.Add( am.Name ); return retVal; } } /// /// Returns a new instance from given name from the list /// Or Default if not found /// /// The activationMode to get /// A new ActivationMode instance public ActivationMode ActivationModeByName( string actModeName ) { try { ActivationMode fAm = this.Find( am => am.Name == actModeName ); return new ActivationMode( fAm ); } catch { return new ActivationMode( ); } } } }