public void LoadFlatFile(string rootNodePath, string filename, string formatfile = null, Encoding encoding = null) { if (formatfile == null) { var fi = new FileInfo(filename); formatfile = filename.Substring(0, filename.Length - fi.Extension.Length) + ".fmt"; } var mapNode = FormatReader.LoadFormatFile(formatfile, _nodes, rootNodePath, encoding ?? _defaultEncoding, _aliases); _mapSets[rootNodePath] = mapNode; using (var source = new FileStream(filename, FileMode.Open, FileAccess.Read)) { // Create node rows for parents of map node var nodes = new List <SharpNode> { mapNode.Parent }; while (nodes[0].Parent != null) { nodes.Insert(0, nodes[0].Parent); } nodes.Remove(nodes.Last()); var rows = nodes.Select(n => new SharpNodeRow(n)).ToList(); _rows.AddRange(rows); using (var reader = new FlatReader(source, mapNode, encoding ?? _defaultEncoding, SkipEmptyRows)) { _rows.InsertRows(reader.GetEnumerator(), rootRow: rows.Last()); } _rows.SubmitChanges(); } }
public static SharpNodeMap LoadFormatFile(string filename, SharpNodeCollection nodes, string path, Encoding encoding = null, Dictionary <string, string> aliases = null) { SharpNodeMap result; using (var stream = new FileStream(filename, FileMode.Open)) { var reader = new FormatReader(stream, encoding); if (aliases != null) { reader.Names = aliases; } result = reader.CreateColumnNodes(nodes, path); } return(result); }
public void OpenDelimitedFile(string rootNodePath, string filename, Encoding encoding = null) { using (var source = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (!SkipReadHeader) { var headerReader = new StreamReader(source); DefaultHeaderLine = headerReader.ReadLine(); } var mapNode = FormatReader.LoadHeaderLine(DefaultHeaderLine, _delimiter, _nodes, rootNodePath, _aliases); _mapSets[rootNodePath] = mapNode; _stream = new FileStream(filename, FileMode.Open, FileAccess.Read); _rows = new SharpRowStream { Nodes = _nodes, StreamNode = _nodes.GetNode(rootNodePath), StreamSource = new FlatReader(_stream, mapNode, encoding, SkipEmptyRows) }; // Create node rows for parents of map node var nodes = new List <SharpNode> { mapNode.Parent }; while (nodes[0].Parent != null) { nodes.Insert(0, nodes[0].Parent); } nodes.Remove(nodes.Last()); var rows = nodes.Select(n => new SharpNodeRow(n)).ToList(); _rows.AddRange(rows); } }
public void LoadDelimitedFile(string rootNodePath, string filename, Encoding encoding = null) { using (var source = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (!SkipReadHeader) { var headerReader = new StreamReader(source); DefaultHeaderLine = headerReader.ReadLine(); } var mapNode = FormatReader.LoadHeaderLine(DefaultHeaderLine, _delimiter, _nodes, rootNodePath, _aliases); _mapSets[rootNodePath] = mapNode; // Create node rows for parents of map node var nodes = new List <SharpNode> { mapNode.Parent }; while (nodes[0].Parent != null) { nodes.Insert(0, nodes[0].Parent); } nodes.Remove(nodes.Last()); var rows = nodes.Select(n => new SharpNodeRow(n)).ToList(); _rows.AddRange(rows); source.Seek(0, SeekOrigin.Begin); using (var reader = new FlatReader(source, mapNode, encoding, SkipEmptyRows)) { reader.SkipLines = SkipReadHeader ? 0 : 1; _rows.InsertRows(reader.GetEnumerator(), rootRow: rows.Last()); } _rows.SubmitChanges(); } }
public void LoadFormatFile(string rootNodePath, string formatfile, Encoding encoding = null) { var mapNode = FormatReader.LoadFormatFile(formatfile, _nodes, rootNodePath, encoding ?? _defaultEncoding, _aliases); _mapSets[rootNodePath] = mapNode; }