public ICollectionReader ExecuteReader(string queryText, ICollection<IParameter> parameters) { if (string.IsNullOrEmpty(queryText)) throw new ArgumentNullException("queryText can not be null or empty string"); if (typeof(T) == typeof(IJSONDocument) || typeof(T) == typeof(JSONDocument)) { Type type; if (!JsonDocumentUtil.IsSupportedParameterType(parameters, out type)) { throw new ArgumentException(string.Format("Type {0} is not supported on Collection<JSONDocument>", type), "parameters"); } } Query query = new Query(); query.QueryText = queryText; query.Parameters = parameters.Cast<IParameter>().ToList(); ReadQueryOperation readQueryOperation = new ReadQueryOperation(); readQueryOperation.Database = _database.DatabaseName; readQueryOperation.Collection = _collectionName; readQueryOperation.Query = query; ReadQueryResponse readQueryResponse = (ReadQueryResponse)_database.ExecutionMapper.ExecuteReader(readQueryOperation); if (!readQueryResponse.IsSuccessfull) { if (readQueryResponse.ErrorParams != null && readQueryResponse.ErrorParams.Length > 0) throw new Exception(string.Format("Operation failed Error: " + Common.ErrorHandling.ErrorMessages.GetErrorMessage(readQueryResponse.ErrorCode, readQueryResponse.ErrorParams))); throw new Exception("Operation failed Error: " + Common.ErrorHandling.ErrorMessages.GetErrorMessage(readQueryResponse.ErrorCode)); } CollectionReader reader = new CollectionReader((DataChunk)readQueryResponse.DataChunk, _database.ExecutionMapper, _database.DatabaseName, _collectionName); return reader; }
public void TestWriteCollectionData_ManyCollectionsManyArtefacts() { // Test the typical use case for the CollectionWriter CreateTwoCollectionsWithTwoArtefacts(); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); for (int i = 0; i < 2; i++) { Dictionary <string, string[]> collectionMetadata = CollectionReader.GetCollectionMetadataWithIdentifier(String.Format("TEST-COLLECTION-0{0}", i)); Assert.That(collectionMetadata ["title"] [0] == "Test Title"); Assert.That(collectionMetadata ["title"] [1] == "A second title"); Assert.That(collectionMetadata ["creator"] [0] == "Test Creator"); Assert.That(collectionMetadata ["creator"] [1] == "A co-creator"); Assert.That(collectionMetadata ["date"] [0] == "2016-10-20"); for (int j = 0; j < 2; j++) { Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection(String.Format("TEST-COLLECTION-0{0}", i), String.Format("TEST-ARTEFACT-0{0}", j)); 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); } } }
/// <summary> /// Places artefact at one of the instance points defined in Editor /// </summary> /// <param name="instantNumber">Instantiation number to place artefact at</param> /// <param name="browseArtefact">Artefact to place</param> private void PlaceArtefact(int instantNumber, GameObject collectArtefact) { Dictionary <string, Dictionary <string, float> > transInfo; VerticeTransform VertTrans; try { transInfo = CollectionReader.GetTransformForArtefactWithIdentifierInCollection(collectionId, collectArtefact.name); VertTrans = new VerticeTransform(transInfo); } catch (System.Exception ex) { transInfo = null; VertTrans = new VerticeTransform(loadPlaneBoxCol.bounds.min.x, loadPlaneBoxCol.bounds.max.x, loadPlaneBoxCol.bounds.min.z, loadPlaneBoxCol.bounds.max.z); Debug.Log("No pos info available, random assignment"); Debug.Log("Random pos: " + VertTrans.position.x + " " + VertTrans.position.y + " " + VertTrans.position.z); } Instantiate(particleLocator, collectArtefact.transform); collectArtefact.transform.position = VertTrans.position;; Rigidbody rb = collectArtefact.AddComponent <Rigidbody> (); rb.mass = 3; collectArtefact.GetComponent <MeshRenderer>().enabled = true; ProgressBarCont.AddTask("Placing " + collectArtefact.name); }
public ICollectionReader GetDocuments(ICollection<string> documentKeys) { if (documentKeys == null) throw new ArgumentNullException("documentKeys"); if (documentKeys.Count < 1) throw new ArgumentException("No DocumentKey specified"); List<JSONDocument> documents = new List<JSONDocument>(); foreach (string documentKey in documentKeys) { if (documentKey != null) { JSONDocument jdoc = new JSONDocument(); jdoc.Key = documentKey; documents.Add(jdoc); } } GetDocumentsOperation getDocumentsOperation = new GetDocumentsOperation(); getDocumentsOperation.DocumentIds = documents.Cast<IJSONDocument>().ToList(); getDocumentsOperation.Database = _database.DatabaseName; getDocumentsOperation.Collection = _collectionName; GetDocumentsResponse getDocumentsResponse = (GetDocumentsResponse)_database.ExecutionMapper.GetDocuments(getDocumentsOperation); if (getDocumentsResponse.IsSuccessfull) { CollectionReader reader = new CollectionReader((DataChunk)getDocumentsResponse.DataChunk, _database.ExecutionMapper, _database.DatabaseName, _collectionName); return reader; } else throw new Exception("Operation failed Error: " + Common.ErrorHandling.ErrorMessages.GetErrorMessage(getDocumentsResponse.ErrorCode, getDocumentsResponse.ErrorParams)); }
public void GetCollections() { string[] collectIdentifiers = CollectionReader.GetIdentifiersForCollections(); for (int i = 0; i < collectIdentifiers.Length; i++) { InstantCollectButton(collectIdentifiers[i]); } }
public void DownloadXmlFile() { WWW www = new WWW(url); while (!www.isDone) { } CollectionReader.LoadXmlFromText(www.text); }
public void GetIdentifiersForArtefactsInCollectionWithIdentifier() { string[] collectionIdentifiers = CollectionReader.GetIdentifiersForCollections(); string[] artefactIdentifiers = CollectionReader.GetIdentifiersForArtefactsInCollectionWithIdentifier(collectionIdentifiers[0]); Assert.That(artefactIdentifiers[0] == "Evans Bay Wharf"); Assert.That(artefactIdentifiers[1] == "Cog Wheel Evans Bay"); Assert.That(artefactIdentifiers[2] == "Evans Boat House"); Assert.That(artefactIdentifiers[3] == "Cricket Monument"); Assert.That(artefactIdentifiers[4] == "Doll Head"); }
void Start() { // Upon creating this object, download the relevant XML data and use it to prepare the CollectionReader #if UNITY_WEBGL StartCoroutine(DownloadXml(Paths.CollectionMetadata)); #elif UNITY_STANDALONE Debug.Log("Will load from " + Paths.CollectionMetadata); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); GetCollections(); #endif }
public void TestGetIdentifiersForCollections() { string[] collectionIdentifiers = CollectionReader.GetIdentifiersForCollections(); Assert.That(collectionIdentifiers[0] == "P14C3H01D3R-00"); Assert.That(collectionIdentifiers[1] == "P14C3H01D3R-01"); Assert.That(collectionIdentifiers[2] == "P14C3H01D3R-02"); Assert.That(collectionIdentifiers[3] == "P14C3H01D3R-03"); Assert.That(collectionIdentifiers[4] == "P14C3H01D3R-04"); Assert.That(collectionIdentifiers[5] == "P14C3H01D3R-05"); }
void Start() { // Upon creating this object, download the relevant XML data and use it to prepare the CollectionReader #if UNITY_WEBGL // StartCoroutine (DownloadXml (Paths.Local + "/Vertice_CollectionInformation.xml")); StartCoroutine(DownloadXml(Paths.CollectionMetadata)); #else Debug.Log("Will load from " + Paths.CollectionMetadata); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); GetCollections(); #endif }
public void GetCollectionMetadataWithIdentifier() { string[] collectionIdentifiers = CollectionReader.GetIdentifiersForCollections(); Dictionary <string, string[]> collectionMetadata = CollectionReader.GetCollectionMetadataWithIdentifier(collectionIdentifiers [0]); Assert.That(collectionMetadata ["identifier"] [0] == collectionIdentifiers [0]); Assert.That(collectionMetadata ["title"][0] == "Photogrammetry Test Scans"); Assert.That(collectionMetadata ["creator"][0] == "Ryan Achten"); Assert.That(collectionMetadata ["date"][0] == "29/11/2015"); Assert.That(collectionMetadata ["description"][0] == "A museum is distinguished by a collection of often unique objects that forms the core of its activities for exhibitions, education, research, etc."); Assert.That(collectionMetadata ["subject"][0] == "Photogrammetry"); Assert.That(collectionMetadata ["coverage"] [0] == "Evan's Bay"); Assert.That(collectionMetadata ["coverage"] [1] == "Basin Reserve"); Assert.That(collectionMetadata ["extent"] [0] == "5"); }
public void TestAddArtefactToCollection() { CreateTwoCollectionsWithTwoArtefacts(); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); string[] collectionIdentifiers_00 = CollectionReader.GetIdentifiersForArtefactsInCollectionWithIdentifier("TEST-COLLECTION-00"); int numArtefactsBeforeAdd = collectionIdentifiers_00.Length; CollectionWriter.AddArtefactToCollectionWithIdentifier("TEST-COLLECTION-00", "NEW-ARTEFACT", new VerticeTransform(0f, 0f, 0f, 0f)); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); string[] updated_collectionIdentifiers_00 = CollectionReader.GetIdentifiersForArtefactsInCollectionWithIdentifier("TEST-COLLECTION-00"); int numArtefactsAfterAdd = updated_collectionIdentifiers_00.Length; Assert.That(numArtefactsAfterAdd == (numArtefactsBeforeAdd + 1)); }
private void GetIdentifiers(string collectId) { collectionId = collectId; string[] collectionIdentifiers = CollectionReader.GetIdentifiersForArtefactsInCollectionWithIdentifier(collectId); importedObjects = new GameObject[collectionIdentifiers.Length]; progressBar.SetActive(true); ProgressBarCont.SetMaxVal(collectionIdentifiers.Length * 2); for (int i = 0; i < collectionIdentifiers.Length; i++) { string meshLocation = Paths.PathToFile(DublinCoreReader.GetMeshLocationForArtefactWithIdentifier(collectionIdentifiers [i])); string texLocation = Paths.PathToFile(DublinCoreReader.GetTextureLocationForArtefactWithIdentifier(collectionIdentifiers [i])); StartCoroutine(ImportModel(i, collectionIdentifiers[i], meshLocation, texLocation)); } }
public void GetTransformForArtefactWithIdentifierInCollection() { Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection("P14C3H01D3R-00", "Evans Bay Wharf"); Assert.That(transformData ["position"] ["x"] == 40.01599f); Assert.That(transformData ["position"] ["y"] == -11.58916f); Assert.That(transformData ["position"] ["z"] == 184.2516f); Assert.That(transformData ["rotation"] ["x"] == 1.0f); Assert.That(transformData ["rotation"] ["y"] == 1.0f); Assert.That(transformData ["rotation"] ["z"] == 1.0f); Assert.That(transformData ["rotation"] ["w"] == 1.0f); Assert.That(transformData ["scale"] ["x"] == 1.0f); Assert.That(transformData ["scale"] ["y"] == 1.0f); Assert.That(transformData ["scale"] ["z"] == 1.0f); }
private void InstantCollectButton(string collectID) { GameObject curCollectButton = Instantiate(collectButtonPrefab, instantParent) as GameObject; curCollectButton.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f); Dictionary <string, string[]> data = CollectionReader.GetCollectionMetadataWithIdentifier(collectID); // Debug.Log("****Debug Test****"); // foreach (KeyValuePair<string, string[]> kvp in data) { // Debug.Log("Data key: " + kvp.Key); // for (int i = 0; i < kvp.Value.Length; i++) { // Debug.Log(kvp.Key +": " + kvp.Value[i]); // } // } string[] collectData = new string[5]; try { collectData[0] = data["title"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[0] = ""; } try { collectData[1] = collectID; // collectData[1] = data["Identifier"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[1] = ""; } try { collectData[2] = data["creator"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[2] = ""; } try { collectData[3] = data["date"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[3] = ""; } try { collectData[4] = data["description"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[4] = ""; } curCollectButton.GetComponent <Collect_LoadCollectButtonInfo>().LoadInfo(collectData); }
/// <summary> /// Download an XML file from a specified URL and populate a CollectionReader with the contents of the /// XML file /// </summary> /// <param name="url">The absolute path to the XML file, with the scheme (e.g. file://, http://, etc.) </param> IEnumerator DownloadXml(string url) { Debug.Log("Downloading some XML from " + url); UnityWebRequest www = UnityWebRequest.Get(url); yield return(www.Send()); if (www.isError) { // TODO: Echo the error condition to the user Debug.Log("Couldn't download XML file at " + url + "\n" + www.error); } else { CollectionReader.LoadXmlFromText(www.downloadHandler.text); Debug.Log("Downloaded some XML from " + url); GetCollections(); } }
static public void LoadXmlData(string collectionId) { Dictionary <string, string[]> data = new Dictionary <string, string[]>(); data = new Dictionary <string, string[]>(); data = CollectionReader.GetCollectionMetadataWithIdentifier(collectionId); CollectionTitle = CreateStructList("title", data); CollectionIdentifier = collectionId; CollectionCreator = CreateStructList("creator", data); CollectionContributor = CreateStructList("contributor", data); CollectionDate = CreateStructList("date", data); CollectionCoverage = CreateStructList("coverage", data); CollectionSubject = CreateStructList("subject", data); try { CollectionDescription = data["description"][0]; } catch (KeyNotFoundException e) { CollectionDescription = ""; } }
public void TestInstantiateWithCollectionReaderDictionary() { // Get the list of collection identifiers, and subsequently the list of artefact identifiers for the first collection string[] collectionIdentifiers = CollectionReader.GetIdentifiersForCollections(); string[] artefactIdentifiers = CollectionReader.GetIdentifiersForArtefactsInCollectionWithIdentifier(collectionIdentifiers [0]); // Now get the transform data for the first artefact in the first collection, and attempt to construct a VerticeTransform with the data Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection(collectionIdentifiers [0], artefactIdentifiers [0]); VerticeTransform transform = new VerticeTransform(transformData); Assert.That(transform.position.x == 40.01599f); Assert.That(transform.position.y == -11.58916f); Assert.That(transform.position.z == 184.2516f); Assert.That(transform.rotation.x == 1.0f); Assert.That(transform.rotation.y == 1.0f); Assert.That(transform.rotation.z == 1.0f); Assert.That(transform.rotation.w == 1.0f); Assert.That(transform.scale.x == 1.0f); Assert.That(transform.scale.y == 1.0f); Assert.That(transform.scale.z == 1.0f); }
/// <summary> /// Writes the built XML document to a file /// </summary> /// <param name="filePath">The file path to write to</param> static void WriteXmlToFile() { XmlWriter writer = null; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; try { writer = XmlWriter.Create(Paths.CollectionMetadata, settings); _xmlDocument.WriteTo(writer); writer.Flush(); } finally { if (writer != null) { writer.Close(); CollectionReader.LoadXmlFromFile(Paths.CollectionMetadata); } } }
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 ICollectionReader ExecuteReader(string queryText, ICollection <IParameter> parameters) { if (string.IsNullOrEmpty(queryText)) { throw new ArgumentException("value can not be null or empty string.", "queryText"); } Query query = new Query(); query.QueryText = queryText; query.Parameters = (List <IParameter>)parameters; ReadQueryOperation readQueryOperation = new ReadQueryOperation(); readQueryOperation.Database = _databaseName; //Collection Name Cannot be null(Protobuf) readQueryOperation.Collection = ""; readQueryOperation.Query = query; ReadQueryResponse readQueryResponse = (ReadQueryResponse)this.ExecutionMapper.ExecuteReader(readQueryOperation); if (readQueryResponse.IsSuccessfull) { //TODO ReadQueryResponse must have Collection Name or server must share collection name becuse it is needed for // GetNextChunk and CloseDataChunk operations CollectionReader reader = new CollectionReader((DataChunk)readQueryResponse.DataChunk, this.ExecutionMapper, this.DatabaseName, readQueryOperation.Collection); return(reader); } else if (readQueryResponse.ErrorParams != null && readQueryResponse.ErrorParams.Length > 0) { throw new Exception(string.Format("Operation failed Error: " + Common.ErrorHandling.ErrorMessages.GetErrorMessage(readQueryResponse.ErrorCode, readQueryResponse.ErrorParams))); } throw new Exception("Operation failed Error: " + Common.ErrorHandling.ErrorMessages.GetErrorMessage(readQueryResponse.ErrorCode)); }
private void InstantCollectButton(string collectID) { GameObject curCollectButton = Instantiate(collectButtonPrefab, instantParent) as GameObject; curCollectButton.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f); Dictionary <string, string[]> data = CollectionReader.GetCollectionMetadataWithIdentifier(collectID); string[] collectData = new string[5]; try { collectData[0] = data["title"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[0] = ""; } try { collectData[1] = data["identifier"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[1] = ""; } try { collectData[2] = data["creator"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[2] = ""; } try { collectData[3] = data["date"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[3] = ""; } try { collectData[4] = data["description"][0]; //grabs first title for collection button } catch (System.Exception ex) { collectData[4] = ""; } curCollectButton.GetComponent <Browse_AddToCollectButtonInfo>().LoadInfo(collectData); }
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); }
public void GetTransformForArtefactWithIdentifierInCollection_IncompleteTransform() { Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection("P14C3H01D3R-00", "Cog Wheel Evans Bay"); }
public void GetIdentifiersForArtefactsInCollectionWithIdentifier_Invalid() { string[] artefactIdentifiers = CollectionReader.GetIdentifiersForArtefactsInCollectionWithIdentifier("THIS IS NOT A REAL COLLECTION ID"); }
internal override void Run() { int collectionItterated = 1; LoggerManager.Instance.SetThreadContext(new LoggerContext() { ShardName = _context.LocalShardName != null ? _context.LocalShardName : "", DatabaseName = Database != null ? Database : "" }); try { IDatabaseStore dbInstance = _context.DatabasesManager.GetDatabase(Database); foreach (string _collection in Collections) { if (((Storage.DatabaseStore)dbInstance).Collections.ContainsKey(_collection)) { //Add custom object Query defaultQuery = new Query(); defaultQuery.QueryText = "Select * from "; //M_Note: precausion used incase user goes bonkers whilst naming his collections if (_collection.Contains("\"")) { defaultQuery.QueryText += "$" + _collection + "$"; } else { defaultQuery.QueryText += "\"" + _collection + "\""; } ReadQueryOperation readQueryOperation = new ReadQueryOperation(); readQueryOperation.Database = Database.ToString(); readQueryOperation.Collection = _collection; readQueryOperation.Query = defaultQuery; ArrayList docList = new ArrayList(); long currentSize = 0; DataSlice _activeSlice = PersistenceManager.ActiveContext.GetBackupFile(Database).CreateNewDataSlice(); _activeSlice.SliceHeader.Collection = _collection; _activeSlice.SliceHeader.Database = Database; _activeSlice.SliceHeader.Cluster = Cluster; _activeSlice.SliceHeader.ContentType = DataSliceType.Data; try { ReadQueryResponse readQueryResponse = (ReadQueryResponse)dbInstance.ExecuteReader(readQueryOperation); if (readQueryResponse.IsSuccessfull) { _dbReader = new CollectionReader((DataChunk)readQueryResponse.DataChunk, _context.TopologyImpl, Database, _collection); //create data slice to be written in the common queue while (_dbReader != null && _dbReader.ReadNext() && _dbReader.GetDocument() != null) { //get document and create chunk and add to shared storage IJSONDocument _doc = _dbReader.GetDocument(); // verify size if (currentSize + _doc.Size <= _activeSlice.Capcity) { docList.Add(_doc); currentSize += _doc.Size + 2;// Hack to accomodate the 2 bytes serialization is going add } else { DataSlice _nxtSlice = PersistenceManager.ActiveContext.GetBackupFile(Database).CreateNewDataSlice(); _nxtSlice.SliceHeader.Collection = _collection; _nxtSlice.SliceHeader.Database = Database; _nxtSlice.SliceHeader.Cluster = Cluster; _nxtSlice.SliceHeader.ContentType = DataSliceType.Data; _activeSlice.Data = CompactBinaryFormatter.ToByteBuffer(docList, string.Empty); _activeSlice.SliceHeader.DataCount = docList.Count; _activeSlice.SliceHeader.TotalSize = _activeSlice.Data.LongLength; // Add to shared queue PersistenceManager.SharedQueue.Add(_activeSlice); _activeSlice = _nxtSlice; docList.Clear(); docList.Add(_doc); currentSize = 0; currentSize += _doc.Size; } } _dbReader.Dispose(); // write final data set if (docList.Count > 0) { _activeSlice.Data = CompactBinaryFormatter.ToByteBuffer(docList, string.Empty); _activeSlice.SliceHeader.DataCount = docList.Count; _activeSlice.SliceHeader.TotalSize = _activeSlice.Data.LongLength; // Add to shared queue PersistenceManager.SharedQueue.Add(_activeSlice); docList.Clear(); } // submit status ExecutionStatus.Status = RecoveryStatus.Executing; ExecutionStatus.PercentageExecution = (collectionItterated / Collections.Count);//[M_NOTE] rudementary logic, change this ExecutionStatus.MessageTime = DateTime.Now; ExecutionStatus.Message = "Completed Backup of " + Database + "_" + _collection + " : " + _collection; collectionItterated++; if (ProgressHandler != null) { ProgressHandler.SubmitRecoveryState(ExecutionStatus); } } else { throw new Exception("Operation failed Error code: " + readQueryResponse.ErrorCode); } } catch (Exception ex) { if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled) { LoggerManager.Instance.RecoveryLogger.Error("DatabaseBackupJob.Run()", Database + " : " + ex.ToString()); } collectionItterated--; } } } // Add command slice DataSlice finalSlice = new DataSlice(999999); finalSlice.SliceHeader.Collection = "Complete"; finalSlice.SliceHeader.Database = Database; finalSlice.SliceHeader.Cluster = Cluster; finalSlice.SliceHeader.ContentType = DataSliceType.Command; finalSlice.Data = CompactBinaryFormatter.ToByteBuffer("Data_Complete_Adding", string.Empty); PersistenceManager.SharedQueue.Add(finalSlice); while (!PersistenceManager.SharedQueue.Consumed) { // wait till all data has been consumed and written //M_TODO: // Add timeout interval for file writing, incase the data is not being consumed and timeout span has been reached, break the loop and DIE!!! } if (PersistenceManager.SharedQueue.Consumed) { // submit status ExecutionStatus.Status = RecoveryStatus.Completed; ExecutionStatus.PercentageExecution = 1;//[M_NOTE] rudementary logic, change this ExecutionStatus.MessageTime = DateTime.Now; ExecutionStatus.Message = "Completed Backup of " + Database; } else { // submit status ExecutionStatus.Status = RecoveryStatus.Failure; ExecutionStatus.PercentageExecution = (collectionItterated / Collections.Count);//[M_NOTE] rudementary logic, change this ExecutionStatus.MessageTime = DateTime.Now; ExecutionStatus.Message = "Failed Backup of " + Database; } if (ProgressHandler != null) { System.Threading.Tasks.Task.Factory.StartNew(() => ProgressHandler.SubmitRecoveryState(ExecutionStatus)); } if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsInfoEnabled) { LoggerManager.Instance.RecoveryLogger.Info("DatabaseBackupJob.Run()", Database + "Completed"); } } catch (ThreadAbortException) { if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsDebugEnabled) { LoggerManager.Instance.RecoveryLogger.Debug("DatabaseBackupJob.Run()", "Thread stopped"); } Thread.ResetAbort(); } catch (Exception exp) { if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled) { LoggerManager.Instance.RecoveryLogger.Error("DatabaseBackupJob.Run()", Database + " : " + exp.ToString()); } ExecutionStatus.Status = RecoveryStatus.Failure; ExecutionStatus.PercentageExecution = (collectionItterated / Collections.Count);//[M_NOTE] rudementary logic, change this ExecutionStatus.MessageTime = DateTime.Now; ExecutionStatus.Message = "Failed Backup of " + Database; if (ProgressHandler != null) { System.Threading.Tasks.Task.Factory.StartNew(() => ProgressHandler.SubmitRecoveryState(ExecutionStatus)); } } }
public void ConstructorTest() { // construct a collection reader from a database reader and a collection name _collectionReaderT = new CollectionReader<Entry>(_collectionReader); Assert.IsNotNull(_collectionReader); }
public async void Test() { _databaseConnection.Connect(); ///////////////////////////////////// // OPERATIONAL, CONTEXUAL SCOPE... // ///////////////////////////////////// // create a Writer to write to the database IWriter writer = new Writer(_databaseConnection); // create a Reader to read from the database IReader reader = new Reader(_databaseConnection); // create an Updater to update the database IUpdater updater = new Updater(_databaseConnection); Entry exampleMongoDBEntry = new Entry(); exampleMongoDBEntry.Message = "Hello"; // write the object to the "MyFirstCollection" Collection that exists within the // previously referenced "MyFirstDatabase" that was used to create the "writer" object writer.Write<Entry>("MyFirstCollection", exampleMongoDBEntry); IEnumerable<Entry> readEntrys = reader.Read<Entry>("MyFirstCollection", // within this collection... "Message",// for the object field "Description" "Hello");// return matches for 'Hello' Assert.AreEqual(1, readEntrys.Count()); //////////////////////////////////// // AND ASYNCHRONOUS OPERATIONS... // //////////////////////////////////// // read, write and update asynchronously using System.Threading.Task IAsyncReader asyncReader = new AsyncReader(reader); readEntrys = await asyncReader.ReadAsync<Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); IAsyncWriter asyncWriter = new AsyncWriter(writer); IAsyncUpdater asyncUpdater = new AsyncUpdater(updater); // or delegate call backs IAsyncDelegateReader asyncDelegateReader = new AsyncDelegateReader(reader); asyncDelegateReader.AsyncReadCompleted += new ReadCompletedEvent(readerCallBack); asyncDelegateReader.ReadAsync<Entry>("MyFirstCollection", "Message", "Hello"); _readerAutoResetEvent.WaitOne(); Assert.AreEqual(1, _asyncReadResults.Count()); IAsyncDelegateWriter asyncDelegateWriter = new AsyncDelegateWriter(writer); IAsyncDelegateUpdater asyncDelegateUpdater = new AsyncDelegateUpdater(updater); ///////////////////////////////////////////// // FOR A SERVER, DATABASE OR COLLECTION... // ///////////////////////////////////////////// // get a little higher level with the EasyMongo.Database namespace to target a database for operations IDatabaseReader databaseReader = new DatabaseReader(reader, asyncReader); IDatabaseWriter databaseWriter = new DatabaseWriter(writer, asyncWriter); IDatabaseUpdater databaseUpdater = new DatabaseUpdater(updater, asyncUpdater); // or a little lower level with the EasyMongo.Collection namespace to target a specific Collection ICollectionReader collectionReader = new CollectionReader(databaseReader, "MyFirstCollection"); ICollectionWriter collectionWriter = new CollectionWriter(databaseWriter, "MyFirstCollection"); ICollectionUpdater collectionUpdater = new CollectionUpdater(databaseUpdater, "MyFirstCollection"); /////////////////////////////////////////////// // TO RESTRICT CLIENT SCOPE (LAW OF DEMETER) // /////////////////////////////////////////////// // operate only against "MyFirstDatabase"'s "MySecondCollection" readEntrys = collectionReader.Read<Entry>("Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////// // GENERIC CLASSES // ///////////////////// // Instead of defining generic type arguments at the method level, // you can do it once at the class declaration IWriter<Entry> writerT = new Writer<Entry>(writer); writerT.Write("MySecondCollection", new Entry() { Message = "Goodbye World (Generically)" }); /////////////////////////////// // SIMPLIFY CREATION VIA IoC // /////////////////////////////// // because EasyMongo is a componentized framework built with blocks of functionality, EasyMongo // works great with DI containers and Inversion of Control. // here's an example of using the nuget Ninject extension to load EasyMongo mappings and a conn // string from configuration Ninject.IKernel kernel = new Ninject.StandardKernel(); ICollectionUpdater<Entry> collectionUpdaterT = kernel.TryGet<ICollectionUpdater<Entry>>(); // the alternative to this would be: IServerConnection serverConn = new ServerConnection(LOCAL_MONGO_SERVER_CONNECTION_STRING); IDatabaseConnection databaseConnn = new DatabaseConnection(serverConn, "MyFirstDatabase"); IDatabaseUpdater databaseUpdatr = new DatabaseUpdater(updater, asyncUpdater); ICollectionUpdater collectionUpdaterTheHardWay = new CollectionUpdater(databaseUpdater, "MySecondCollection"); ///////////////////////// // SIMPLE QUERIES... // ///////////////////////// databaseReader.Read<Entry>("MyFirstCollection", "Message", "Hello"); readEntrys = await databaseReader.ReadAsync<Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////////// // POWERFUL QUERIES... // ///////////////////////// // when more robust querying is needed leverage power of underlying MongoDB driver IMongoQuery IMongoQuery query1 = Query.Matches("Message", new BsonRegularExpression("HE", "i")); IEnumerable<Entry> queryResults = reader.Execute<Entry>("MyFirstCollection", query1); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); ////////////////////// // AND COMBINATIONS // ////////////////////// Entry exampleMongoDBEntry2 = new Entry(); exampleMongoDBEntry2.Message = "Hello Again"; Entry exampleMongoDBEntry3 = new Entry(); exampleMongoDBEntry3.Message = "Goodbye"; writer.Write<Entry>("MyFirstCollection", exampleMongoDBEntry2); writer.Write<Entry>("MyFirstCollection", exampleMongoDBEntry3); // "AND" multiple IMongoQueries... IMongoQuery query2 = Query.Matches("Message", new BsonRegularExpression("Again")); queryResults = reader.ExecuteAnds<Entry>("MyFirstCollection", new []{ query1, query2}); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello Again", queryResults.ElementAt(0).Message); // "OR" multiple IMongoQueries... IMongoQuery query3 = Query.Matches("Message", new BsonRegularExpression("Goo")); queryResults = reader.ExecuteOrs<Entry>("MyFirstCollection", new[] { query1, query2, query3 }); Assert.AreEqual(3, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); Assert.AreEqual("Hello Again", queryResults.ElementAt(1).Message); Assert.AreEqual("Goodbye", queryResults.ElementAt(2).Message); }
public void GetTransformForArtefactWithIdentifierInCollection_InvalidArtefact() { Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection("P14C3H01D3R-00", "NO SUCH ARTEFACT"); }
public void ConstructorTest() { // construct a collection reader from a database reader and a collection name _collectionReaderT = new CollectionReader <Entry>(_collectionReader); Assert.IsNotNull(_collectionReader); }
public async void Test() { _databaseConnection.Connect(); ///////////////////////////////////// // OPERATIONAL, CONTEXUAL SCOPE... // ///////////////////////////////////// // create a Writer to write to the database IWriter writer = new Writer(_databaseConnection); // create a Reader to read from the database IReader reader = new Reader(_databaseConnection); // create an Updater to update the database IUpdater updater = new Updater(_databaseConnection); Entry exampleMongoDBEntry = new Entry(); exampleMongoDBEntry.Message = "Hello"; // write the object to the "MyFirstCollection" Collection that exists within the // previously referenced "MyFirstDatabase" that was used to create the "writer" object writer.Write <Entry>("MyFirstCollection", exampleMongoDBEntry); IEnumerable <Entry> readEntrys = reader.Read <Entry>("MyFirstCollection", // within this collection... "Message", // for the object field "Description" "Hello"); // return matches for 'Hello' Assert.AreEqual(1, readEntrys.Count()); //////////////////////////////////// // AND ASYNCHRONOUS OPERATIONS... // //////////////////////////////////// // read, write and update asynchronously using System.Threading.Task IAsyncReader asyncReader = new AsyncReader(reader); readEntrys = await asyncReader.ReadAsync <Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); IAsyncWriter asyncWriter = new AsyncWriter(writer); IAsyncUpdater asyncUpdater = new AsyncUpdater(updater); // or delegate call backs IAsyncDelegateReader asyncDelegateReader = new AsyncDelegateReader(reader); asyncDelegateReader.AsyncReadCompleted += new ReadCompletedEvent(readerCallBack); asyncDelegateReader.ReadAsync <Entry>("MyFirstCollection", "Message", "Hello"); _readerAutoResetEvent.WaitOne(); Assert.AreEqual(1, _asyncReadResults.Count()); IAsyncDelegateWriter asyncDelegateWriter = new AsyncDelegateWriter(writer); IAsyncDelegateUpdater asyncDelegateUpdater = new AsyncDelegateUpdater(updater); ///////////////////////////////////////////// // FOR A SERVER, DATABASE OR COLLECTION... // ///////////////////////////////////////////// // get a little higher level with the EasyMongo.Database namespace to target a database for operations IDatabaseReader databaseReader = new DatabaseReader(reader, asyncReader); IDatabaseWriter databaseWriter = new DatabaseWriter(writer, asyncWriter); IDatabaseUpdater databaseUpdater = new DatabaseUpdater(updater, asyncUpdater); // or a little lower level with the EasyMongo.Collection namespace to target a specific Collection ICollectionReader collectionReader = new CollectionReader(databaseReader, "MyFirstCollection"); ICollectionWriter collectionWriter = new CollectionWriter(databaseWriter, "MyFirstCollection"); ICollectionUpdater collectionUpdater = new CollectionUpdater(databaseUpdater, "MyFirstCollection"); /////////////////////////////////////////////// // TO RESTRICT CLIENT SCOPE (LAW OF DEMETER) // /////////////////////////////////////////////// // operate only against "MyFirstDatabase"'s "MySecondCollection" readEntrys = collectionReader.Read <Entry>("Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////// // GENERIC CLASSES // ///////////////////// // Instead of defining generic type arguments at the method level, // you can do it once at the class declaration IWriter <Entry> writerT = new Writer <Entry>(writer); writerT.Write("MySecondCollection", new Entry() { Message = "Goodbye World (Generically)" }); /////////////////////////////// // SIMPLIFY CREATION VIA IoC // /////////////////////////////// // because EasyMongo is a componentized framework built with blocks of functionality, EasyMongo // works great with DI containers and Inversion of Control. // here's an example of using the nuget Ninject extension to load EasyMongo mappings and a conn // string from configuration Ninject.IKernel kernel = new Ninject.StandardKernel(); ICollectionUpdater <Entry> collectionUpdaterT = kernel.TryGet <ICollectionUpdater <Entry> >(); // the alternative to this would be: IServerConnection serverConn = new ServerConnection(LOCAL_MONGO_SERVER_CONNECTION_STRING); IDatabaseConnection databaseConnn = new DatabaseConnection(serverConn, "MyFirstDatabase"); IDatabaseUpdater databaseUpdatr = new DatabaseUpdater(updater, asyncUpdater); ICollectionUpdater collectionUpdaterTheHardWay = new CollectionUpdater(databaseUpdater, "MySecondCollection"); ///////////////////////// // SIMPLE QUERIES... // ///////////////////////// databaseReader.Read <Entry>("MyFirstCollection", "Message", "Hello"); readEntrys = await databaseReader.ReadAsync <Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////////// // POWERFUL QUERIES... // ///////////////////////// // when more robust querying is needed leverage power of underlying MongoDB driver IMongoQuery IMongoQuery query1 = Query.Matches("Message", new BsonRegularExpression("HE", "i")); IEnumerable <Entry> queryResults = reader.Execute <Entry>("MyFirstCollection", query1); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); ////////////////////// // AND COMBINATIONS // ////////////////////// Entry exampleMongoDBEntry2 = new Entry(); exampleMongoDBEntry2.Message = "Hello Again"; Entry exampleMongoDBEntry3 = new Entry(); exampleMongoDBEntry3.Message = "Goodbye"; writer.Write <Entry>("MyFirstCollection", exampleMongoDBEntry2); writer.Write <Entry>("MyFirstCollection", exampleMongoDBEntry3); // "AND" multiple IMongoQueries... IMongoQuery query2 = Query.Matches("Message", new BsonRegularExpression("Again")); queryResults = reader.ExecuteAnds <Entry>("MyFirstCollection", new [] { query1, query2 }); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello Again", queryResults.ElementAt(0).Message); // "OR" multiple IMongoQueries... IMongoQuery query3 = Query.Matches("Message", new BsonRegularExpression("Goo")); queryResults = reader.ExecuteOrs <Entry>("MyFirstCollection", new[] { query1, query2, query3 }); Assert.AreEqual(3, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); Assert.AreEqual("Hello Again", queryResults.ElementAt(1).Message); Assert.AreEqual("Goodbye", queryResults.ElementAt(2).Message); }