public void LoadData_EmptyStream()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(0, 0, DataType.Byte, DataType.Byte, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			using (var stream = new MemoryStream())
			{
				dataService.LoadData(stream, model);
			}
		}
		public void LoadData_OneWordArgument_OneDataEntry()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(1, 0, DataType.Word, DataType.Byte, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[] {0x42, 0x35};
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(1));
			Assert.That(model.GetMachineArgument(0, 0), Is.EqualTo("3542"));
		}
Beispiel #3
0
		public DataModel LoadData(string filePath, FullDataPropertiesDto fullDataPropertiesDto)
		{
			if (!File.Exists(filePath))
			{
				log.ErrorFormat(InternalResources.FileDoesNotExist, filePath);
				throw new FileNotExistsException(filePath);
			}

			var dataModel = new CachingDataModel(filePath, fullDataPropertiesDto, mathService);
			using (var stream = File.OpenRead(filePath))
			{
				LoadDataImpl(stream, dataModel);
			}

			return dataModel;
		}
		private void LoadFile(string filePath, FullDataPropertiesDto fullDataPropertiesDto)
		{
			view.SetStatus(Resources.LoadingFileStatus);
			view.GoToWaitMode();

			var updateRecentFilesTask = taskService.CreateTask(
				() =>
				{
					recentFilesService.AddFile(filePath);
					return recentFilesService.GetRecentFiles();
				})
				.RunOnSuccess(recentFiles => view.SetRecentFiles(recentFiles))
				.RunOnError(exception =>
				            {
				            	log.Error(exception);
				            	var message = string.Format(Resources.FailedToUpdateRecentFilesList, exception.Message);
				            	view.ShowError(message);
				            });
			taskService.CreateTask(
				() => dataService.LoadData(filePath, fullDataPropertiesDto))
				.WithContinuation(updateRecentFilesTask)
				.RunOnSuccess(LoadDataSuccessCallback)
				.RunOnError(LoadDataErrorCallback)
				.Start();
		}
		private void LoadFile(string filePath, CoreDataPropertiesDto coreDataPropertiesDto)
		{
			var fullDataPropertiesDto = new FullDataPropertiesDto(coreDataPropertiesDto);
			LoadFile(filePath, fullDataPropertiesDto);
		}
Beispiel #6
0
		public DataModel(string filePath, FullDataPropertiesDto fullDataPropertiesDto, IMathService mathService)
		{
			FilePath = filePath;
			dataPropertiesModel = GetDataPropertiesModel(fullDataPropertiesDto);
			this.mathService = mathService;
		}
Beispiel #7
0
		private static DataPropertiesModel GetDataPropertiesModel(FullDataPropertiesDto dto)
		{
			var model = new DataPropertiesModel(
				dto.NumberOfArguments, dto.NumberOfFunctions,
				dto.ArgumentsType, dto.FunctionsType, dto.ArithmeticType,
				dto.ArgumentScales, dto.FunctionScales);
			return model;
		}
		public FullDataPropertiesDto GetFullDto()
		{
			var dto = new FullDataPropertiesDto(
				NumberOfArguments, NumberOfFunctions,
				ArgumentsType, FunctionsType, ArithmeticType,
				argumentScales, functionScales);
			return dto;
		}
		public void LoadData_TwoQwordFunctions_TwoDataEntries()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(0, 2, DataType.Byte, DataType.Qword, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[]
			           {
			           	0x42, 0x35, 0xAB, 0xCD, 0x01, 0x23, 0x45, 0x67,
			           	0x89, 0x9A, 0xBC, 0xDE, 0xFF, 0x00, 0x11, 0x22,
			           	0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA,
			           	0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x01, 0x02
			           };
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(2));
			Assert.That(model.GetMachineFunction(0, 0), Is.EqualTo("67452301CDAB3542"));
			Assert.That(model.GetMachineFunction(1, 0), Is.EqualTo("221100FFDEBC9A89"));
			Assert.That(model.GetMachineFunction(0, 1), Is.EqualTo("AA99887766554433"));
			Assert.That(model.GetMachineFunction(1, 1), Is.EqualTo("020100FFEEDDCCBB"));
		}
		public void LoadData_TwoDwordFunctions_TwoDataEntries()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(0, 2, DataType.Byte, DataType.Dword, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[]
			           {0x42, 0x54, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(2));
			Assert.That(model.GetMachineFunction(0, 0), Is.EqualTo("34125442"));
			Assert.That(model.GetMachineFunction(1, 0), Is.EqualTo("BC9A7856"));
			Assert.That(model.GetMachineFunction(0, 1), Is.EqualTo("1100FFDE"));
			Assert.That(model.GetMachineFunction(1, 1), Is.EqualTo("55443322"));
		}
		public void LoadData_TwoWordFunctions_OneDataEntry()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(0, 2, DataType.Byte, DataType.Word, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[] {0x42, 0x54, 0x12, 0x34};
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(1));
			Assert.That(model.GetMachineFunction(0, 0), Is.EqualTo("5442"));
			Assert.That(model.GetMachineFunction(1, 0), Is.EqualTo("3412"));
		}
		public void LoadData_TwoQwordArguments_OneDataEntry()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(2, 0, DataType.Qword, DataType.Byte, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[]
			           {
			           	0x42, 0x35, 0xAB, 0xCD, 0x01, 0x23, 0x45, 0x67,
			           	0x89, 0x9A, 0xBC, 0xDE, 0xFF, 0x00, 0x11, 0x22
			           };
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(1));
			Assert.That(model.GetMachineArgument(0, 0), Is.EqualTo("67452301CDAB3542"));
			Assert.That(model.GetMachineArgument(1, 0), Is.EqualTo("221100FFDEBC9A89"));
		}
		public void LoadData_TwoWordArguments_TwoDataEntries()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(2, 0, DataType.Word, DataType.Byte, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[] {0x42, 0x54, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC};
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(2));
			Assert.That(model.GetMachineArgument(0, 0), Is.EqualTo("5442"));
			Assert.That(model.GetMachineArgument(1, 0), Is.EqualTo("3412"));
			Assert.That(model.GetMachineArgument(0, 1), Is.EqualTo("7856"));
			Assert.That(model.GetMachineArgument(1, 1), Is.EqualTo("BC9A"));
		}
		public void LoadData_OneQwordFunction_OneDataEntry()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(0, 1, DataType.Byte, DataType.Qword, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[] {0x42, 0x35, 0xAB, 0xCD, 0xEF, 0xFF, 0x11, 0x22};
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(1));
			Assert.That(model.GetMachineFunction(0, 0), Is.EqualTo("2211FFEFCDAB3542"));
		}
		public void LoadData_OneDwordFunction_TwoDataEntries()
		{
			var dataPropertiesDto = new FullDataPropertiesDto(
				new CoreDataPropertiesDto(0, 1, DataType.Byte, DataType.Dword, ArithmeticType.Integer));
			var model = new DataModel(string.Empty, dataPropertiesDto, mathService);
			var data = new byte[] {0x42, 0x35, 0xAB, 0xCD, 0x01, 0x23, 0x45, 0x67};
			using (var stream = new MemoryStream(data))
			{
				dataService.LoadData(stream, model);
			}

			Assert.That(model.DataEntriesCount, Is.EqualTo(2));
			Assert.That(model.GetMachineFunction(0, 0), Is.EqualTo("CDAB3542"));
			Assert.That(model.GetMachineFunction(0, 1), Is.EqualTo("67452301"));
		}
		public CachingDataModel(string filePath, FullDataPropertiesDto fullDataPropertiesDto, IMathService mathService)
			: base(filePath, fullDataPropertiesDto, mathService)
		{
			//
		}