public static IEnumerable <DataGroup> GetGroups(DataGroupCollection groups) { if (groups == null) { yield break; } foreach (DataGroup group in groups) { yield return(group); foreach (DataGroup child in GetGroups(group.Groups)) { yield return(child); } } }
/// <summary> /// Initializes a new instance of the <see cref="HeaderBlock" /> class. /// </summary> /// <param name="mdf">The MDF.</param> /// <exception cref="System.FormatException"></exception> public HeaderBlock(Mdf mdf) : base(mdf) { byte[] data = new byte[Size - 4]; int read = Mdf.Data.Read(data, 0, data.Length); if (read != data.Length) { throw new FormatException(); } FileComment = null; ProgramBlock = null; uint ptrFirstDataGroup = BitConverter.ToUInt32(data, 0); uint ptrTextBlock = BitConverter.ToUInt32(data, 4); uint ptrProgramBlock = BitConverter.ToUInt32(data, 8); DataGroupsCount = BitConverter.ToUInt16(data, 12); Date = UTF8Encoding.UTF8.GetString(data, 14, 10); Time = UTF8Encoding.UTF8.GetString(data, 24, 8); Author = UTF8Encoding.UTF8.GetString(data, 32, 32); Organization = UTF8Encoding.UTF8.GetString(data, 64, 32); Project = UTF8Encoding.UTF8.GetString(data, 96, 32); Subject = UTF8Encoding.UTF8.GetString(data, 128, 32); /// Get the current version of MDF file /// and check if the property is avaible in this version var _RequiredVersionForTimeStamp = (MdfVersionAttribute)Attribute.GetCustomAttribute(typeof(HeaderBlock).GetProperty("TimeStamp"), typeof(MdfVersionAttribute)); if (this.Mdf.IDBlock.Version >= _RequiredVersionForTimeStamp.Version) { TimeStamp = BitConverter.ToUInt64(data, 160); } else { TimeStamp = Convert.ToUInt64(_RequiredVersionForTimeStamp.DefaultValue); } /// Get the current version of MDF file /// and check if the property is avaible in this version var _RequiredVersionForUTCTimeOffset = (MdfVersionAttribute)Attribute.GetCustomAttribute(typeof(HeaderBlock).GetProperty("UTCTimeOffset"), typeof(MdfVersionAttribute)); if (this.Mdf.IDBlock.Version >= _RequiredVersionForUTCTimeOffset.Version) { UTCTimeOffset = BitConverter.ToInt16(data, 168); } else { UTCTimeOffset = Convert.ToInt16(_RequiredVersionForUTCTimeOffset.DefaultValue); } /// Get the current version of MDF file /// and check if the property is avaible in this version var _RequiredVersionForTimeQuality = (MdfVersionAttribute)Attribute.GetCustomAttribute(typeof(HeaderBlock).GetProperty("TimeQuality"), typeof(MdfVersionAttribute)); if (this.Mdf.IDBlock.Version >= _RequiredVersionForTimeQuality.Version) { TimeQuality = (TimeQuality)BitConverter.ToUInt16(data, 170); } else { TimeQuality = (TimeQuality)Convert.ToUInt16(_RequiredVersionForTimeQuality.DefaultValue); } /// Get the current version of MDF file /// and check if the property is avaible in this version var _RequiredVersionForTimerIdentification = (MdfVersionAttribute)Attribute.GetCustomAttribute(typeof(HeaderBlock).GetProperty("TimerIdentification"), typeof(MdfVersionAttribute)); if (this.Mdf.IDBlock.Version >= _RequiredVersionForTimerIdentification.Version) { TimerIdentification = UTF8Encoding.UTF8.GetString(data, 172, 32); } else { TimerIdentification = _RequiredVersionForTimerIdentification.DefaultValue.ToString(); } /// Check if ptrTextBlock is null if (ptrTextBlock != 0) { Mdf.Data.Position = ptrTextBlock; FileComment = new TextBlock(mdf); } /// Check if ptrProgramBlock is null if (ptrProgramBlock != 0) { Mdf.Data.Position = ptrProgramBlock; ProgramBlock = new ProgramBlock(mdf); } /// Check if ptrFirstDataGroup is null if (ptrFirstDataGroup != 0) { Mdf.Data.Position = ptrFirstDataGroup; DataGroups = new DataGroupCollection(mdf, new DataGroupBlock(mdf)); } }