Exemplo n.º 1
0
        /// <summary>
        /// Parses the given string to produce a new instance of <see cref="DeviceStatusFlags"/>.
        /// </summary>
        /// <param name="value">The string to parse.</param>
        /// <returns>A new instance of <see cref="DeviceStatusFlags"/> containing the flags specified by <paramref name="value"/>.</returns>
        /// <remarks>The string must be of the format: Lo: loFlag0, loFlag1, ... loFlagN; Hi: hiFlag0, hiFlag1, ... hiFlagM.</remarks>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is empty, contains only whitespace, or either portion (high or low)
        /// is not present or is empty or whitespace. Also thrown if the portions of the string are not prefixed with 'Lo:' and 'Hi:'.</exception>
        public static DeviceStatusFlags Parse(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            var allParts = value.Split(new[] { ';' });

            ValidateStringPartsForParse(allParts, validatePartsType: false);

            var firstParts    = allParts[0].Split(new[] { ':' });
            var firstPartType = ValidateStringPartsForParse(firstParts, validatePartsType: true);

            var secondParts    = allParts[1].Split(new[] { ':' });
            var secondPartType = ValidateStringPartsForParse(secondParts, validatePartsType: true);

            if (firstPartType == secondPartType)
            {
                throw new ArgumentException();
            }

            var lowFlagsString = firstPartType == FlagsStringPart.Lo ? firstParts[1] : secondParts[1];
            var lowFlags       = (DeviceStatusFlagsLo)Enum.Parse(typeof(DeviceStatusFlagsLo), lowFlagsString.Trim());

            var highFlagsString = firstPartType == FlagsStringPart.Hi ? firstParts[1] : secondParts[1];
            var highFlags       = (DeviceStatusFlagsHi)Enum.Parse(typeof(DeviceStatusFlagsHi), highFlagsString.Trim());

            var flags = new DeviceStatusFlags(lowFlags, highFlags);

            return(flags);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public bool UpdateCurrentValue(DeviceStatusFlags currentConfiguration)
        {
            this.VerifyWriteAccess <T>(); // throws if read-only
            var newValue     = ConvertDeviceStatusFlagsToValue(currentConfiguration);
            var valueChanged = INotifyPropertyChangedHelpers.SafeDidValueChangeCompare(newValue, CurrentValue);

            CurrentValue = newValue;
            return(valueChanged);
        }
 /// <summary>
 /// Updates the device configuration settings.
 /// </summary>
 /// <param name="device">The target Locutus device whose configuration is to be set.</param>
 /// <param name="newConfigurationFlags">The new configuration data.</param>
 /// <param name="onCompleteHandler">Success handler, used to report successful execution of the command.</param>
 /// <param name="errorHandler">Error handler, used to report errors to the user.</param>
 public static void SetConfiguration(this Device device, DeviceStatusFlags newConfigurationFlags, DeviceCommandCompleteHandler onCompleteHandler, DeviceCommandErrorHandler errorHandler)
 {
     if (device.IsSafeToStartCommand())
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, ProtocolCommandId.SetConfiguration)
         {
             Data      = newConfigurationFlags,
             OnSuccess = onCompleteHandler,
             OnFailure = errorHandler
         };
         executeCommandTaskData.StartTask(SetConfiguration);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Parses the given string to produce a new instance of <see cref="DeviceStatusFlags"/>.
        /// </summary>
        /// <param name="value">The string to parse.</param>
        /// <param name="flags">The <see cref="DeviceStatusFlags"/> containing the flags specified by <paramref name="value"/>,
        /// or <see cref="DeviceStatusFlags.None"/> if <paramref name="value"/> is not valid.</param>
        /// <returns><c>true</c> if <paramref name="value"/> was successfully parsed.</returns>
        public static bool TryParse(string value, out DeviceStatusFlags flags)
        {
            var success = true;

            try
            {
                flags = Parse(value);
            }
            catch (Exception)
            {
                flags   = DeviceStatusFlags.None;
                success = false;
            }
            return(success);
        }
        /// <inheritdoc />
        protected override bool ConvertDeviceStatusFlagsToValue(DeviceStatusFlags currentConfiguration)
        {
            var value = currentConfiguration.HasFlag(FeatureFlagsMask);

            return(value);
        }
        /// <summary>
        /// Creates an instance of <see cref="ConfigurableLtoFlashBooleanFeature"/>.
        /// </summary>
        /// <param name="uniqueId">The unique identifier of the configurable feature.</param>
        /// <param name="displayName">The user-friendly display name of the feature.</param>
        /// <param name="defaultValue">The factory default value for the feature.</param>
        /// <param name="featureFlagsMask">The flags mask for the feature.</param>
        /// <param name="readOnly">If <c>true</c>, the feature is read-only and will throw a <see cref="System.InvalidOperationException"/> if modified.</param>
        /// <returns>A new configurable LTO Flash! feature.</returns>
        public static IConfigurableLtoFlashFeature Create(string uniqueId, string displayName, bool defaultValue, DeviceStatusFlags featureFlagsMask, bool readOnly)
        {
            IConfigurableLtoFlashFeature configurableFeature;

            if (readOnly)
            {
                configurableFeature = new ReadOnlyConfigurableLtoFlashFeature(uniqueId, displayName, defaultValue, featureFlagsMask);
            }
            else
            {
                configurableFeature = new ConfigurableLtoFlashBooleanFeature(uniqueId, displayName, defaultValue, featureFlagsMask);
            }
            return(configurableFeature);
        }
 /// <summary>
 /// Initializes a new instance of <see cref="ConfigurableLtoFlashBooleanFeature"/>.
 /// </summary>
 /// <param name="uniqueId">The unique identifier of the configurable feature.</param>
 /// <param name="displayName">The user-friendly display name of the feature.</param>
 /// <param name="defaultValue">The factory default value for the feature.</param>
 /// <param name="featureFlagsMask">The flags mask for the feature.</param>
 protected ConfigurableLtoFlashBooleanFeature(string uniqueId, string displayName, bool defaultValue, DeviceStatusFlags featureFlagsMask)
     : base(uniqueId, displayName, defaultValue, featureFlagsMask)
 {
 }
Exemplo n.º 8
0
        /// <inheritdoc />
        protected override IntellivisionIIStatusFlags ConvertDeviceStatusFlagsToValue(DeviceStatusFlags currentConfiguration)
        {
            var value = currentConfiguration.Lo.ToIntellivisionIICompatibilityFlags();

            return(value);
        }
        /// <inheritdoc />
        protected override DeviceStatusFlags ConvertValueToDeviceStatusFlags(ShowTitleScreenFlags newValue)
        {
            var configurationFlags = new DeviceStatusFlags(newValue.ToDeviceStatusFlagsLo());

            return(configurationFlags);
        }
Exemplo n.º 10
0
 protected override T ConvertDeviceStatusFlagsToValue(DeviceStatusFlags currentConfiguration)
 {
     throw new System.InvalidOperationException();
 }
        /// <inheritdoc />
        protected override DeviceStatusFlags ConvertValueToDeviceStatusFlags(SaveMenuPositionFlags newValue)
        {
            var configurationFlags = new DeviceStatusFlags(newValue.ToDeviceStatusFlagsLo());

            return(configurationFlags);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Determines whether one or more bit fields are set in the current instance.
 /// </summary>
 /// <param name="flags">Flags to check.</param>
 /// <returns><c>true</c> if the bit field or bit fields that are set in <paramref name="flags"/> are also set in the current instance; otherwise, <c>false</c>.</returns>
 public bool HasFlag(DeviceStatusFlags flags)
 {
     return(HasFlag(flags.Lo) && HasFlag(flags.Hi));
 }
        /// <inheritdoc />
        protected override ShowTitleScreenFlags ConvertDeviceStatusFlagsToValue(DeviceStatusFlags currentConfiguration)
        {
            var value = currentConfiguration.Lo.ToShowTitleScreenFlags();

            return(value);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Converts the given current configuration as <see cref="DeviceStatusFlags"/> to a concrete type.
 /// </summary>
 /// <param name="currentConfiguration">The device's current status.</param>
 /// <returns>The configurable feature as a concretely typed value.</returns>
 protected abstract T ConvertDeviceStatusFlagsToValue(DeviceStatusFlags currentConfiguration);
        /// <inheritdoc />
        protected override SaveMenuPositionFlags ConvertDeviceStatusFlagsToValue(DeviceStatusFlags currentConfiguration)
        {
            var value = currentConfiguration.Lo.ToSaveMenuPositionFlags();

            return(value);
        }
Exemplo n.º 16
0
 public ReadOnlyConfigurableLtoFlashFeature(string uniqueId, string displayName, T defaultValue, DeviceStatusFlags featureFlagsMask)
     : base(uniqueId, displayName, defaultValue, featureFlagsMask)
 {
 }
Exemplo n.º 17
0
        /// <inheritdoc />
        protected override DeviceStatusFlags ConvertValueToDeviceStatusFlags(IntellivisionIIStatusFlags newValue)
        {
            var configurationFlags = new DeviceStatusFlags(newValue.ToDeviceStatusFlagsLo());

            return(configurationFlags);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initialize a new instance of <see cref="ConfigurableLtoFlashFeature{T}"/>.
 /// </summary>
 /// <param name="uniqueId">The unique identifier of the configurable feature.</param>
 /// <param name="displayName">The user-friendly display name of the feature.</param>
 /// <param name="defaultValue">The factory default value for the feature.</param>
 /// <param name="featureFlagsMask">The flags mask for the feature.</param>
 protected ConfigurableLtoFlashFeature(string uniqueId, string displayName, T defaultValue, DeviceStatusFlags featureFlagsMask)
     : base(uniqueId, displayName, defaultValue)
 {
     FeatureFlagsMask = featureFlagsMask;
 }
Exemplo n.º 19
0
        /// <inheritdoc />
        protected override EcsStatusFlags ConvertDeviceStatusFlagsToValue(DeviceStatusFlags currentConfiguration)
        {
            var value = currentConfiguration.Lo.ToEcsCompatibilityFlags();

            return(value);
        }