public void SetNewFile(Uri newFileUri) { fileLocation = newFileUri; targetPackageData = null; fileExtension = Path.GetExtension(newFileUri.AbsolutePath); fileExtension = fileExtension.Trim('.'); if (string.IsNullOrEmpty(fileExtension)) { return; } if (currentFileDecoder != null) { currentFileDecoder.decodeProgressCallbackEvent -= GetDataFromDecoder; } currentFileDecoder = decoderDict[fileExtension]; if (currentFileDecoder != null) { currentFileDecoder.decodeProgressCallbackEvent += GetDataFromDecoder; currentFileDecoder.SetFilePath(newFileUri); currentFileDecoder.Decode(); isDecoding = true; } }
public void ParseFileTest1() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('f') .AddChar('i') .AddChar('l') .AddChar('e') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x0).BitList; FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), new WeightsTable()); Assert.IsNotNull(segment); Assert.AreEqual("file.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); CollectionAssert.IsEmpty(outputStream.ByteList); }
/// <summary> /// 解析一个Path为控件 /// </summary> /// <returns></returns> public FrameworkElement Decode(string filePath) { string suffix = Path.GetExtension(filePath); IFileDecoder decoder = _suffixToFileMap.GetDecoder(suffix); if (decoder == null) { decoder = this.BinaryFile; } decoder.Decode(filePath); return(decoder.Element); }
public void ParseFileTest2() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('d') .AddChar('a') .AddChar('t') .AddChar('a') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x19) .AddByte(0x20) .AddByte(0x55) .AddByte(0xFF) .AddByte(0x01).BitList; WeightsTable weightsTable = new WeightsTable(); weightsTable.TrackSymbol(1, 1); weightsTable.TrackSymbol(2, 2); weightsTable.TrackSymbol(3, 4); weightsTable.TrackSymbol(4, 8); FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), weightsTable); Assert.IsNotNull(segment); Assert.AreEqual("data.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); byte[] expectedData = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; Assert.AreEqual(expectedData, outputStream.ByteList); }
// Added possibility to decode file via a custom file decoder, written by the library user. public string ReadEncodedFile(string pathName, IFileDecoder fileDecoder) { return(fileDecoder.Decode(File.ReadAllText(path: pathName))); }