Ejemplo n.º 1
0
        private void loadImportedDataSetsFromConfiguration(ImporterConfiguration configuration)
        {
            _confirmationPresenter.SetDataSetNames(_dataSource.NamesFromConvention()); //this could probably be in the apply
            //About NanSettings: we do actually read the nanSettings in import dataSheets
            //we just never update the editor on the view, which actually is a problem
            var sheets = new Cache <string, DataSheet>();

            foreach (var sheetName in _configuration.LoadedSheets)
            {
                _importerDataPresenter.ImportedSheets.AddSheet(_dataSourceFile.DataSheets.GetDataSheetByName(sheetName));
            }

            try
            {
                var namingConvention = configuration.NamingConventions;
                loadSheets(_dataSourceFile, _importerDataPresenter.ImportedSheets.GetDataSheetNames(), configuration.FilterString, namingConvention);
                _confirmationPresenter.TriggerNamingConventionChanged(namingConvention);
            }
            catch (AbstractImporterException e)
            {
                _dialogCreator.MessageBoxError(e.Message);
            }

            _importerDataPresenter.DisableImportedSheets();
        }
        protected override void Context()
        {
            base.Context();

            _importerConfiguration    = A.Fake <OSPSuite.Core.Import.ImporterConfiguration>();
            _importerConfiguration.Id = "Id";
            _importerConfiguration.AddParameter(A.Fake <DataFormatParameter>());

            A.CallTo(() => _dimensionFactory.DimensionsSortedByName).Returns(new []
            {
                DimensionFactoryForSpecs.MassDimension,
                DimensionFactoryForSpecs.TimeDimension,
                Constants.Dimension.NO_DIMENSION
            });
            A.CallTo(() => _dimensionFactory.Dimension(Constants.Dimension.TIME)).Returns(DimensionFactoryForSpecs.TimeDimension);

            A.CallTo(() => _context.PublishEvent(A <ObservedDataAddedEvent> ._)).Invokes(call => _event = call.GetArgument <ObservedDataAddedEvent>(0));
            _dataRepository.Name          = "A";
            _dataRepository.BaseGrid.Name = "B";

            A.CallTo(() => _containerTask.CreateUniqueName(A <IEnumerable <IWithName> > ._, "A", true)).Returns("A");

            _dataRepository.Add(new DataColumn("name", DimensionFactoryForSpecs.MassDimension, _dataRepository.BaseGrid));

            A.CallTo(() => _dataImporter.ImportDataSets(A <IReadOnlyList <MetaDataCategory> > .Ignored, A <IReadOnlyList <ColumnInfo> > .Ignored, A <DataImporterSettings> .Ignored, A <string> .Ignored))
            .Returns((new[] { _dataRepository }, _importerConfiguration));
        }
Ejemplo n.º 3
0
        protected override void Context()
        {
            base.Context();
            _dialogCreator         = A.Fake <IDialogCreator>();
            _importer              = IoC.Container.Resolve <IImporter>();
            _applicationController = A.Fake <ApplicationController>();

            sut = new DataImporter(_dialogCreator, _importer, _applicationController, _dimensionFactory);

            _importerConfiguration = new ImporterConfiguration {
                FileName = "IntegrationSample1.xlsx", NamingConventions = "{Source}.{Sheet}.{Organ}.{Molecule}"
            };
            _importerConfiguration.AddToLoadedSheets("Sheet1");
            _importerConfigurationMW = new ImporterConfiguration {
                FileName = "IntegrationSample1.xlsx", NamingConventions = "{Source}.{Sheet}.{Organ}.{Molecule}"
            };
            _importerConfigurationMW.AddToLoadedSheets("Sheet1");
            _metaDataCategories   = (IReadOnlyList <MetaDataCategory>)sut.DefaultMetaDataCategoriesForObservedData();
            _dataImporterSettings = new DataImporterSettings();
            _dataImporterSettings.NameOfMetaDataHoldingMoleculeInformation        = "Molecule";
            _dataImporterSettings.NameOfMetaDataHoldingMolecularWeightInformation = "Molecular Weight";
            _dataImporterSettings.IgnoreSheetNamesAtImport      = true;
            _dataImporterSettings.CheckMolWeightAgainstMolecule = false;
            _columnInfos = getDefaultColumnInfos();

            _metaDataCategories.First(md => md.Name == _dataImporterSettings.NameOfMetaDataHoldingMoleculeInformation).ListOfValues.Add("TestInputMolecule", "233");
        }
Ejemplo n.º 4
0
        public void SaveConfiguration()
        {
            var fileName = _dialogCreator.AskForFileToSave(Captions.Importer.SaveConfiguration, Constants.Filter.XML_FILE_FILTER, Constants.DirectoryKey.OBSERVED_DATA);

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            _configuration = UpdateAndGetConfiguration();
            _pkmlPersistor.SaveToPKML(_configuration, fileName);
        }
Ejemplo n.º 5
0
        private void applyConfiguration(ImporterConfiguration configuration)
        {
            var excelColumnNames         = _columnMappingPresenter.GetAllAvailableExcelColumns();
            var listOfNonExistingColumns = configuration.Parameters.Where(parameter => !excelColumnNames.Contains(parameter.ColumnName) && parameter.ComesFromColumn()).ToList();

            if (listOfNonExistingColumns.Any())
            {
                var confirm = _dialogCreator.MessageBoxYesNo(Captions.Importer.ConfirmDroppingExcelColumns(string.Join("\n", listOfNonExistingColumns.Select(x => x.ColumnName))));

                if (confirm == ViewResult.No)
                {
                    return;
                }

                foreach (var element in listOfNonExistingColumns)
                {
                    configuration.RemoveParameter(element);
                }
            }

            var mappings = configuration.Parameters.OfType <MappingDataFormatParameter>();
            var listOfNonExistingUnitColumns = mappings.Where(parameter => !parameter.MappedColumn.Unit.ColumnName.IsNullOrEmpty() && !excelColumnNames.Contains(parameter.MappedColumn.Unit.ColumnName)).ToList();

            foreach (var element in listOfNonExistingUnitColumns)
            {
                element.MappedColumn.Unit      = new UnitDescription();
                element.MappedColumn.Dimension = null;
            }

            _importerDataPresenter.ResetLoadedSheets();
            _view.DisableConfirmationView();

            _configuration = configuration;

            if (!_configuration.NamingConventions.IsNullOrEmpty())
            {
                _confirmationPresenter.TriggerNamingConventionChanged(_configuration.NamingConventions);
            }

            _dataSourceFile.Format.CopyParametersFromConfiguration(_configuration);

            _columnMappingPresenter.SetDataFormat(_dataSourceFile.Format);
            _columnMappingPresenter.ValidateMapping();
            _nanPresenter.Settings = configuration.NanSettings;
            if (configuration.NanSettings != null)
            {
                _nanPresenter.FillNaNSettings();
            }
            _importerDataPresenter.SetFilter(configuration.FilterString);
        }
Ejemplo n.º 6
0
        protected override void Context()
        {
            _dataImporterSettings = new DataImporterSettings();
            base.Context();
            _mapper = A.Fake <IDataSetToDataRepositoryMapper>();
            var cache   = new Cache <string, IDataSet>();
            var dataSet = new DataSet();

            dataSet.AddData(new List <ParsedDataSet>()
            {
                new ParsedDataSet(new List <string>(), A.Fake <DataSheet>(), new List <UnformattedRow>(), new Dictionary <ExtendedColumn, IList <SimulationPoint> >())
            });
            _dataSource = A.Fake <IDataSource>();
            A.CallTo(() => _dataSource.DataSets).Returns(cache);
            cache.Add("sheet1", dataSet);
            var dataRepository = new DataRepository {
                Name = "name"
            };

            dataRepository.ExtendedProperties.Add(new ExtendedProperty <string>()
            {
                Name = "Molecule", Value = "Molecule1"
            });
            dataRepository.ExtendedProperties.Add(new ExtendedProperty <string>()
            {
                Name = "Mol weight", Value = 22.0.ToString()
            });

            var dataColumn = new BaseGrid("Time", A.Fake <IDimension>());
            var dataInfo   = new DataInfo(ColumnOrigins.Undefined);

            dataColumn.DataInfo = dataInfo;
            dataRepository.Add(dataColumn);

            var moleculeDataColumn = new DataColumn("Measurement", A.Fake <IDimension>(), dataColumn);

            dataColumn.DataInfo = dataInfo;
            dataRepository.Add(moleculeDataColumn);
            A.CallTo(() => _mapper.ConvertImportDataSet(A <ImportedDataSet> .Ignored)).Returns(new DataSetToDataRepositoryMappingResult(dataRepository));

            var moleculeMetaDataCategory = createMetaDataCategory <string>("Molecule", isMandatory: true);

            moleculeMetaDataCategory.IsListOfValuesFixed = true;
            moleculeMetaDataCategory.DefaultValue        = "Molecule1";
            moleculeMetaDataCategory.ListOfValues.Add("Molecule1", 6.0.ToString());
            moleculeMetaDataCategory.ShouldListOfValuesBeIncluded = true;
            moleculeMetaDataCategory.SelectDefaultValue           = true;

            _metaDataCategories = new List <MetaDataCategory>()
            {
                moleculeMetaDataCategory,
                createMetaDataCategory <string>("Mol weight", isMandatory: false)
            };
            var dataFormat = A.Fake <IDataFormat>();

            A.CallTo(() => dataFormat.Parameters).Returns(new List <DataFormatParameter>());
            _dataSourceFile = A.Fake <IDataSourceFile>();
            A.CallTo(() => _dataSourceFile.Format).Returns(dataFormat);
            _importerDataPresenter = A.Fake <IImporterDataPresenter>();
            A.CallTo(() => _importerDataPresenter.SetDataSource(A <string> .Ignored)).Returns(_dataSourceFile);
            _importerView = A.Fake <IImporterView>();
            _importer     = A.Fake <IImporter>();
            _nanPresenter = A.Fake <INanPresenter>();
            _importConfirmationPresenter = A.Fake <IImportConfirmationPresenter>();
            _columnMappingPresenter      = A.Fake <IColumnMappingPresenter>();
            _sourceFilePresenter         = A.Fake <ISourceFilePresenter>();
            _dialogCreator = A.Fake <IDialogCreator>();
            _pkmlPeristor  = A.Fake <IPKMLPersistor>();

            sut = new ImporterPresenterForTest(
                _importerView,
                _mapper,
                _importer,
                _nanPresenter,
                _importerDataPresenter,
                _importConfirmationPresenter,
                _columnMappingPresenter,
                _sourceFilePresenter,
                _dialogCreator,
                _pkmlPeristor,
                _dataSource);
            _importerConfiguration = A.Fake <ImporterConfiguration>();
            sut.LoadConfiguration(_importerConfiguration, "");
            sut.SetSettings(_metaDataCategories, new ColumnInfoCache(), _dataImporterSettings);
        }
Ejemplo n.º 7
0
 public void LoadConfiguration(ImporterConfiguration configuration, string fileName)
 {
     openFile(fileName);
     applyConfiguration(configuration);
     loadImportedDataSetsFromConfiguration(configuration);
 }
 public void CopyParametersFromConfiguration(OSPSuite.Core.Import.ImporterConfiguration configuration)
 {
     Parameters = new List <DataFormatParameter>(configuration.Parameters);
 }