public void WriteAndReadJaggedArray() { string filename = Path.Combine(folder, $"{nameof(WriteAndReadJaggedArray)}.H5"); var obj = new TestClassWithJaggedArray(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteObject(fileId, obj, "test"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var obj2 = Hdf5.ReadObject <TestClassWithJaggedArray>(fileId, "test"); Assert.IsTrue(obj.Equals(obj2)); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadObjectWithStructs() { string filename = Path.Combine(folder, "testObjectWithStructArray.H5"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteObject(fileId, classWithStructs, "test"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { TestClassWithStructs objWithStructs; var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); objWithStructs = Hdf5.ReadObject <TestClassWithStructs>(fileId, "test"); CollectionAssert.AreEqual(wDataList, objWithStructs.DataList); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public Task WaitForDataWritten() { try { record = false; LockSlim.EnterWriteLock(); if (!RPositionSamplesData.Any()) { Logger.LogWarning("No R Position events to write to H5 file"); return(Task.CompletedTask); } var dataToWrite = RPositionSamplesData; RPositionSamplesData = new List <RPositionEvent>(); Logger.LogInformation("Start write of RPosition events"); Hdf5RPositionEvents events = new Hdf5RPositionEvents(dataToWrite); var status = Hdf5.WriteObject(GroupRoot, events, Constants.EventGroupName); Logger.LogInformation("End write of RPosition with status " + status); } catch (Exception e) { Logger.LogError(e, $"Error writing RPosition Events: {e.Message}"); } finally { LockSlim.ExitWriteLock(); } return(Task.CompletedTask); }
public void WriteAndReadListOfList() { string filename = Path.Combine(folder, $"{nameof(WriteAndReadList)}.H5"); TestClassListOfList data = new TestClassListOfList(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, data, "test"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var objWithList = Hdf5.ReadObject <TestClassListOfList>(fileId, "test"); Hdf5.CloseFile(fileId); Assert.IsTrue(objWithList.Data[0].SequenceEqual(data.Data[0])); Assert.IsTrue(objWithList.Data[1].SequenceEqual(data.Data[1])); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public Task WaitForDataWritten() { try { record = false; LockSlim.EnterWriteLock(); if (!SystemEventSamplesData.Any()) { Logger.LogWarning("No system events to write to H5 file"); return(Task.CompletedTask); } var dataToWrite = SystemEventSamplesData; SystemEventSamplesData = new List <SystemEvent>(); Logger.LogInformation("Start write of system events"); Hdf5SystemEvents events = new Hdf5SystemEvents(dataToWrite); var status = Hdf5.WriteObject(GroupRoot, events, Constants.EventGroupName); Logger.LogInformation("End write of system events with status " + status); return(Task.CompletedTask); } finally { LockSlim.ExitWriteLock(); } }
public Task WaitForDataWritten() { record = false; Logger.LogInformation("Start write of Tags"); var status = Hdf5.WriteObject(GroupId, TagsData.ToArray()); Logger.LogInformation("End write of Tags with status " + status); return(Task.CompletedTask); }
public Task WaitForDataWritten() { record = false; Logger.LogInformation("Start write of system events"); events = new Hdf5Events(SystemEventSamplesData); var status = Hdf5.WriteObject(GroupId, events); Logger.LogInformation("End write of system events with status " + status); return(Task.CompletedTask); }
public void WriteAndReadObjectWithPropertiesAndArrayPropertyTest() { try { var testClass = new TestClassWithArray() { TestInteger = 2, TestDouble = 1.1, TestBoolean = true, TestString = "test string", TestDoubles = new double[] { 1.1, 1.2, -1.1, -1.2 }, TestStrings = new string[] { "one", "two", "three", "four" } }; testClassWithArrays.TestInteger = 2; testClassWithArrays.TestDouble = 1.1; testClassWithArrays.TestBoolean = true; testClassWithArrays.TestString = "test string"; testClassWithArrays.TestDoubles = new double[] { 1.1, 1.2, -1.1, -1.2 }; testClassWithArrays.TestStrings = new string[] { "one", "two", "three", "four" }; string filename = Path.Combine(folder, "testArrayObjects.H5"); var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId >= 0); Hdf5.WriteObject(fileId, testClassWithArrays, "objectWithTwoArrays"); TestClassWithArray readObject = new TestClassWithArray { TestStrings = new string[0], TestDoubles = null, TestDouble = double.NaN }; readObject = Hdf5.ReadObject(fileId, readObject, "objectWithTwoArrays"); Assert.IsTrue(testClassWithArrays.Equals(readObject)); readObject = Hdf5.ReadObject <TestClassWithArray>(fileId, "objectWithTwoArrays"); Assert.IsTrue(testClassWithArrays.Equals(readObject)); Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadObjectWithHdf5Attributes() { string filename = Path.Combine(folder, "testHdf5Attribute.H5"); var attObject = new AttributeClass(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, attObject, "anObject"); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public Task WaitForDataWritten() { if (!userEventsData.Any()) { Logger.LogWarning("No user event to write to H5 file"); return(Task.CompletedTask); } var dataToWrite = userEventsData; userEventsData = new List <UserEventRecord>(); Hdf5UserEvents eventsToH5 = new Hdf5UserEvents(dataToWrite); Logger.LogInformation("Start write of User Events"); var status = Hdf5.WriteObject(GroupRoot, eventsToH5, Constants.EventGroupName); Logger.LogInformation("End write of User Events with status " + status); return(Task.CompletedTask); }
public void WriteAndReadObjectWithPropertiesTest() { string filename = Path.Combine(folder, "testObjects.H5"); try { testClass.TestInteger = 2; testClass.TestDouble = 1.1; testClass.TestBoolean = true; testClass.TestString = "test string"; // 31-Oct-2003, 18:00 is 731885.75 in matlab testClass.TestTime = new DateTime(2003, 10, 31, 18, 0, 0); var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, testClass, "objectWithProperties"); Hdf5.CloseFile(fileId); } catch (Exception ex) { CreateExceptionAssert(ex); } try { var fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); TestClass readObject = new TestClass(); readObject = Hdf5.ReadObject(fileId, readObject, "objectWithProperties"); Assert.IsTrue(testClass.Equals(readObject)); readObject = Hdf5.ReadObject <TestClass>(fileId, "objectWithProperties"); Assert.IsTrue(testClass.Equals(readObject)); Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadAllPrimitives() { string filename = Path.Combine(folder, "testAllPrimitives.H5"); //var groupStr = "/test"; //string concatFunc(string x) => string.Concat(groupStr, "/", x); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, allTypesObject, "/test"); var readObject = Hdf5.ReadObject <AllTypesClass>(fileId, "/test"); Assert.IsTrue(allTypesObject.PublicInstanceFieldsEqual(readObject)); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } }
public void WriteAndReadObjectWithHdf5Attributes() { string groupName = "anObject"; string filename = Path.Combine(folder, "testHdf5Attribute.H5"); var attObject = new AttributeClass(); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, attObject, groupName); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } var OpenFileId = Hdf5.OpenFile(filename); var data = Hdf5.ReadObject <AttributeClass>(OpenFileId, groupName); Assert.IsTrue(Math.Abs(data.noAttribute - 10.0f) < 0.001); }
public void WriteOverrideAndReadObjectWithHdf5Attributes() { string groupName = "simpleObject"; string filename = Path.Combine(folder, "testSimpleHdf5Attribute.H5"); var attObject = new AttributeSimpleClass(); attObject.SetStringProperty("new value"); try { var fileId = Hdf5.CreateFile(filename); Assert.IsTrue(fileId > 0); Hdf5.WriteObject(fileId, attObject, groupName); Assert.IsTrue(Hdf5.CloseFile(fileId) == 0); } catch (Exception ex) { CreateExceptionAssert(ex); } var openFileId = Hdf5.OpenFile(filename); var data = Hdf5.ReadObject <AttributeSimpleClass>(openFileId, groupName); Hdf5.CloseFile(openFileId); Assert.IsTrue(data.Equals(attObject)); attObject.SetStringProperty("third"); attObject.datetime = DateTime.Now; openFileId = Hdf5.OpenFile(filename); Hdf5.WriteObject(openFileId, attObject, groupName); Assert.IsTrue(Hdf5.CloseFile(openFileId) == 0); openFileId = Hdf5.OpenFile(filename); data = Hdf5.ReadObject <AttributeSimpleClass>(openFileId, groupName); Hdf5.CloseFile(openFileId); Assert.IsTrue(data.Equals(attObject)); File.Delete(filename); }
public void WriteAndReadUserSystemEvents() { string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WriteAndReadUserSystemEvents.H5"); var userEventsData = new List <UserEventRecord>() { new UserEventRecord("research1", "button1", "none", DateTimeOffset.Now.ToUnixTimeMilliseconds()), new UserEventRecord("research1", "button2", "none", DateTimeOffset.Now.ToUnixTimeMilliseconds() + 10) }; var fileId = Hdf5.CreateFile(filename); Hdf5UserEvents hdf5UserEvents = new Hdf5UserEvents(userEventsData); Assert.IsTrue(fileId > 0); var status = Hdf5.WriteObject(fileId, hdf5UserEvents, "test"); Hdf5.CloseFile(fileId); fileId = Hdf5.OpenFile(filename); Assert.IsTrue(fileId > 0); var objWithStructs = Hdf5.ReadObject <Hdf5UserEvents>(fileId, "test"); CollectionAssert.AreEqual(hdf5UserEvents.Events, objWithStructs.Events); Hdf5.CloseFile(fileId); }