Example #1
0
        public void WriteAndReadObjectWithPropertiesAndArrayPropertyTest()
        {
            try
            {
                testClassWithArrays.TestInteger      = 2;
                testClassWithArrays.TestDouble       = 1.1;
                testClassWithArrays.TestBoolean      = true;
                testClassWithArrays.TestString       = "test string";
                testClassWithArrays.TestDoubles      = new[] { 1.1, 1.2, -1.1, -1.2 };
                testClassWithArrays.TestStrings      = new[] { "one", "two", "three", "four" };
                testClassWithArrays.testDoublesField = new[] { 1.1, 1.2, -1.1, -1.2 };
                testClassWithArrays.testStringsField = new[] { "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 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);
        }
Example #4
0
        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);
        }