public void PrintColoredStructure(IHaveStructure anEntityWithStructure) { aLogger.LogMessage($"Entered: {MethodBase.GetCurrentMethod().Name}", LogMsgType.Debug); Initialize(); var i = 1; foreach (var unit in anEntityWithStructure.Structure) { if (unit.Value == "000000") { int dx = 100; } PrintValue(unit.Value, unit.UnitColor); } rtb.AppendText(Environment.NewLine); aLogger.LogMessage($"Exited: {MethodBase.GetCurrentMethod().Name}", LogMsgType.Debug); }
public static T GetUnit <T>(string fileName, ref Logger aLogger, int startAddress, string description, IHaveStructure myParent) where T : IHaveStructure, IHaveCommonProps, new() { var instance = Activator.CreateInstance <T>(); try { var unitStartAddress = startAddress; instance.Description = description; instance.Logger = aLogger; if (instance is IHaveStartAddress) { (instance as IHaveStartAddress).StartAddress = startAddress; } //IF THE START ADDRESS IS -1 THEN THE FILE NAME IS THE HEX VALUE instance.RawValue = (startAddress == -1) ? fileName : ReadBytesFromImageAsHex(fileName, unitStartAddress, instance.Size, ref aLogger); if (instance is IHaveExactSize) { var expectedSizeInHex = (instance as IHaveExactSize).GetExpectedSize() * 2; var checkerSize = instance.RawValue.Length; if (checkerSize != expectedSizeInHex) { var err = $"in {System.Reflection.MethodBase.GetCurrentMethod().Name}, Structure unit has fixed size of [{expectedSizeInHex}] but the actual size is[{checkerSize}]...Operation Terminated "; aLogger.LogMessage(err, LogMsgType.Fatal); throw new Exception(err); } } if (instance.Structure != null) { ParseStructureUnits(instance.Structure, instance.RawValue, aLogger); } else { aLogger.LogMessage( $"in {System.Reflection.MethodBase.GetCurrentMethod().Name}, Structure list is empty...Operation Terminated ", LogMsgType.Fatal); } if (instance is BootSector) { (instance as BootSector).DetermineFatType(); } if (instance is FatDirectoryArea) { if (myParent is BootSector) { var i = instance as FatDirectoryArea; if (i.IsThisEntryaLongFileName()) { i.Structure = i.LongFileNameStructure; ParseStructureUnits(i.Structure, i.RawValue, aLogger); } var mp = myParent as BootSector; i.MaxNumofRootDirectories = mp.GetMaxNumberOfRootDirectories(); i.SectorsPerCluster = mp.GetNumberOfSectorsPerCluser(); i.RootDirectoryStartAddress = mp.GetRootDirectoryStartByte(); } else { var err = $"in {System.Reflection.MethodBase.GetCurrentMethod().Name}, You forget to pass bootsector parent? normally its null. Operation terminated. "; aLogger.LogMessage(err, LogMsgType.Fatal); throw new Exception("err"); } } return(instance); } catch (Exception ex) { aLogger.LogMessage(ex.Message, LogMsgType.Fatal); return(instance); } }