/// <summary> /// Loads the database for this instance. /// </summary> /// <param name="fileName"></param> /// <returns></returns> public override bool LoadSchema(string fileName) { if (DataNodes == null) { DataNodes = new List <DataNode>(); } var folderItem = new DataNode(); var previewFolder = new ZipArchive(new FileStream(fileName, FileMode.Open)); folderItem.Name = Path.GetFileNameWithoutExtension(fileName); folderItem.Path = fileName; foreach (var document in previewFolder.Entries.Take(50)) { if (document != null) { var entryItem = new DataNode(); entryItem.Name = document.FullName; string content = new StreamReader(document.Open()).ReadToEnd(); entryItem.Value = Encoding.UTF8.GetBytes(content) ?? null; entryItem.NodeType = typeof(byte[]); entryItem.Parent.Add(folderItem); folderItem.Children.Add(entryItem); } } previewFolder.Dispose(); DataNodes.Add(folderItem); return(DataNodes.Count > 0 ? true : false); }
/// <summary> /// Loads the database for this instance. /// may be called multiple times, if uploading multiple CSV files. /// </summary> /// <param name="fileName"></param> /// <returns></returns> public override bool LoadSchema(string fileName) { //enforce that the filename must be a known configuration. if (!FileIsKnown(fileName)) { return(false); } using (var dbPreview = new CsvReader(new StreamReader(fileName), true)) { if (CsvDataToImport == null) { CsvDataToImport = new List <CSVInstance>(); DataNodes = new List <DataNode>(); } //a local tableNode object, which will track this one of multiple CSV files that may be imported var tableNodes = new List <DataNode>(); CsvDataToImport.Add(new CSVInstance(fileName) { TableNodes = tableNodes, RecordType = GetRecordTypeFromFilename(fileName) }); var currentIndex = 0; var tableItem = new DataNode { Name = Path.GetFileNameWithoutExtension(fileName) }; var firstRow = dbPreview.ElementAtOrDefault(0); if (firstRow != null) { foreach (var columnName in dbPreview.GetFieldHeaders()) { var childItem = new DataNode { Name = columnName, NodeType = typeof(string), Value = firstRow[currentIndex] ?? string.Empty }; childItem.Parent.Add(tableItem); tableItem.Children.Add(childItem); currentIndex++; } tableNodes.Add(tableItem); DataNodes.Add(tableItem); //this is to maintain compatibility with the base Excavator object. } return(tableNodes.Count() > 0 ? true : false); } }
public void AddDataNode(int dataNodeIndex, int replica) { if (dataNodeIndex < 0) { throw new ArgumentException("data node index is null"); } if (replica == RouteResultsetNode.DefaultReplicaIndex || replica < 0) { replica = -1; } if (DataNodes == null) { DataNodes = new List <Pair <int, int> >(); } DataNodes.Add(new Pair <int, int>(dataNodeIndex, replica)); }