Click here to Skip to main content
15,895,538 members
Articles / Web Development / HTML

Transformalizing NorthWind

Rate me:
Please Sign up or sign in to vote.
4.95/5 (29 votes)
24 Jul 2014GPL37 min read 57.8K   341   53  
Combining de-normalization, transformation, replication, and awesome-ness.
#region License
// /*
// See license included in this library folder.
// */
#endregion

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Transformalize.Libs.ExcelDataReader.Core.BinaryFormat
{
	/// <summary>
	/// Represents Root Directory in file
	/// </summary>
	internal class XlsRootDirectory
	{
		private readonly List<XlsDirectoryEntry> m_entries;
		private readonly XlsDirectoryEntry m_root;

		/// <summary>
		/// Creates Root Directory catalog from XlsHeader
		/// </summary>
		/// <param name="hdr">XlsHeader object</param>
		public XlsRootDirectory(XlsHeader hdr)
		{
			var stream = new XlsStream(hdr, hdr.RootDirectoryEntryStart);
			var array = stream.ReadStream();
			byte[] tmp;
			XlsDirectoryEntry entry;
			var entries = new List<XlsDirectoryEntry>();
			for (var i = 0; i < array.Length; i += XlsDirectoryEntry.Length)
			{
				tmp = new byte[XlsDirectoryEntry.Length];
				Buffer.BlockCopy(array, i, tmp, 0, tmp.Length);
				entries.Add(new XlsDirectoryEntry(tmp));
			}
			m_entries = entries;
			for (var i = 0; i < entries.Count; i++)
			{
				entry = entries[i];
				if (m_root == null && entry.EntryType == STGTY.STGTY_ROOT)
					m_root = entry;
				if (entry.ChildSid != (uint)FATMARKERS.FAT_FreeSpace)
					entry.Child = entries[(int)entry.ChildSid];
				if (entry.LeftSiblingSid != (uint)FATMARKERS.FAT_FreeSpace)
					entry.LeftSibling = entries[(int)entry.LeftSiblingSid];
				if (entry.RightSiblingSid != (uint)FATMARKERS.FAT_FreeSpace)
					entry.RightSibling = entries[(int)entry.RightSiblingSid];
			}
		}

		/// <summary>
		/// Returns all entries in Root Directory
		/// </summary>
		public ReadOnlyCollection<XlsDirectoryEntry> Entries
		{
			get { return m_entries.AsReadOnly(); }
		}

		/// <summary>
		/// Returns the Root Entry
		/// </summary>
		public XlsDirectoryEntry RootEntry
		{
			get { return m_root; }
		}

		/// <summary>
		/// Searches for first matching entry by its name
		/// </summary>
		/// <param name="EntryName">String name of entry</param>
		/// <returns>Entry if found, null otherwise</returns>
		public XlsDirectoryEntry FindEntry(string EntryName)
		{
			foreach (var e in m_entries)
			{
				if (e.EntryName == EntryName)
					return e;
			}
			return null;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions