public void SaveCollectionData() { //Pull metadata from struct Dictionary <string, string[]> collectionMetadata = new Dictionary <string, string[]>(); string[] collectTitles = DataListToArray(CollectDataHost.CollectionTitle); collectionMetadata.Add("title", collectTitles); // string[] identArray = new string[1]{CollectDataHost.CollectionIdentifier}; //FIXME can't have two 'identifier' keys in the dictionary // collectionMetadata.Add("identifier", identArray); string[] collectCreators = DataListToArray(CollectDataHost.CollectionCreator); collectionMetadata.Add("creator", collectCreators); string[] collectContributors = DataListToArray(CollectDataHost.CollectionContributor); collectionMetadata.Add("contributor", collectContributors); string[] collectDates = DataListToArray(CollectDataHost.CollectionDate); collectionMetadata.Add("date", collectDates); string[] collectCoverage = DataListToArray(CollectDataHost.CollectionCoverage); collectionMetadata.Add("coverage", collectCoverage); string[] collectSubject = DataListToArray(CollectDataHost.CollectionSubject); collectionMetadata.Add("subject", collectSubject); string[] descriptArray = new string[1] { CollectDataHost.CollectionDescription }; collectionMetadata.Add("description", descriptArray); //Create transforms Dictionary <string, VerticeTransform> artefactTransforms = new Dictionary <string, VerticeTransform>(); if (collectionArtefactsParent.childCount > 0) { for (int i = 0; i < collectionArtefactsParent.childCount; i++) { Transform curObjTrans = collectionArtefactsParent.GetChild(i); VerticeTransform curArtefactVerticeTrans = new VerticeTransform(curObjTrans.position, curObjTrans.rotation, curObjTrans.localScale); string curArtefactName = curObjTrans.name; artefactTransforms.Add(curArtefactName, curArtefactVerticeTrans); } } CollectionWriter.WriteCollectionWithIdentifer(CollectDataHost.CollectionIdentifier, collectionMetadata, artefactTransforms); // CollectMenuGuiControl.LoadCollectInfo(CollectDataHost.CollectionIdentifier); }
public void CreateTwoCollectionsWithTwoArtefacts() { for (int i = 0; i < 2; i++) { Dictionary <string, string[]> descriptiveData = new Dictionary <string, string[]> (); Dictionary <string, VerticeTransform> structuralData = new Dictionary <string, VerticeTransform> (); descriptiveData.Add("title", new string[] { "Test Title", "A second title" }); descriptiveData.Add("creator", new string[] { "Test Creator", "A co-creator" }); descriptiveData.Add("date", new string[] { "2016-10-20" }); for (int j = 0; j < 2; j++) { structuralData.Add(String.Format("TEST-ARTEFACT-0{0}", j), new VerticeTransform(Vector3.one, Quaternion.identity, Vector3.one)); } CollectionWriter.WriteCollectionWithIdentifer(String.Format("TEST-COLLECTION-0{0}", i), descriptiveData, structuralData); } }
public void TestSaveLocationChanges() { // Check that, when the save location is changed, the two XML files a) can vary independently, and that b) the second file // is an extension of whatever data existed in the first file (i.e. that, in a sense, operations on the second file are precluded by // all of the operations that had occurred to establish the first file). CollectionWriter.EstablishNewDocument(); // Create some data Dictionary <string, string[]> descriptiveData = new Dictionary <string, string[]>(); Dictionary <string, VerticeTransform> structuralData = new Dictionary <string, VerticeTransform>(); descriptiveData.Add("title", new string[] { "Test Title" }); descriptiveData.Add("creator", new string[] { "Test Creator" }); descriptiveData.Add("date", new string[] { "2016-10-20" }); structuralData.Add("TEST-ARTEFACT-01", new VerticeTransform(Vector3.one, Quaternion.identity, Vector3.one)); // Write data to the first file Paths.CollectionMetadata = Environment.CurrentDirectory + "/Assets/Scripts/Metadata/TestAssets/Collection_Writer_Test.xml"; CollectionWriter.WriteCollectionWithIdentifer("TEST-COLLECTION-01", descriptiveData, structuralData); // Change location and save the new collection Paths.CollectionMetadata = Environment.CurrentDirectory + "/Assets/Scripts/Metadata/TestAssets/Collection_Writer_Test_02.xml"; CollectionWriter.WriteCollectionWithIdentifer("TEST-COLLECTION-02", descriptiveData, structuralData); // Check that the first file has only one collection CollectionReader.LoadXmlFromFile(Environment.CurrentDirectory + "/Assets/Scripts/Metadata/TestAssets/Collection_Writer_Test.xml"); string[] collectionIdentifiers_01 = CollectionReader.GetIdentifiersForCollections(); Assert.That(collectionIdentifiers_01.Length == 1); // Now check that the second file has two CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); string[] collectionIdentifiers_02 = CollectionReader.GetIdentifiersForCollections(); Assert.That(collectionIdentifiers_02.Length == 2); // Tidy up (the second file will be deleted in TearDown) File.Delete(Environment.CurrentDirectory + "/Assets/Scripts/Metadata/TestAssets/Collection_Writer_Test.xml"); }
public void TestOverwriteCollection() { CreateTwoCollectionsWithTwoArtefacts(); Dictionary <string, string[]> descriptiveData = new Dictionary <string, string[]>(); Dictionary <string, VerticeTransform> structuralData = new Dictionary <string, VerticeTransform>(); descriptiveData.Add("title", new string[] { "Test Overwrite" }); descriptiveData.Add("creator", new string[] { "Test Creator Overwrite" }); descriptiveData.Add("date", new string[] { "2016-10-26" }); structuralData.Add("TEST-ARTEFACT-03", new VerticeTransform(Vector3.one, Quaternion.identity, Vector3.one)); CollectionWriter.WriteCollectionWithIdentifer("TEST-COLLECTION-00", descriptiveData, structuralData); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); Dictionary <string, string[]> collectionMetadata = CollectionReader.GetCollectionMetadataWithIdentifier("TEST-COLLECTION-00"); Assert.That(collectionMetadata ["title"] [0] == "Test Overwrite"); Assert.That(collectionMetadata ["creator"] [0] == "Test Creator Overwrite"); Assert.That(collectionMetadata ["date"] [0] == "2016-10-26"); Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection("TEST-COLLECTION-00", "TEST-ARTEFACT-03"); Assert.That(transformData ["position"] ["x"] == Vector3.one.x); Assert.That(transformData ["position"] ["y"] == Vector3.one.y); Assert.That(transformData ["position"] ["z"] == Vector3.one.z); Assert.That(transformData ["rotation"] ["x"] == Quaternion.identity.x); Assert.That(transformData ["rotation"] ["y"] == Quaternion.identity.y); Assert.That(transformData ["rotation"] ["z"] == Quaternion.identity.z); Assert.That(transformData ["rotation"] ["w"] == Quaternion.identity.w); Assert.That(transformData ["scale"] ["x"] == Vector3.one.x); Assert.That(transformData ["scale"] ["y"] == Vector3.one.y); Assert.That(transformData ["scale"] ["z"] == Vector3.one.z); }
public void TestWriteCollectionData_OneToOne() { // Test that a collection whose descriptive elements are non-repeating write correctly Dictionary <string, string[]> descriptiveData = new Dictionary <string, string[]>(); Dictionary <string, VerticeTransform> structuralData = new Dictionary <string, VerticeTransform>(); descriptiveData.Add("title", new string[] { "Test Title" }); descriptiveData.Add("creator", new string[] { "Test Creator" }); descriptiveData.Add("date", new string[] { "2016-10-20" }); structuralData.Add("TEST-ARTEFACT-01", new VerticeTransform(Vector3.one, Quaternion.identity, Vector3.one)); CollectionWriter.WriteCollectionWithIdentifer("TEST-COLLECTION-01", descriptiveData, structuralData); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); Dictionary <string, string[]> collectionMetadata = CollectionReader.GetCollectionMetadataWithIdentifier("TEST-COLLECTION-01"); Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection("TEST-COLLECTION-01", "TEST-ARTEFACT-01"); Assert.That(collectionMetadata ["title"] [0] == "Test Title"); Assert.That(collectionMetadata ["creator"] [0] == "Test Creator"); Assert.That(collectionMetadata ["date"] [0] == "2016-10-20"); Assert.That(transformData ["position"] ["x"] == Vector3.one.x); Assert.That(transformData ["position"] ["y"] == Vector3.one.y); Assert.That(transformData ["position"] ["z"] == Vector3.one.z); Assert.That(transformData ["rotation"] ["x"] == Quaternion.identity.x); Assert.That(transformData ["rotation"] ["y"] == Quaternion.identity.y); Assert.That(transformData ["rotation"] ["z"] == Quaternion.identity.z); Assert.That(transformData ["rotation"] ["w"] == Quaternion.identity.w); Assert.That(transformData ["scale"] ["x"] == Vector3.one.x); Assert.That(transformData ["scale"] ["y"] == Vector3.one.y); Assert.That(transformData ["scale"] ["z"] == Vector3.one.z); }