public FlashUploadCommandVM(IRUSDevice device, IFlashDumpDataParserFactory parserFactory, IFlashDumpSaver flashDumpSaver, IFlashDumpLoader dumpLoader, BusyObject busy) { _device = device ?? throw new ArgumentNullException(nameof(device)); _parserFactory = parserFactory; _flashDumpSaver = flashDumpSaver; IsBusy = busy ?? throw new ArgumentNullException(nameof(busy)); SaveDump = new ActionCommand(saveDumpAsync, () => _dump != null && IsBusy.IsNotBusy, IsBusy); async Task saveDumpAsync() { try { var path = IOUtils.RequestFileSavingPath("BIN(*.bin)|*.bin"); if (path != null) { using (var targetDumpFile = File.Create(path)) { await _dump.SaveDumpAsync(targetDumpFile, _flashDumpSaver, new AsyncOperationInfo()); } await dumpLoader.LoadAsync(path, new AsyncOperationInfo()); UserInteracting.ReportSuccess("Сохранение дампа Flash-памяти", "Файл успешно сохранен"); } } catch (Exception ex) { Logger.LogErrorEverywhere("Ошибка сохранения дампа Flash-памяти", ex); } } }
public async static Task <FlashStreamReader> CreateAsync(RUSDeviceId device, IDictionary <RUSDeviceId, IEnumerable <IDataEntity> > formats, IFlashDumpDataParserFactory parserFactory, AsyncOperationInfo operationInfo) { var flashDumpPath = Storaging.GetTempFilePath(); var baseStream = new FileStream(flashDumpPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); var flashDumpWriteStream = new FillNotifiableWriteOnlyStreamDecorator(CHUNK_SIZE, baseStream); var partsProvider = new DumpParserPartsProvider(flashDumpPath); var partsProviderSupplier = new StreamPartsProviderSupplier(flashDumpWriteStream, partsProvider); var scope = new DeviceOperationScope(new FlashDumpStreamParameter(flashDumpWriteStream)); var sections = formats.Select(f => new SectionedDataPacketParser.Section( f.Key, new DataPacketParser(EntitiesDeserializer.ExtractDataPacketDescriptors(f.Value)))) .ToArray(); var dataParser = new SectionedDataPacketParser(sections); var parserFuture = parserFactory.CreateFromRawPartsAsync(partsProvider.RawDumpParts(), dataParser, operationInfo); return(new FlashStreamReader(scope, device, formats, parserFuture, partsProviderSupplier, flashDumpWriteStream, flashDumpPath)); }
static FlashDumpDataParserFactory() { Instance = new FlashDumpDataParserFactory(); }