public void RemoveExistingFromHeader(HeaderContent aHeaderContent, string aHeaderPath) { if (aHeaderPath.StartsWith("<") && aHeaderPath.EndsWith(">") || !aHeaderContent.SortedHeaderResults.ContainsKey(aHeaderPath)) return; foreach (var headerItem in aHeaderContent.SortedHeaderResults[aHeaderPath]) { emptyIDs.Remove(Convert.ToInt32(headerItem.ID.Value)); } emptyIDs.Remove(0); }
public static HeaderId NormalizeRecurrenceForID(HeaderId aID, HeaderContent aHeaderContent) { while (IDValidator.IsRecurrentCase(aID, aHeaderContent)) { aID.Value = aHeaderContent.NameToID[aID.Value].Value; } if (!IDValidator.IsValidWithoutRecurrenceCheck(aID)) { aID.Value = Constants.kInvalidID.Value; } return(aID); }
public static bool IsValid(string aString, HeaderContent aHeaderContent) => !IsRecurrentCase(aString, aHeaderContent) && IsValidWithoutRecurrenceCheck(aString) || aString == Constants.kNotFoundID.Value;
public static bool IsValid(HeaderId aID, HeaderContent aHeaderContent) => IsValid(aID.Value, aHeaderContent);
public static bool IsRecurrentCase(string aString, HeaderContent aHeaderContent) => !IsValidWithoutRecurrenceCheck(aString) && aHeaderContent.NameToID.ContainsKey(aString);
public static bool IsRecurrentCase(HeaderId aID, HeaderContent aHeaderContent) => IsRecurrentCase(aID.Value, aHeaderContent);
public static HeaderId CopyNormalizeRecurrenceForID(HeaderId aID, HeaderContent aHeaderContent) => NormalizeRecurrenceForID(new HeaderId(aID), aHeaderContent);
public static void AddItem(TestItem aTestItem, RCFileContent aRCFileContent, HeaderContent aHeaderContent) { var stringTableContent = aRCFileContent.StringTableContent; var stringTableIndexOrder = aRCFileContent.StringTableIndexOrder; var determinedStringTableIndex = StringTableIndexCalculator.CalculateIndex(aTestItem.ID); // Check if StringTable with index currentIdx exists if (!stringTableContent.ContainsKey(determinedStringTableIndex)) { stringTableContent.Add(determinedStringTableIndex, new List <RCFileItem>()); stringTableIndexOrder.Add(determinedStringTableIndex); } var printStyle = StringTablePrintStyleDeterminer.DeterminePrintStyle(aTestItem.Name, aTestItem.Value); bool notYetAdded = true; var startIndex = (stringTableContent[determinedStringTableIndex].Count / Constants.kStringTableCapacity) * Constants.kStringTableCapacity; int testItemID; if (aTestItem.ID.IsHexa) { testItemID = Convert.ToInt32(aTestItem.ID.Value, 16); } else { testItemID = Convert.ToInt32(aTestItem.ID.Value); } for (int i = startIndex; i < stringTableContent[determinedStringTableIndex].Count; ++i) { var currentName = stringTableContent[determinedStringTableIndex][i].Name; if (!aHeaderContent.NameToID.TryGetValue(currentName, out var currentIDString)) { continue; } if (!int.TryParse(currentIDString.Value, out var currentID)) { continue; } if (testItemID < currentID) { stringTableContent[determinedStringTableIndex].Insert(i, new RCFileItem { Name = aTestItem.Name, Value = aTestItem.Value, ID = aTestItem.ID, PrintStyle = printStyle }); notYetAdded = false; break; } } if (!notYetAdded) { return; } stringTableContent[determinedStringTableIndex].Add( new RCFileItem { Name = aTestItem.Name, Value = aTestItem.Value, ID = aTestItem.ID, PrintStyle = printStyle }); notYetAdded = false; }
private void ParseRCFile(string aPath, Encoding aCodePage, HeaderContent aHeaderContent) { using (var stringTableParser = new RCFileParser(aPath, aCodePage)) { int currentStringTableIndex = Constants.kNotDiscovered; // Index of current STable int previousStringTableIndex = Constants.kNotDiscovered; // Index of previous STable int unusedSTableIndex = 0; List <RCFileItem> unusedElements = new List <RCFileItem>(); while (stringTableParser.HasNext()) { var obj = stringTableParser.GetNext(); if (obj.Name == "BEGIN") { continue; } if (obj.Name == "END") // End of the current STable { if (currentStringTableIndex != Constants.kNotDiscovered && previousStringTableIndex != currentStringTableIndex) // If index has been calculated and it is new { mRCFileContent.StringTableIndexOrder.Add(currentStringTableIndex); // Add current index to the order list // Add unused to the beginning mRCFileContent.StringTableContent[currentStringTableIndex].InsertRange(0, unusedElements); } else if (currentStringTableIndex == Constants.kNotDiscovered) { // Assign a meaningless STable index currentStringTableIndex = --unusedSTableIndex; // Add to StringTableIndexOrder mRCFileContent.StringTableIndexOrder.Add(currentStringTableIndex); // Add all unused to STable mRCFileContent.StringTableContent.Add(currentStringTableIndex, new List <RCFileItem>()); mRCFileContent.StringTableContent[currentStringTableIndex].AddRange(unusedElements); } unusedElements.Clear(); previousStringTableIndex = currentStringTableIndex; currentStringTableIndex = Constants.kNotDiscovered; // Reset index of current STable } else // Found new object from current STable { if (!aHeaderContent.NameToID.ContainsKey(obj.Name)) // If there's no ID for the current Name in current RC's headers { if (currentStringTableIndex == Constants.kNotDiscovered) { unusedElements.Add(obj); } obj.ID = Constants.kNotFoundID; mHeaderContent.NameToID[obj.Name] = obj.ID; } else { obj.ID = aHeaderContent.NameToID[obj.Name]; } if (currentStringTableIndex == Constants.kNotDiscovered && obj.ID != Constants.kNotFoundID) // If index is not yet calculated and ID exists { currentStringTableIndex = StringTableIndexCalculator.CalculateIndex(aHeaderContent.NameToID[obj.Name]); // Get index of current STable } if (currentStringTableIndex == Constants.kNotDiscovered) { continue; // Could not calculate index of current STable } if (!mRCFileContent.StringTableContent.ContainsKey(currentStringTableIndex)) // In case current STable is not registered in the Dictionary { mRCFileContent.StringTableContent.Add(currentStringTableIndex, new List <RCFileItem>()); // Register STable in Dictionary } mRCFileContent.StringTableContent[currentStringTableIndex].Add(obj); // Add current object to its STable } } } }
public RCFileContentBuilder(string aPath, Encoding aCodePage, HeaderContent aHeaderContent) { mPath = aPath; mCodePage = aCodePage; mHeaderContent = aHeaderContent; }