public List <string> GetImportFileColumnsAsList(Guid guid, string bmFileName, string modelAlias) { List <string> columnNames = new List <string>(); BaseImportTools bit = new BaseImportTools(); string targetFolder; bool attmemptModelLoad; string originalName = bmFileName; bmFileName = ExtractBlockModelFromZip(bmFileName, out targetFolder, out attmemptModelLoad); IStorageFile bmFile = _storageProvider.GetFile(bmFileName); Stream bmFileStream = bmFile.OpenRead(); NKD.Import.FormatSpecification.ImportDataMap idm = null; double _originX = -1; double _originY = -1; double _originZ = -1; try { StreamReader sr = new StreamReader(bmFileStream); string headerLine = ""; string firstDataLine = ""; if (sr != null) { headerLine = sr.ReadLine(); firstDataLine = sr.ReadLine(); bit.ParseDataLinesForOrigins(headerLine, firstDataLine, ',', out _originX, out _originY, out _originZ); // auto generate a format defintion based on Goldfields typical input column data idm = bit.AutoGenerateFormatDefinition(headerLine, ','); } sr.Close(); } catch { } if (idm != null) { foreach (ColumnMap cm in idm.columnMap) { columnNames.Add(cm.sourceColumnName); } } return(columnNames); }
public List<string> GetImportFileColumnsAsList(Guid guid, string bmFileName, string modelAlias) { List<string> columnNames = new List<string>(); string scs = global::System.Configuration.ConfigurationManager.ConnectionStrings["XODBConnectionString"].ConnectionString; string connString = scs; BaseImportTools bit = new BaseImportTools(); string targetFolder; bool attmemptModelLoad; string originalName = bmFileName; bmFileName = ExtractBlockModelFromZip(bmFileName, out targetFolder, out attmemptModelLoad); IStorageFile bmFile = _storageProvider.GetFile(bmFileName); Stream bmFileStream = bmFile.OpenRead(); XODB.Import.FormatSpecification.ImportDataMap idm = null; double _originX = -1; double _originY = -1; double _originZ = -1; try { StreamReader sr = new StreamReader(bmFileStream); string headerLine = ""; string firstDataLine = ""; if (sr != null) { headerLine = sr.ReadLine(); firstDataLine = sr.ReadLine(); bit.ParseDataLinesForOrigins(headerLine, firstDataLine, out _originX, out _originY, out _originZ); // auto generate a format defintion based on Goldfields typical input column data idm = bit.AutoGenerateFormatDefinition(headerLine); } sr.Close(); } catch { } if (idm != null) { foreach (ColumnMap cm in idm.columnMap) { columnNames.Add(cm.sourceColumnName); } } return columnNames; }
/// <summary> /// Import the block model. This is ultimatly carried out throught he import library which must be /// passed the streams for the import file (and defintiion possibly). /// </summary> /// <param name="bmFileName"></param> /// <param name="formatFileName"></param> /// <param name="projectID"></param> /// <param name="alias"></param> /// <param name="authorGuid"></param> /// <param name="res2"></param> /// <param name="domains"></param> /// <param name="targetFolder"></param> /// <param name="attmemptModelLoad"></param> /// <param name="notes"></param> /// <param name="stage"></param> /// <returns></returns> private ModelImportStatus DoNewModelImport(string bmFileName, string formatFileName, string projectID, string alias, Guid authorGuid, ref List <string> domains, string targetFolder, bool attmemptModelLoad, string notes, string stage, Guid stageMetaID) { ModelImportStatus mos = new ModelImportStatus(); mos.finalErrorCode = ModelImportStatus.OK; double _originX = -1; double _originY = -1; double _originZ = -1; BaseImportTools bit = new BaseImportTools(); if (attmemptModelLoad) { //IStorageFile formatFile = _storageProvider.GetFile(formatFileName); IStorageFile bmFile = _storageProvider.GetFile(bmFileName); Stream bmFileStream = bmFile.OpenRead(); Stream bmTempFileStream = bmFile.OpenRead(); // try and automatically detect the origin coordinates from the file itself - a datamine file // always carries the origin coords in XMORIG, YMORIG, ZMORIG NKD.Import.FormatSpecification.ImportDataMap idm = null; try { StreamReader sr = new StreamReader(bmTempFileStream); string headerLine = ""; string firstDataLine = ""; if (sr != null) { headerLine = sr.ReadLine(); firstDataLine = sr.ReadLine(); bit.ParseDataLinesForOrigins(headerLine, firstDataLine, ',', out _originX, out _originY, out _originZ); // auto generate a format defintion based on Goldfields typical input column data idm = bit.AutoGenerateFormatDefinition(headerLine, ','); } sr.Close(); } catch (Exception ex) { mos.AddWarningMessage("Unable to auto detect origin and other format information from the file\n\n" + ex.ToString()); } var opts = new TransactionOptions(); opts.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted; using (new TransactionScope(TransactionScopeOption.Suppress, opts)) { try { Guid blockModelGUID = Guid.NewGuid(); mos.modelID = blockModelGUID; domains = bit.PerformBMImport(mos, blockModelGUID, bmFileStream, null, idm, _originX, _originY, _originZ, null, 1000, projectID, alias, authorGuid, _users.ApplicationConnectionString); List <Tuple <string, string> > doms = new List <Tuple <string, string> >(); string domainColumnName = "Domain"; foreach (string ss in domains) { doms.Add(new Tuple <string, string>(domainColumnName, ss)); } UpdateDomains(doms, blockModelGUID); AddModelNotes(notes, blockModelGUID); UpdateStage(blockModelGUID, stageMetaID, stage); } catch (Exception ex) { mos.finalErrorCode = ModelImportStatus.ERROR_WRITING_TO_DB; mos.AddErrorMessage("Error importing block model:\n" + ex.ToString()); } } //TODO call into import library with the stream object for the import bmFileStream.Close(); _storageProvider.DeleteFile(bmFileName); _storageProvider.DeleteFolder(targetFolder); } return(mos); }
/// <summary> /// Import the block model. This is ultimatly carried out throught he import library which must be /// passed the streams for the import file (and defintiion possibly). /// </summary> /// <param name="bmFileName"></param> /// <param name="formatFileName"></param> /// <param name="projectID"></param> /// <param name="alias"></param> /// <param name="authorGuid"></param> /// <param name="res2"></param> /// <param name="domains"></param> /// <param name="targetFolder"></param> /// <param name="attmemptModelLoad"></param> /// <param name="notes"></param> /// <param name="stage"></param> /// <returns></returns> private ModelImportStatus DoNewModelImport(string bmFileName, string formatFileName, string projectID, string alias, Guid authorGuid, ref List<string> domains, string targetFolder, bool attmemptModelLoad, string notes, string stage, Guid stageMetaID) { ModelImportStatus mos = new ModelImportStatus(); mos.finalErrorCode = ModelImportStatus.OK; double _originX = -1; double _originY = -1; double _originZ = -1; string connString = global::System.Configuration.ConfigurationManager.ConnectionStrings["XODBConnectionString"].ConnectionString; BaseImportTools bit = new BaseImportTools(); if (attmemptModelLoad) { //IStorageFile formatFile = _storageProvider.GetFile(formatFileName); IStorageFile bmFile = _storageProvider.GetFile(bmFileName); Stream bmFileStream = bmFile.OpenRead(); Stream bmTempFileStream = bmFile.OpenRead(); // try and automatically detect the origin coordinates from the file itself - a datamine file // always carries the origin coords in XMORIG, YMORIG, ZMORIG XODB.Import.FormatSpecification.ImportDataMap idm = null; try { StreamReader sr = new StreamReader(bmTempFileStream); string headerLine = ""; string firstDataLine = ""; if (sr != null) { headerLine = sr.ReadLine(); firstDataLine = sr.ReadLine(); bit.ParseDataLinesForOrigins(headerLine, firstDataLine, out _originX, out _originY, out _originZ); // auto generate a format defintion based on Goldfields typical input column data idm = bit.AutoGenerateFormatDefinition(headerLine); } sr.Close(); } catch (Exception ex) { mos.AddWarningMessage("Unable to auto detect origin and other format information from the file\n\n" + ex.ToString()); } var opts = new TransactionOptions(); opts.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted; using (new TransactionScope(TransactionScopeOption.Suppress, opts)) { try { Guid blockModelGUID = Guid.NewGuid(); mos.modelID = blockModelGUID; domains = bit.PerformBMImport(mos, blockModelGUID, bmFileStream, null, idm, _originX, _originY, _originZ, null, 1000, projectID, alias, authorGuid, connString); List<Tuple<string, string>> doms = new List<Tuple<string, string>>(); string domainColumnName = "Domain"; foreach (string ss in domains) { doms.Add(new Tuple<string, string>(domainColumnName, ss)); } XODB.Helpers.BMImportHelper.UpdateDomains(doms, blockModelGUID); XODB.Helpers.BMImportHelper.AddModelNotes(notes, blockModelGUID); XODB.Helpers.BMImportHelper.UpdateStage(blockModelGUID, stageMetaID, stage); } catch (Exception ex) { mos.finalErrorCode = ModelImportStatus.ERROR_WRITING_TO_DB; mos.AddErrorMessage("Error importing block model:\n" + ex.ToString()); } } //TODO call into import library with the stream object for the import bmFileStream.Close(); _storageProvider.DeleteFile(bmFileName); _storageProvider.DeleteFolder(targetFolder); } return mos; }