Пример #1
0
        public static ExperimentViewModel ToViewModel([NotNull] this ExperimentEntity experimentEntity)
        {
            var experimentViewModel = new ExperimentViewModel
            {
                DateTime         = experimentEntity.DateTime,
                BaseDistance     = experimentEntity.BaseDistance,
                Category         = experimentEntity.Category,
                DistanceRange    = new ObservableCollection <double>(experimentEntity.DistanceRange),
                ExperimentStatus = experimentEntity.ExperimentStatus,
                Name             = experimentEntity.Name,
                PhysicModel      = experimentEntity.PhysicModel == null? null : ParamsRetrieverManager.GetParamsRetrievers().FirstOrDefault(x => x.Name == experimentEntity.PhysicModel),
                SpectrometerName = experimentEntity.Spectrometer,
                WaveMax          = experimentEntity.WaveMax,
                WaveMin          = experimentEntity.WaveMin,
                RetrievedParams  = (experimentEntity.RetrievedParams ?? new List <Params>()).ToArray(),
                SavedData        = experimentEntity.Data == null? null : new ExperimentEntityDataViewModel()
                {
                    WaveLengthArray = experimentEntity.Data.WaveLengthArray,
                    DataItems       = new FullyObservableCollection <ExperimentEntityDataItemViewModel>(experimentEntity.Data.DataItems.Select(x => x.ToViewModel()))
                }
            };

            //todo move to other place
            EntityDataProvider <ExperimentEntity> .Instance.SaveManager.Map(experimentViewModel, experimentEntity);

            return(experimentViewModel);
        }
Пример #2
0
        private async void CreateExperimentAction()
        {
            var dialog = (BaseMetroDialog)Application.Current.Windows.OfType <MainWindow>().First().Resources["ExperimentDialog"];
            var experimentDialogViewModel = new ExperimentDialogViewModel
            {
                DialogCloseAction = async(vm) =>
                {
                    await MetroDialogCoordinator.HideMetroDialogAsync(this, dialog);
                },
                DialogAddAction = async(vm) =>
                {
                    var newExperimentVm = new ExperimentViewModel();
                    newExperimentVm.InitFieldsFrom(vm);
                    ExperimentListViewModel.ExperimentTileCollection.Add(newExperimentVm);
                    EntityDataProvider <ExperimentEntity> .Instance.SaveManager.Map(newExperimentVm);

                    Logger.Info(StringResourceProvider.Instance[StringResourceProvider.Keys.Experiment_PLACE_WasAdded].Value, newExperimentVm.Name);
                    //todo save previous selected item data

                    ExperimentListViewModel.SelectedExperimentTile = null;
                    await Task.Delay(300);

                    ExperimentListViewModel.SelectedExperimentTile = newExperimentVm;
                    await MetroDialogCoordinator.HideMetroDialogAsync(this, dialog);
                },
                Name             = "Experiment #" + DateTime.Now.ToString("yyyy MMMM dd HH:mm"),
                DateTime         = DateTime.Now,
                Category         = "Spectrum",
                WaveMax          = 720,
                WaveMin          = 430,
                ExperimentStatus = ExperimentStatus.Unknown,
                //DistanceRange = new ObservableCollection<double>() { 1.25, 1.5, 1.75, 2, 2.5 },
                DistanceRange = new ObservableCollection <double>()
                {
                    1.25, 1.375, 1.5, 1.625, 1.75, 1.875, 2, 2.25, 2.5
                },
                SpectrometerName = "LOTIS CMS-400",

                BaseDistance  = 1.25,
                DistanceToAdd = 2
            };

            //dialog.Content = experimentDialogViewModel;
            dialog.DataContext = experimentDialogViewModel;
            experimentDialogViewModel.PhysicModel = ParamsRetrieverManager.GetParamsRetrievers().FirstOrDefault();
            await MetroDialogCoordinator.ShowMetroDialogAsync(this, dialog);
        }