/// <summary> /// Converts a string representation of the <see cref="FirmwareMetadata"/> to its /// equivalent value. A return value indicates whether the conversion succeeded. /// </summary> /// <param name="metadata">The string representing the <see cref="FirmwareMetadata"/>.</param> /// <param name="value"> /// When this method returns, contains the equivalent <see cref="FirmwareMetadata"/> object /// for the specified string representation if the conversion was successful; /// otherwise, contains <b>null</b>. /// </param> /// <returns><b>true</b> if the conversion was successful; otherwise, <b>false</b>.</returns> public static bool TryParse(string metadata, out FirmwareMetadata value) { if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } var match = MetadataRegex.Match(metadata); if (match.Success && match.Groups.Count == 7) { var deviceName = match.Groups[1].Value; var firmwareVersion = HarpVersion.Parse(match.Groups[2].Value); var protocolVersion = HarpVersion.Parse(match.Groups[3].Value); var hardwareVersion = HarpVersion.Parse(match.Groups[4].Value); var assemblyNumber = match.Groups[5].Value == HarpVersion.FloatingWildcard ? (int?)null : int.Parse(match.Groups[5].Value); var prereleaseVersion = string.IsNullOrEmpty(match.Groups[6].Value) ? (int?)null : int.Parse(match.Groups[6].Value); value = new FirmwareMetadata(deviceName, firmwareVersion, protocolVersion, hardwareVersion, assemblyNumber, prereleaseVersion); return(true); } else { value = null; return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="FirmwareMetadata"/> class with the /// specified device name, the firmware version and compatible hardware versions. /// </summary> /// <param name="deviceName">The unique identifier of the device type on which the firmware should be installed.</param> /// <param name="firmwareVersion">The version of the firmware contained in the device or hex file.</param> /// <param name="protocolVersion">The version of the Harp protocol implemented by the firmware.</param> /// <param name="hardwareVersion">The hardware version of the device, or range of hardware versions supported by the firmware.</param> /// <param name="assemblyNumber">The board assembly version of the device, or range of assembly versions supported by the firmware.</param> /// <param name="prereleaseVersion">The optional prerelease number, for preview versions of the firmware.</param> public FirmwareMetadata( string deviceName, HarpVersion firmwareVersion, HarpVersion protocolVersion, HarpVersion hardwareVersion, int?assemblyNumber = default, int?prereleaseVersion = default) { DeviceName = deviceName ?? throw new ArgumentNullException(nameof(deviceName)); FirmwareVersion = firmwareVersion ?? throw new ArgumentNullException(nameof(firmwareVersion)); ProtocolVersion = protocolVersion ?? throw new ArgumentNullException(nameof(protocolVersion)); HardwareVersion = hardwareVersion ?? throw new ArgumentNullException(nameof(hardwareVersion)); AssemblyNumber = assemblyNumber; PrereleaseVersion = prereleaseVersion; }
/// <summary> /// Returns whether the firmware supports the specified hardware version /// and board assembly number. /// </summary> /// <param name="deviceName">The identifier of the device to check for compatibility.</param> /// <param name="hardwareVersion">The hardware version to check for compatibility.</param> /// <param name="assemblyNumber">The optional board assembly number to check for compatibility.</param> /// <returns> /// <b>true</b> if the firmware supports the specified <paramref name="hardwareVersion"/> and /// <paramref name="assemblyNumber"/>; otherwise, <b>false</b>. /// </returns> public bool Supports(string deviceName, HarpVersion hardwareVersion, int assemblyNumber = default) { return(DeviceName == deviceName && HardwareVersion.Satisfies(hardwareVersion) && (!AssemblyNumber.HasValue || AssemblyNumber.Value == assemblyNumber)); }