From 00a491d93733d4625ad329b2ba8237f445364b3f Mon Sep 17 00:00:00 2001 From: Mirta Date: Wed, 30 Dec 2020 16:39:52 +0200 Subject: merge --- .../VersionPackageDescriptorExtensions.cs | 83 ---------------------- 1 file changed, 83 deletions(-) delete mode 100644 Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs (limited to 'Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs') diff --git a/Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs b/Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs deleted file mode 100644 index 8c66b1c12..000000000 --- a/Software/Visual_Studio/Tango.PMR/ExtensionMethods/VersionPackageDescriptorExtensions.cs +++ /dev/null @@ -1,83 +0,0 @@ -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 -{ - /// - /// Throws exception if the tfp package is invalid. - /// - /// The descriptor. - /// - /// TFP package contains multiple MCU files. - /// or - /// TFP package MCU does specify any version. - /// or - /// - 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."); - } - - if (descriptor.FileDescriptors.GroupBy(x => x.FileName).Any(x => x.Count() > 1)) - { - throw new InvalidDataException("The TPF package cannot contain duplicate file names."); - } - - foreach (var item in descriptor.FileDescriptors) - { - try - { - Version.Parse(item.Version); - } - catch - { - throw new InvalidDataException($"Invalid version ({item.Version}) for file '{item.FileName}'."); - } - } - } - - /// - /// Gets the MCU version. - /// - /// The descriptor. - /// - public static Version GetMcuVersion(this VersionPackageDescriptor descriptor) - { - descriptor.Validate(); - - var mcuFile = descriptor.FileDescriptors.SingleOrDefault(x => x.Destination == VersionFileDestination.Mcu); - - if (mcuFile == null) - { - throw new FileNotFoundException("Could not retrieve TFP package version. MCU file not found."); - } - - return Version.Parse(mcuFile.Version); - } - - /// - /// Determines whether this package contains an MCU file. - /// - /// The descriptor. - public static bool ContainsMcu(this VersionPackageDescriptor descriptor) - { - return descriptor.FileDescriptors.Any(x => x.Destination == VersionFileDestination.Mcu); - } - - /// - /// Determines whether this package contains none MCU files. - /// - /// The descriptor. - public static bool ContainsNoneMcu(this VersionPackageDescriptor descriptor) - { - return descriptor.FileDescriptors.Any(x => x.Destination != VersionFileDestination.Mcu); - } -} - -- cgit v1.3.1