public void ShowImportReferences() { User.CheckPermission(PermissionCategory.IMPORT_REFERENCES, PERMISSION_MASK.ALLOW, "You do not have sufficient privileges to import references into BioLink!"); if (_importReferencesWizard == null) { var context = new ImportWizardContext(); Func <List <FieldDescriptor> > fieldSource = () => { var service = new ImportService(User); return(service.GetReferenceImportFields()); }; Func <ImportProcessor> importProcessorFactory = () => { return(new ImportReferencesProcessor()); }; _importReferencesWizard = new ImportWizard(User, "Import References", context, new ImportFilterSelection(), new ImportMappingPage(fieldSource), new ImportPage(importProcessorFactory)); _importReferencesWizard.Closed += new EventHandler((sender, e) => { _importReferencesWizard = null; }); } _importReferencesWizard.Show(); _importReferencesWizard.Focus(); }
public override bool GetOptions(System.Windows.Window parentWindow, ImportWizardContext context) { var frm = new CSVImportOptionsWindow(_options); frm.Owner = parentWindow; frm.WindowStartupLocation = WindowStartupLocation.CenterOwner; if (frm.ShowDialog().GetValueOrDefault(false)) { _options = new CSVImporterOptions { Filename = frm.Filename, Delimiter = frm.Delimiter, FirstRowContainsNames = frm.IsFirstRowContainNames, ColumnNames = frm.ColumnNames }; return(true); } return(false); }
public override bool GetOptions(System.Windows.Window parentWindow, ImportWizardContext context) { var frm = new BVPImportOptionsWindow(PluginManager.Instance.User, _options); frm.Owner = parentWindow; frm.WindowStartupLocation = WindowStartupLocation.CenterOwner; if (frm.ShowDialog().GetValueOrDefault(false)) { _options = new BVPImportOptions { Filename = frm.Filename, RowSource = frm.RowSource }; if (context.FieldMappings == null || context.FieldMappings.Count() == 0) { PreloadMappings(context); } return(true); } return(false); }
public void Import(Window parentWindow, ImportWizardContext context, IProgressObserver progress, Action <ImportStatusLevel, string> logFunc) { this.ParentWindow = parentWindow; this.Importer = context.Importer; this.Mappings = context.FieldMappings; this.Progress = progress; this.LogFunc = logFunc; if (Progress != null) { Progress.ProgressStart("Initialising..."); } if (!InitImport()) { return; } ProgressMsg("Importing data - Stage 1", 0); if (!DoStage1()) { return; } CreateColumnIndexes(); Cancelled = false; var connection = User.GetConnection(); LogMsg("Importing data - Stage 2", 10); int rowCount = 0; int lastPercent = 0; DateTime timeStarted = DateTime.Now; DateTime lastCheck = timeStarted; RowSource.Reset(); while (RowSource.MoveNext() && !Cancelled) { ImportCurrentRow(rowCount++, connection); var dblPercent = (double)((double)rowCount / (double)RowSource.RowCount) * 90; int percent = ((int)dblPercent) + 10; var timeSinceLastUpdate = DateTime.Now - lastCheck; if (percent != lastPercent || timeSinceLastUpdate.Seconds > 5) { var timeSinceStart = DateTime.Now - timeStarted; var avgMillisPerRow = (double)(timeSinceStart.TotalMilliseconds == 0 ? 1 : timeSinceStart.TotalMilliseconds) / (double)(rowCount == 0 ? 1 : rowCount); var rowsLeft = RowSource.RowCount - rowCount; var secondsLeft = (int)((double)(rowsLeft * avgMillisPerRow) / 1000.0); lastCheck = DateTime.Now; TimeSpan ts = new TimeSpan(0, 0, secondsLeft); var message = string.Format("Importing rows - Stage 2 ({0} of {1}). {2} remaining.", rowCount, RowSource.RowCount, ts.ToString()); ProgressMsg(message, percent); lastPercent = percent; } } ProgressMsg("Importing rows - Stage 2 Complete", 100); LogMsg("{0} Rows successfully imported, {1} rows failed with errors", _successCount, _errorCount); LogMsg("Cleaning up staging database..."); if (RowSource.Service.GetErrorCount() > 0) { if (ParentWindow.Question("Errors were encountered during the import. Rejected rows can be corrected and re-imported by re-running the import wizard and selecting the 'Import Error Database' option. Would you like to save the rejected rows so that they can be corrected and re-imported?", "Save rejected rows?", System.Windows.MessageBoxImage.Exclamation)) { // Clean out just the imported records, leaving just the error rows... LogMsg("Purging successfully imported rows from staging database..."); RowSource.Service.PurgeImportedRecords(); LogMsg("Saving mapping information to staging database..."); RowSource.Service.SaveMappingInfo(Importer, Mappings); LogMsg("Disconnecting from staging database..."); RowSource.Service.Disconnect(); var dlg = new Microsoft.Win32.SaveFileDialog(); dlg.Filter = "SQLite database files|*.sqlite|All files (*.*)|*.*"; dlg.Title = "Save error database file"; if (dlg.ShowDialog().ValueOrFalse()) { LogMsg("Copying staging database from {0} to {1}", RowSource.Service.FileName, dlg.FileName); System.IO.File.Copy(RowSource.Service.FileName, dlg.FileName, true); } } } connection.Close(); }
private void PreloadMappings(ImportWizardContext context) { var service = new ImportService(PluginManager.Instance.User); var fields = service.GetImportFields(); var mappings = new List <ImportFieldMapping>(); if (_options != null && _options.RowSource != null) { _options.RowSource.Reset(); var columns = _options.RowSource.ColumnNames; foreach (String colName in columns) { var candidate = fields.Find((field) => { if (!string.IsNullOrEmpty(colName)) { // First try a simple match of the name... if (field.DisplayName.Equals(colName, StringComparison.CurrentCultureIgnoreCase)) { return(true); } ; // Next convert all underscores to spaces and try that.... var test = colName.Replace("_", " "); if (field.DisplayName.Equals(test, StringComparison.CurrentCultureIgnoreCase)) { return(true); } } return(false); }); var mapping = new ImportFieldMapping { SourceColumn = colName, TargetColumn = "Material.Other", DefaultValue = null, IsFixed = false }; if (candidate != null) { mapping.TargetColumn = string.Format("{0}.{1}", candidate.Category, candidate.DisplayName); } else { DarwinCoreField dwc; if (Enum.TryParse <DarwinCoreField>(colName, out dwc)) { switch (dwc) { case DarwinCoreField.fieldNotes: case DarwinCoreField.validatorNotes: case DarwinCoreField.transcriberNotes: mapping.TargetColumn = "Material.Notes"; break; case DarwinCoreField.associatedMedia: mapping.TargetColumn = "Material.Multimedia"; break; } } } mappings.Add(mapping); } } context.FieldMappings = mappings; }
public override bool GetOptions(System.Windows.Window parentWindow, ImportWizardContext context) { var frm = new CSVImportOptionsWindow(_options); frm.Owner = parentWindow; frm.WindowStartupLocation = WindowStartupLocation.CenterOwner; if (frm.ShowDialog().GetValueOrDefault(false)) { _options = new CSVImporterOptions { Filename = frm.Filename, Delimiter = frm.Delimiter, FirstRowContainsNames = frm.IsFirstRowContainNames, ColumnNames = frm.ColumnNames }; return true; } return false; }