diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-01-27 17:31:20 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-01-27 17:31:20 +0200 |
| commit | 1f78f8b3220487028bd20cd317094ea55517d0af (patch) | |
| tree | 99351cf019bc118426d148723e0c912eadf2dc13 /Software/Visual_Studio/Tango.PMR/ExtensionMethods | |
| parent | dead9a919e2a786162a420cb1233db178aeb11f3 (diff) | |
| download | Tango-1f78f8b3220487028bd20cd317094ea55517d0af.tar.gz Tango-1f78f8b3220487028bd20cd317094ea55517d0af.zip | |
Implemented validation and more extension methods for VersionPackageDescriptor.
Implemented TFP package validation on Firmware Upgrade and Package Generator.
Omitted MCU file from uploading when upgrading package.
Diffstat (limited to 'Software/Visual_Studio/Tango.PMR/ExtensionMethods')
| -rw-r--r-- | Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs b/Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs new file mode 100644 index 000000000..78b179736 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.FirmwareUpgrade; + +public static class VersionPackageDescriptorExtensions +{ + /// <summary> + /// Validates the specified TFP package. + /// </summary> + /// <param name="descriptor">The descriptor.</param> + /// <exception cref="InvalidDataException"> + /// TFP package contains multiple MCU files. + /// or + /// TFP package MCU does specify any version. + /// or + /// </exception> + public static void Validate(this VersionPackageDescriptor descriptor) + { + if (descriptor.FileDescriptors.Where(x => x.Destination == VersionFileDestination.Mcu).Count() > 1) + { + throw new InvalidDataException("TFP package contains multiple MCU files."); + } + + var mcuFile = descriptor.FileDescriptors.SingleOrDefault(x => x.Destination == VersionFileDestination.Mcu); + + if (String.IsNullOrWhiteSpace(mcuFile.Version)) + { + throw new InvalidDataException("TFP package MCU does specify any version."); + } + + try + { + Version.Parse(mcuFile.Version); + } + catch + { + throw new InvalidDataException($"TFP package MCU version '{mcuFile.Version}' is invalid."); + } + } + + /// <summary> + /// Gets the MCU version. + /// </summary> + /// <param name="descriptor">The descriptor.</param> + /// <returns></returns> + public static Version GetMcuVersion(this VersionPackageDescriptor descriptor) + { + descriptor.Validate(); + + var mcuFile = descriptor.FileDescriptors.SingleOrDefault(x => x.Destination == VersionFileDestination.Mcu); + + return Version.Parse(mcuFile.Version); + } + + /// <summary> + /// Determines whether this package contains an MCU file. + /// </summary> + /// <param name="descriptor">The descriptor.</param> + public static bool ContainsMcu(this VersionPackageDescriptor descriptor) + { + return descriptor.FileDescriptors.Any(x => x.Destination == VersionFileDestination.Mcu); + } + + /// <summary> + /// Determines whether this package contains none MCU files. + /// </summary> + /// <param name="descriptor">The descriptor.</param> + public static bool ContainsNoneMcu(this VersionPackageDescriptor descriptor) + { + return descriptor.FileDescriptors.Any(x => x.Destination != VersionFileDestination.Mcu); + } +} + |
