protected virtual void Dispose(bool disposing) { if (disposing) { SaveHeader(); dset?.Dispose(); var info = Hdf5.GroupInfo(_groupId); _groupId = Hdf5.CloseGroup(_groupId); fileId = Hdf5.CloseFile(fileId); } }
public static T ReadObject <T>(hid_t groupId, T readValue, string groupName) { if (readValue == null) { throw new ArgumentNullException(nameof(readValue)); } bool isGroupName = !string.IsNullOrWhiteSpace(groupName); if (isGroupName) { groupId = H5G.open(groupId, groupName); } Type tyObject = readValue.GetType(); foreach (Attribute attr in Attribute.GetCustomAttributes(tyObject)) { if (attr is Hdf5GroupName) { groupName = (attr as Hdf5GroupName).Name; } if (attr is Hdf5SaveAttribute) { Hdf5SaveAttribute atLeg = attr as Hdf5SaveAttribute; if (atLeg.SaveKind == Hdf5Save.DoNotSave) { return(readValue); } } } ReadFields(tyObject, readValue, groupId); ReadProperties(tyObject, readValue, groupId); if (isGroupName) { Hdf5.CloseGroup(groupId); } return(readValue); }
public static object WriteObject(hid_t groupId, object writeValue, string groupName = null) { if (writeValue == null) { throw new ArgumentNullException(nameof(writeValue)); } bool createGroupName = !string.IsNullOrWhiteSpace(groupName); if (createGroupName) { groupId = Hdf5.CreateGroup(groupId, groupName); } Type tyObject = writeValue.GetType(); foreach (Attribute attr in Attribute.GetCustomAttributes(tyObject)) { Hdf5SaveAttribute legAt = attr as Hdf5SaveAttribute; if (legAt != null) { Hdf5Save kind = legAt.SaveKind; if (kind == Hdf5Save.DoNotSave) { return(writeValue); } } } WriteProperties(tyObject, writeValue, groupId); WriteFields(tyObject, writeValue, groupId); WriteHdf5Attributes(tyObject, groupId, groupName); if (createGroupName) { Hdf5.CloseGroup(groupId); } return(writeValue); }
protected virtual void Dispose(bool disposing) { Trace.WriteLine($"saving file {Header.Patient.Name} samples: {_sampleCount}; fileId: {fileId}"); Header.Recording.EndTime = Header.Recording.StartTime + TimeSpan.FromSeconds(_sampleCount / Header.Recording.SampleRate); Header.Recording.NrOfSamples = _sampleCount; Header.EventListToEvents(); for (int i = 0; i < Header.Channels.Count(); i++) { Header.Channels[i].NrOfSamples = _sampleCount; } Trace.WriteLine($"writing file {Header.Patient.Name} groupId: {_groupId}; fileId: {fileId}"); Hdf5.WriteObject(_groupId, Header); if (disposing) { if (dset != null) { dset.Dispose(); } var info = Hdf5.GroupInfo(_groupId); _groupId = Hdf5.CloseGroup(_groupId); fileId = Hdf5.CloseFile(fileId); } }