示例#1
0
        public void ShowImport()
        {
            User.CheckPermission(PermissionCategory.IMPORT_MATERIAL, PERMISSION_MASK.ALLOW, "You do not have sufficient privileges to import into BioLink!");

            if (_importWizard == null)
            {
                var context = new ImportWizardContext();

                Func <List <FieldDescriptor> > fieldSource = () => {
                    var service = new ImportService(User);
                    return(service.GetImportFields());
                };

                Func <ImportProcessor> importProcessorFactory = () => {
                    return(new MaterialImportProcessor());
                };

                _importWizard = new ImportWizard(User, "Import Data", context, new ImportFilterSelection(), new ImportMappingPage(fieldSource), new ImportPage(importProcessorFactory));

                _importWizard.Closed += new EventHandler((sender, e) => {
                    _importWizard = null;
                });
            }

            _importWizard.Show();
            _importWizard.Focus();
        }
        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;
        }