public void SetData(ModelImportStatus _mos) { mos = _mos; string message = ""; ObservableCollection<ErrorMessages> messageList = new ObservableCollection<ErrorMessages>(); GenerateMessages(out message, out messageList, true); //DataGridMessageList.Items. foreach(ErrorMessages em in messageList){ em.SetStatusTextInfo(); } DataGridMessageList.Items.Clear(); DataGridMessageList.ItemsSource = messageList; MessageText.Text = message; }
/// <summary> /// Carry out the block model import /// </summary> /// <param name="SelectedBMFile"></param> /// <param name="SelectedFormatBMFile"></param> /// <param name="importMap"></param> /// <param name="blockRawFileReader"></param> /// <returns></returns> internal bool DoBMImport(string SelectedBMFile, string SelectedFormatBMFile, ImportDataMap importMap, RawFileReader blockRawFileReader, string XODBProjectID, string modelAlias) { BaseImportTools bit = new BaseImportTools(); int cxColumnID = importMap.GetColumnIDMappedTo("CentroidX"); int cyColumnID = importMap.GetColumnIDMappedTo("CentroidY"); int czColumnID = importMap.GetColumnIDMappedTo("CentroidZ"); ColumnStats xOrigin = blockRawFileReader.GetDimensions(cxColumnID); ColumnStats yOrigin = blockRawFileReader.GetDimensions(cyColumnID); ColumnStats zOrigin = blockRawFileReader.GetDimensions(czColumnID); int approxNumLines = xOrigin.count; Stream bmFileStream = new FileStream(SelectedBMFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // Stream bmFileStream = new FileStream(SelectedBMFile, FileMode.Open); ModelImportStatus mos = new ModelImportStatus(); Guid newModelGuid = Guid.NewGuid(); Guid authorGuid = new Guid(); List<string> status = bit.PerformBMImport(mos, newModelGuid, bmFileStream, null, importMap, xOrigin.min, yOrigin.min, zOrigin.min, backgroundWorker, approxNumLines, XODBProjectID, modelAlias, authorGuid, ConnectionString); return true; }
private void bw_DoCoalQualityImportWork(object sender, DoWorkEventArgs e) { ImportDataMap importMap = (ImportDataMap)e.Argument; commandDirector.SetCurrentWorkerThread(workerCoalQualityDataImport); ModelImportStatus status = commandDirector.DoCoalQualityImport(SelectedFile, SelectedFormatFile, importMap, blockRawFileReader, XODBProjectID, doDuplicateCheck, doImportOverwrite); lastestImportUpdateStatus = status; }
private void bw_DoSurveyImportWork(object sender, DoWorkEventArgs e) { ImportDataMap importMap = (ImportDataMap)e.Argument; commandDirector.SetCurrentWorkerThread(workerSurveyDataImport); ModelImportStatus status = commandDirector.DoSurveyImport(SelectedFile, SelectedFormatFile, importMap, blockRawFileReader, XODBProjectID, doImportOverwrite, this.doDuplicateCheck); lastestImportUpdateStatus = status; workerSurveyDataImport.ReportProgress((int)0, ""); }
public void ResetUI(){ blockRawFileReader = new RawFileReader(); ModelColumnDefinitions columnDefs = new ModelColumnDefinitions(); lastestImportUpdateStatus = null; SelectedFormatFile = ""; LabelLoadedFile.Content = "no file loaded"; //currentDBFieldsMetaInfo = new List<ColumnMetaInfo>(); MapConfigTable.ResetView(); ImportDataPreview.ResetData(); this.SelectedImportType = -1; ReSetRibbonEnabledStatus(true); }
private void CollarImportExecuted(object sender, ExecutedRoutedEventArgs e) { if (ComboBoxProjectList.SelectedValue == null) { ComboBoxProjectList.BorderBrush = Brushes.Red; MessageBox.Show("You must select a project before importing"); return; } Guid XODBProjectID = (Guid)ComboBoxProjectList.SelectedValue; bool overwrite = (bool)checkBoxOverwrite.IsChecked; ImportDataMap importMap = MapConfigTable.GetImportDataMap(MapConfigTable.collarPrimaryTableName); // add into map details of which columns are foreign keys if (collarDBFields != null) { importMap.UpdateWithFKInof(collarDBFields); } // get the selected project ID ModelImportStatus status = commandDirector.DoCollarImport(SelectedFile, SelectedFormatFile, importMap, blockRawFileReader, XODBProjectID, overwrite); lastestImportUpdateStatus = status; //if(status.finalErrorCode != ModelImportStatus.OK){ // string ss = status.GenerateStringMessage(true); // lastestImportUpdateStatus.SaveReportData(); // if (status.finalErrorCode == ModelImportStatus.DATA_CONSISTENCY_ERROR) // { // string headline = "Import complete. " + status.linesReadFromSource + " data lines read, " + status.recordsAdded + " new records added \n" + status.recordsUpdated + " existing records updated."; // MessageBox.Show("Warnings issued during import.\n\n" + headline + ".\n\n" + ss); // } // else // { // MessageBox.Show("Import failed. " + ss); // } //}else{ // MessageBox.Show("Import complete. "+status.linesReadFromSource+" data lines read, "+status.recordsAdded+" new records added \n"+status.recordsUpdated+" existing records updated."); //} if (lastestImportUpdateStatus != null) { ImportStatusWindow ii = new ImportStatusWindow(); ii.SetData(lastestImportUpdateStatus); ii.ShowDialog(); } //workerBMDataImport = new BackgroundWorker(); //workerBMDataImport.WorkerReportsProgress = true; //workerBMDataImport.WorkerSupportsCancellation = false; //workerBMDataImport.DoWork += bw_DoCollarImportWork; //// Method to call when Progress has changed //workerBMDataImport.ProgressChanged += bw_BMImportProgressChanged; //// Method to run after BackgroundWorker has completed? //workerBMDataImport.RunWorkerCompleted += bw_BMImportRunWorkerCompleted; //workerBMDataImport.RunWorkerAsync(importMap); e.Handled = true; }
private void bw_DoLASBatchImportWork(object sender, DoWorkEventArgs e) { string[] ss = (string[])e.Argument; commandDirector.SetCurrentWorkerThread(workerLASBatchDataImport); ModelImportStatus status = commandDirector.BatchImportLasFiles(ss, XODBProjectID); lastestImportUpdateStatus = status; workerLASBatchDataImport.ReportProgress((int)0, ""); }
internal ModelImportStatus DoCollarImport(string SelectedFile, string SelectedFormatBMFile, ImportDataMap importMap, RawFileReader blockRawFileReader, Guid XODBProjectID, bool overwrite) { BaseImportTools bit = new BaseImportTools(); // get the current collar names in this project List<CollarInfo> existingHoles = this.GetHolesForProject(XODBProjectID); List<string> existingHoleNames = new List<string>(); foreach (CollarInfo ci in existingHoles) { existingHoleNames.Add(ci.Name); } ModelImportStatus mos = new ModelImportStatus(); Stream fileStream = new FileStream(SelectedFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Stream fileStream = new FileStream(SelectedFile, FileMode.Open); bit.PerformCollarImport(mos, fileStream, null, importMap, this.backgroundWorker, XODBProjectID, ConnectionString, existingHoleNames, overwrite); return mos; }
internal ModelImportStatus BatchImportLasFiles(string[] filePaths, Guid currentProjectID) { ModelImportStatus finalStatus = new ModelImportStatus(); LASBatchImportTools ll = new LASBatchImportTools(); List<string> messages = new List<string>(); int importCount = 0; int failCount = 0; string report = ""; Dictionary<string, ModelImportStatus> mosList = new Dictionary<string, ModelImportStatus>(); bool reportStatus = false; if (this.backgroundWorker != null) { reportStatus = true; } int fileCount = filePaths.Length; int thisFileNum = 0; var dataDict = new Dictionary<string, List<object>>(); int holeCount = 0; foreach (string file in filePaths) { var data = new List<object>(); double pct = ((double)thisFileNum / (double)fileCount) * 100.0; thisFileNum++; if (reportStatus) { backgroundWorker.ReportProgress((int)pct, "Processing las file "+thisFileNum+" of "+fileCount+", "+file); } ModelImportStatus mis = new ModelImportStatus(); XODB.Import.Client.Processing.LASImport li = new XODB.Import.Client.Processing.LASImport(); LASFile lf = li.GetLASFile(file, mis); if (lf == null) { mis.errorMessages.Add("Failed to load LAS file " + file); mosList.Add(file, mis); continue; } data = ll.ProcessLASFile(lf, file, mis, currentProjectID, this.backgroundWorker); string msg = ""; if (msg != null) { messages.Add(msg); report += msg + "\n"; failCount++; } else { importCount++; } mosList.Add(file, mis); dataDict.Add(file, data); if (thisFileNum % 5 == 0 || (filePaths.Length-thisFileNum) < 1) //FIXME magic number, should look at used memory and make a choice on that { //insert into DB to avoid memory issues var subdict = dataDict; dataDict = new Dictionary<string, List<object>>(); this.PushToDB(subdict); subdict = null; GC.Collect(); GC.WaitForPendingFinalizers(); } } string finalReport = "Immport status:\nFiles imported:" + importCount + "\nFailed files:" + failCount + "\n\nMessages:\n"; finalReport += report; int totRecordsAddedCount = 0; int totLinesReadCount = 0; foreach (KeyValuePair<string, ModelImportStatus> kvp in mosList) { string lfName = kvp.Key; ModelImportStatus ms = kvp.Value; totRecordsAddedCount += ms.recordsAdded; totLinesReadCount += ms.linesReadFromSource; if (ms.finalErrorCode != ModelImportStatus.OK) { finalStatus.finalErrorCode = ModelImportStatus.GENERAL_LOAD_ERROR; } foreach (string m in ms.warningMessages) { finalStatus.warningMessages.Add(m); } foreach (string m in ms.errorMessages) { finalStatus.errorMessages.Add(m); } } finalStatus.linesReadFromSource = totLinesReadCount; finalStatus.recordsAdded = totRecordsAddedCount; return finalStatus; }
internal ModelImportStatus DoLithoImport(string SelectedFile, string SelectedFormatFile, ImportDataMap importMap, RawFileReader blockRawFileReader, Guid XODBProjectID, bool doOverwrite, bool checkForDuplicates) { BaseImportTools bit = new BaseImportTools(); ModelImportStatus mos = new ModelImportStatus(); GeneralFileInfo gfi = new GeneralFileInfo(); gfi.GeneralFileStats(SelectedFile); int numLines = gfi.numLines; //Stream fileStream = new FileStream(SelectedFile, FileMode.Open); Stream fileStream = new FileStream(SelectedFile, FileMode.Open, FileAccess.Read , FileShare.ReadWrite); bit.PerformLithoImport(mos, fileStream, null, importMap, this.backgroundWorker, XODBProjectID, ConnectionString, numLines, doOverwrite, checkForDuplicates); 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; }
public void AppendModel(ContentItem c) { var m = c.As<BlockModelPart>(); string statusMessage = ""; string connString = global::System.Configuration.ConfigurationManager.ConnectionStrings["XODBConnectionString"].ConnectionString; bool completed = false; BaseImportTools bit = new BaseImportTools(); string targetFolder; bool attmemptModelLoad; var bmFileName = ExtractBlockModelFromZip(m.BmFileName, out targetFolder, out attmemptModelLoad); IStorageFile bmFile = _storageProvider.GetFile(bmFileName); Stream bmFileStream = bmFile.OpenRead(); ModelImportStatus mos = new ModelImportStatus(); try { // Special append method for GF requirements - contains X, Y, Z, and value to append. // target model must have matching X, Y and Z centroids. // auto generate a format defintion based on Goldfields typical input column data var opts = new TransactionOptions(); opts.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted; using (new TransactionScope(TransactionScopeOption.Suppress, opts)) { mos = bit.PerformBMAppend(bmFileStream, m.BmGuid, m.Alias, m.ColumnNameToAdd, m.ColumnIndexToAdd, connString); mos.importTextFileName = m.BmFileName; mos.targetModelName = m.Alias; } statusMessage += string.Format("Successfully appended data to block model:\n{0} - {1}\n\nFrom file:{2}\n\n", m.Alias, m.BmGuid, m.BmFileName); completed = true; } catch (Exception ex) { statusMessage += string.Format("Error appending data to block model:\n{0} - {1}\n\nFrom file:{2}\n\nError:\n{3}\n\n", m.Alias, m.BmGuid, m.BmFileName, ex.ToString()); } finally { statusMessage += mos.GenerateStringMessage(); bmFileStream.Close(); _storageProvider.DeleteFile(bmFileName); _storageProvider.DeleteFolder(targetFolder); } statusMessage += string.Format("Time Elapsed: {0}\n\n", m.Processed.HasValue ? (DateTime.UtcNow - m.Processed.Value).ToString(@"hh\h\:mm\m\:ss\s\:fff\m\s") : "Unknown"); Logger.Information(statusMessage); _userService.EmailUsers(m.Recipients.SplitStringArray(), completed ? "Model Append Succeeded" : "Model Append Failed", statusMessage); }