private Tuple <int, IDictionary <int, int> > GetClosestMatchingErrorMap(ErrorLogId logId, int errorMapFirmwareVersion) { var matchingMap = new Tuple <int, IDictionary <int, int> >(-1, null); IDictionary <int, IDictionary <int, int> > firmwareVersionEntries; if (ErrorMaps.TryGetValue(logId, out firmwareVersionEntries)) { IDictionary <int, int> closestMatchErrorMap; if (firmwareVersionEntries.TryGetValue(errorMapFirmwareVersion, out closestMatchErrorMap)) { matchingMap = new Tuple <int, IDictionary <int, int> >(errorMapFirmwareVersion, closestMatchErrorMap); } else { var closestMatchFirmwareVersion = -1; foreach (var firmwareVersionEntry in firmwareVersionEntries) { var firmwareVersion = firmwareVersionEntry.Key; if ((firmwareVersion > closestMatchFirmwareVersion) && (firmwareVersion < errorMapFirmwareVersion)) { closestMatchFirmwareVersion = firmwareVersion; closestMatchErrorMap = firmwareVersionEntry.Value; } } if ((closestMatchFirmwareVersion > 0) && (closestMatchErrorMap != null)) { matchingMap = new Tuple <int, IDictionary <int, int> >(closestMatchFirmwareVersion, closestMatchErrorMap); } } } return(matchingMap); }
/// <summary> /// Gets the database best capable of providing meaningful error messages given a firmware version and error log identifier. /// </summary> /// <param name="rawFirmwareVersion">The raw firmware version for which an error log is to be parsed.</param> /// <param name="errorLogId">Which section of the error log is requested.</param> /// <param name="errorDatabaseFilesDirectory">Where to look for potential updated version of the error log.</param> /// <returns>An error database most likely to support error log parsing given the input parameters.</returns> internal static ErrorDatabase GetErrorDatabase(int rawFirmwareVersion, ErrorLogId errorLogId, string errorDatabaseFilesDirectory = null) { // First, check default map for exact match. ErrorDatabase matchingDatabase = Default; var errorMapFirmwareVersion = GetFirmwareVersionForLookup(rawFirmwareVersion); var matchingMap = Default.GetClosestMatchingErrorMap(errorLogId, errorMapFirmwareVersion); if (matchingMap.Item1 != errorMapFirmwareVersion) { // Did not find exact match in default database. Next, check on disk in default location for a better match. if (string.IsNullOrWhiteSpace(errorDatabaseFilesDirectory)) { errorDatabaseFilesDirectory = Configuration.Instance.FirmwareUpdatesDirectory; } Tuple <int, IDictionary <int, int> > onDiskMatchingMap; var onDiskDatabaseMatch = GetClosestMatchingErrorDatabase(rawFirmwareVersion, errorLogId, errorDatabaseFilesDirectory, out onDiskMatchingMap); if (onDiskMatchingMap.Item1 > matchingMap.Item1) { matchingMap = onDiskMatchingMap; matchingDatabase = onDiskDatabaseMatch; } // Finally, check embedded resources for a better match. if (matchingMap.Item1 != errorMapFirmwareVersion) { Tuple <int, IDictionary <int, int> > resourcesMatchingMap; var resourcesDatabaseMatch = GetClosestMatchingErrorDatabase(rawFirmwareVersion, errorLogId, FirmwareRevisions.FirmwareUpdateResourcePrefix, out resourcesMatchingMap); if (resourcesMatchingMap.Item1 > matchingMap.Item1) { matchingMap = resourcesMatchingMap; matchingDatabase = resourcesDatabaseMatch; } } } return(matchingDatabase); }
private static ErrorDatabase GetClosestMatchingErrorDatabase(int rawFirmwareVersion, ErrorLogId errorLogId, string databaseRoot, out Tuple <int, IDictionary <int, int> > matchingMap) { matchingMap = null; ErrorDatabase errorDatabase = null; var userFriendlyFirmwareVersion = GetFirmwareVersionForResource(rawFirmwareVersion); int closestFirmwareVersion = -1; string databaseTypeForClosestFirmwareVersion = null; foreach (var databaseType in ErrorDatabaseFileTypes.Keys.Where(t => IsDatabaseTypeSupported(t))) { var closestFirmwareVersionMatch = GetClosestMatchForErrorDatabase(userFriendlyFirmwareVersion, databaseType, databaseRoot); if (closestFirmwareVersionMatch > closestFirmwareVersion) { closestFirmwareVersion = closestFirmwareVersionMatch; databaseTypeForClosestFirmwareVersion = databaseType; } if (closestFirmwareVersion == userFriendlyFirmwareVersion) { break; } } if (closestFirmwareVersion > 0) { // load this database and find best match var databasePath = MakeFullyQualifiedVersionedDatabaseSourceName(closestFirmwareVersion, databaseRoot, databaseTypeForClosestFirmwareVersion); errorDatabase = new ErrorDatabase(databasePath); var errorMapFirmwareVersion = GetFirmwareVersionForLookup(rawFirmwareVersion); matchingMap = errorDatabase.GetClosestMatchingErrorMap(errorLogId, errorMapFirmwareVersion); } return(errorDatabase); }
/// <summary> /// Initialize a new instance with specific values. /// </summary> /// <param name="logIndex">The index of the error log entry.</param> /// <param name="logId">The identifier of which specific part of the firmware the firmware error originated in.</param> /// <param name="lineNumber">The original line number in the firmware source where the error occurred.</param> /// <param name="errorDetails">Data to provide for the error format string from the error database.</param> public ErrorLogEntry(ushort logIndex, ErrorLogId logId, int lineNumber, IEnumerable <int> errorDetails) : base(logIndex, logId, lineNumber, errorDetails) { }