Esempio n. 1
0
        private void FullSerializeAndDeserialize()
        {
            // use the sample data to fake a project
            var sampleProject = new Project {
                Data = SampleRomData.SampleData
            };

            // extract the bytes that would normally be in the SMC file (they only exist in code for this sample data)
            var romFileBytes = sampleProject.Data.GetFileBytes();

            // save it to create an output byte stream, we'd normally write this to the disk
            var serializer  = new ProjectXmlSerializer();
            var outputBytes = serializer.Save(sampleProject);

            // now do the reverse and load our output back as the input
            var(deserializedProject, warning) = serializer.Load(outputBytes);

            // final step, the loading process doesn't save the actual SMC file bytes, so we do it ourselves here
            deserializedProject.Data.CopyRomDataIn(romFileBytes);

            // now we can do a full compare between the original project, and the project which has been cycled through
            // serialization and deserialization
            Assert.True(warning == "");
            Assert.True(sampleProject.Equals(deserializedProject));
        }
        private void FullSerializeAndDeserialize()
        {
            // use the sample data to fake a project
            var srcProject = BuildSampleProject2();

            var expectedTitle = SampleRomData.GetSampleUtf8CartridgeTitle();

            srcProject.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Comment>().Should().BeGreaterThan(0);
            srcProject.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Label>().Should().BeGreaterThan(0);

            // extract the bytes that would normally be in the SMC file (they only exist in code for this sample data)
            var romFileBytes = srcProject.Data.RomByteSource.Bytes.Select(e => e?.Byte ?? 0).ToList().ToList();

            // save it to create an output byte stream, we'd normally write this to the disk
            var serializer  = new ProjectXmlSerializer();
            var outputBytes = serializer.Save(srcProject);

            // now do the reverse and load our output back as the input
            var(deserializedProject, warning) = serializer.Load(outputBytes);

            // final step, the loading process doesn't save the actual SMC file bytes, so we do it ourselves here
            deserializedProject.Project.Data.RomByteSource.SetBytesFrom(romFileBytes);

            // now we can do a full compare between the original project, and the project which has been cycled through
            // serialization and deserialization
            Assert.True(warning == "");
            Assert.True(srcProject.Equals(deserializedProject.Project));

            deserializedProject.Project.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Comment>().Should().BeGreaterThan(0);
            deserializedProject.Project.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Label>().Should().BeGreaterThan(0);

            CartNameTests.TestRomCartTitle(deserializedProject.Project, expectedTitle);
        }
Esempio n. 3
0
 public XmlSerializerService()
 {
     _projectXmlSerializer = new ProjectXmlSerializer <XmlDocumentRoot>();
     _xmlDocumentService   = new XmlDocumentService();
     _studentService       = new StudentService();
     _fileService          = new FileService();
 }
Esempio n. 4
0
        public void Save(Project project, string filename)
        {
            // Everything saves in XML format from here on out.
            // Binary format is deprecated.
            ProjectSerializer defaultSerializer = new ProjectXmlSerializer();

            Save(project, filename, defaultSerializer);
        }
        private void SaveFilePerformanceTest()
        {
            var openFile = "INSERT YOUR FILE HERE BEFORE RUNNING THIS TEST.dizraw";
            var project  = OpenProject(openFile);

            var s = Stopwatch.StartNew();

            var data = new ProjectXmlSerializer().Save(project);

            s.Stop();

            Assert.True(data.Length != 0);

            output.WriteLine($"runtime: {s.ElapsedMilliseconds:N0}");
        }