Ejemplo n.º 1
0
        public void Reading_Invalid_Imml_Results_In_A_MarkupException()
        {
            var immlString = "<IMML Author=\"craigomatic\" Camera=\"Camera\" xmlns=\"http://schemas.vastpark.com/2007/imml/\"><THis is invalid IMML></IMML>";
            var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(immlString));

            var immlSerialiser = new ImmlSerialiser();

            try
            {
                var document = immlSerialiser.Read<ImmlDocument>(stream);
                Assert.True(false); //fail
            }
            catch (MarkupException)
            {
                Assert.True(true); //pass
            }
        }
Ejemplo n.º 2
0
        private async void _OpenFile()
        {
            if (!ApplicationView.TryUnsnap())
            {
                //TODO: handle problem
            }

            var openPicker = new FileOpenPicker();
            openPicker.FileTypeFilter.Add(".imml");
            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

            var file = await openPicker.PickSingleFileAsync();

            if (file != null)
            {
                var serialiser = new ImmlSerialiser();
                var immlDocument = await serialiser.Read<ImmlDocument>(file);

                App.ViewModel.SelectedDocument = new ImmlDocumentViewModel(immlDocument);

                _ContextRenderer.Clear();

                var node = new ImmlDocumentSceneNode();
                node.Initialise(immlDocument, _DeviceManager);

                _ContextRenderer.Add(node);

                //TODO: refactor this out somewhere
                var nestedElements = immlDocument.Elements.AsRecursiveEnumerable();

                foreach (var element in nestedElements)
                {
                    if (element is Primitive)
                    {
                        var nestedNode = new PrimitiveSceneNode();
                        nestedNode.Initialise(element, _DeviceManager);

                        _ContextRenderer.Add(nestedNode);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Serialiser_Can_Read_From_A_Stream()
        {
            var immlString = "<IMML Author=\"craigomatic\" Camera=\"Camera\" xmlns=\"http://schemas.vastpark.com/2007/imml/\"><Camera Name=\"Camera\" Position=\"0,0,-5\" /><Primitive Type=\"Box\" Size=\"1,1,1\" /></IMML>";
            var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(immlString));

            var immlSerialiser = new ImmlSerialiser();
            var document = immlSerialiser.Read<ImmlDocument>(stream);

            Assert.NotNull(document);
            Assert.Equal(2, document.Elements.Count);
        }
Ejemplo n.º 4
0
        public void Serialiser_Reports_An_Error_When_A_Minor_Validation_Problem_Is_Encountered()
        {
            //the camera position attribute is invalid
            var immlString = "<IMML Author=\"craigomatic\" Camera=\"Camera\" xmlns=\"http://schemas.vastpark.com/2007/imml/\"><Camera Name=\"Camera\" Position=\"5\" /><Primitive Type=\"Box\" Size=\"1,1,1\" /></IMML>"; ;

            var immlSerialiser = new ImmlSerialiser();
            immlSerialiser.Read<ImmlDocument>(new MemoryStream(Encoding.UTF8.GetBytes(immlString)));

            Assert.NotEmpty(immlSerialiser.Errors);
            Assert.Equal(1, immlSerialiser.Errors.Count);
        }
Ejemplo n.º 5
0
        public void Serialiser_Does_Not_Report_Errors_When_The_IMML_Is_Valid()
        {
            var immlString = "<IMML Author=\"craigomatic\" Camera=\"Camera\" xmlns=\"http://schemas.vastpark.com/2007/imml/\"><Camera Name=\"Camera\" Position=\"5,5,5\" /><Primitive Type=\"Box\" Size=\"1,1,1\" /></IMML>"; ;

            var immlSerialiser = new ImmlSerialiser();
            immlSerialiser.Read<ImmlDocument>(new MemoryStream(Encoding.UTF8.GetBytes(immlString)));

            Assert.Empty(immlSerialiser.Errors);
        }
Ejemplo n.º 6
0
        public void Serialiser_Creates_Object_Instances_For_All_Elements_Contained_Within_A_Document()
        {
            var bytes = EmbeddedResourceHelper.GetBytes("Imml.Test.Samples.Sample1.gz", System.Reflection.Assembly.GetExecutingAssembly());

            //unzip to get to the imml sample
            var decompressed = new MemoryStream(Ionic.Zlib.GZipStream.UncompressBuffer(bytes));
            var immlSerialiser = new ImmlSerialiser();
            var document = immlSerialiser.Read<ImmlDocument>(decompressed);

            Assert.NotEmpty(document.Elements);

            //TODO: improve the assertions to do as the method name suggests
        }
Ejemplo n.º 7
0
        public void Serialiser_Correctly_Reads_IMML_Containing_Script_Elements()
        {
            var immlString = "<Script Language=\"Lua\" Name=\"Script\" Source=\"\" xmlns=\"http://schemas.vastpark.com/2007/imml/\">function main(obj, args)\r\nend</Script>";
            var immlSerialiser = new ImmlSerialiser();
            var script = immlSerialiser.Read<Script>(new MemoryStream(Encoding.UTF8.GetBytes(immlString)));

            Assert.Contains("function main(obj, args)", script.Value);
        }
Ejemplo n.º 8
0
        public void Serialiser_Can_Read_Strings_From_Disk()
        {
            var tmpFile = System.IO.Path.GetTempFileName();
            var immlString = "<IMML Author=\"craigomatic\" Camera=\"Camera\" xmlns=\"http://schemas.vastpark.com/2007/imml/\"><Camera Name=\"Camera\" Position=\"0,0,-5\" /><Primitive Type=\"Box\" Size=\"1,1,1\" /></IMML>";

            try
            {
                System.IO.File.WriteAllText(tmpFile, immlString);

                var immlSerialiser = new ImmlSerialiser();
                var document = immlSerialiser.Read<ImmlDocument>(tmpFile);

                Assert.NotNull(document);
                Assert.Equal(2, document.Elements.Count);
            }
            finally
            {
                System.IO.File.Delete(tmpFile);
            }
        }