コード例 #1
0
        protected override void CustomFileExport(ExportParameters exportParameters)
        {
            var scriptCompiledBytecode = ScriptCompiledBytecodeResource.Create(exportParameters.FileRecord.Info?.VersionHash ?? string.Empty);

            scriptCompiledBytecode.InitFromRecord(exportParameters.BagStream, exportParameters.FileRecord);
            var outputPath = Path.GetFullPath(Path.Combine(exportParameters.OutputDirectory, exportParameters.FileRecord.Name + exportParameters.FileExtension));

            File.WriteAllBytes(outputPath, scriptCompiledBytecode.Resource.AssemblyBytes);

            exportParameters.OnProgressReport?.Invoke(exportParameters.FileRecord, 0);
        }
コード例 #2
0
        public void TestConstructBytes()
        {
            foreach (var testData in Tests)
            {
                var filebytes = File.ReadAllBytes(testData.CompressedFilePath);

                var resource = ScriptCompiledBytecodeResource.Create(testData.RecordInfo.VersionHash);
                resource.InitFromRawCompressed(filebytes);

                var expectedAssemblyBytes = File.ReadAllBytes(testData.AssemblyPath);
                Assert.AreEqual(resource.Resource.ScriptSourceTextPath, testData.ExpectedAssemblyPath);
                Assert.AreEqual(resource.Resource.AssemblyBytes, expectedAssemblyBytes);
            }
        }
コード例 #3
0
        public void TestConstructCompressedStream()
        {
            foreach (var testData in Tests)
            {
                var compressedFileBytes = File.ReadAllBytes(testData.CompressedFilePath);

                using (var ms = new MemoryStream(compressedFileBytes))
                {
                    var resource = ScriptCompiledBytecodeResource.Create(testData.RecordInfo.VersionHash);
                    resource.InitFromStream(ms);

                    var expectedAssemblyBytes = File.ReadAllBytes(testData.AssemblyPath);
                    Assert.AreEqual(resource.Resource.ScriptSourceTextPath, testData.ExpectedAssemblyPath);
                    Assert.AreEqual(resource.Resource.AssemblyBytes, expectedAssemblyBytes);
                }
            }
        }
コード例 #4
0
        public void TestConstructFileInfo()
        {
            foreach (var testData in Tests)
            {
                var fileStream = File.OpenRead(testData.CompressedFilePath);
                var fileRecord = new FileRecord
                {
                    Length      = (uint)fileStream.Length,
                    Info        = null,
                    Offset      = 0,
                    TimestampNs = 0,
                    Name        = "File Record"
                };

                var resource = ScriptCompiledBytecodeResource.Create(testData.RecordInfo.VersionHash);
                resource.InitFromRecord(fileStream, fileRecord);

                var expectedAssemblyBytes = File.ReadAllBytes(testData.AssemblyPath);
                Assert.AreEqual(resource.Resource.ScriptSourceTextPath, testData.ExpectedAssemblyPath);
                Assert.AreEqual(resource.Resource.AssemblyBytes, expectedAssemblyBytes);
            }
        }