/// <summary> /// Refreshes the status of the program description by checking the file system. /// </summary> /// <param name="peripherals">Peripherals available for compatibility checks.</param> /// <returns><c>true</c>, if file status changed, <c>false</c> otherwise.</returns> public bool RefreshFileStatus(IEnumerable <IPeripheral> peripherals) { #if REPORT_PERFORMANCE var stopwatch = System.Diagnostics.Stopwatch.StartNew(); try { #endif // REPORT_PERFORMANCE var currentStatus = RomFileStatus; var currentIcon = RomFileStatusIcon; ProgramDescription.Validate(Model, peripherals, SingleInstanceApplication.Instance.GetConnectedDevicesHistory(), true); var state = Model.Files.GetSupportFileState(ProgramFileKind.Rom); RomFileStatus = GetRomFileStatus(state); RomFileStatusIcon = StatusIcons[state]; var statusChanged = (currentIcon != RomFileStatusIcon) || (currentStatus != RomFileStatus); if (statusChanged) { this.RaisePropertyChanged(PropertyChanged, "RomFileStatus"); this.RaisePropertyChanged(PropertyChanged, "RomFileStatusIcon"); } return(statusChanged); #if REPORT_PERFORMANCE } finally { stopwatch.Stop(); var romPath = Rom == null ? "<invalid ROM>" : Rom.RomPath; romPath = romPath ?? "<invalid ROM path>"; Logger.Log("ProgramDescriptionViewModel.RefreshFileStatus() for: " + romPath + " took: + " + stopwatch.Elapsed.ToString()); } #endif // REPORT_PERFORMANCE }
/// <summary> /// Initializes a new instance of the ProgramDescriptionViewModel class. /// </summary> /// <param name="programDescription">The ProgramDescription model to model a view for.</param> public ProgramDescriptionViewModel(ProgramDescription programDescription) { _description = programDescription; _description.PropertyChanged += OnPropertyChanged; if (Properties.Settings.Default.RomListValidateAtStartup) { #if REPORT_PERFORMANCE var stopwatch = System.Diagnostics.Stopwatch.StartNew(); try { #endif // REPORT_PERFORMANCE ProgramDescription.Validate(programDescription, SingleInstanceApplication.Instance.GetAttachedDevices(), SingleInstanceApplication.Instance.GetConnectedDevicesHistory(), reportMessagesChanged: false); #if REPORT_PERFORMANCE } finally { stopwatch.Stop(); var romPath = Rom == null ? "<invalid ROM>" : Rom.RomPath; romPath = romPath ?? "<invalid ROM path>"; Logger.Log("ProgramDescriptionViewModel().Validate() for: " + romPath + " took: + " + stopwatch.Elapsed.ToString()); } #endif // REPORT_PERFORMANCE } var state = programDescription.Files.GetSupportFileState(ProgramFileKind.Rom); RomFileStatus = GetRomFileStatus(state); RomFileStatusIcon = StatusIcons[state]; Features = new ComparableObservableCollection <ProgramFeatureImageViewModel>(_description.Features.ToFeatureViewModels()); Initialize(); }
public void ProgramDescription_ValidateWithNullRom_ThrowsNullReferenceException() { var information = new TestProgramInformation(); var crc = 1u; var name = "AgletMaster 5400"; information.AddCrc(crc, name); var description = new ProgramDescription(crc, null, information); Assert.Throws <NullReferenceException>(() => ProgramDescription.Validate(description, null, null, reportMessagesChanged: false)); // Throws because ROM is null. }
public void ProgramDescription_ValidateWithValidRom_ReturnsTrue() { var romPath = ProgramDescriptionTestStorage.Initialize(TestRomResources.TestRomPath).First(); var rom = Rom.Create(romPath, null); Assert.NotNull(rom); var information = new TestProgramInformation(); var crc = rom.Crc; var name = "AgletMaster 5500"; information.AddCrc(crc, name); var description = new ProgramDescription(crc, rom, information); Assert.True(ProgramDescription.Validate(description, null, null, reportMessagesChanged: false)); }
public void ProgramDescription_ValidateWithValidRomWhoseCfgFileIsMissing_ReturnsFalse() { var romPath = ProgramDescriptionTestStorage.Initialize(TestRomResources.TestLuigiScrambledForDevice0Path).First(); var rom = Rom.Create(romPath, null); Assert.NotNull(rom); var information = new TestProgramInformation(); var crc = 0x8C29E37Du; var name = "AgletMaster 5600"; information.AddCrc(crc, name); var description = new ProgramDescription(crc, rom, information); var v = ProgramDescription.Validate(description, null, null, reportMessagesChanged: false); Assert.False(ProgramDescription.Validate(description, null, null, reportMessagesChanged: false)); }