示例#1
0
        private async void SaveValues(string param)
        {
            if (Values == null || Values.Count < 1)
            {
                await MetroDialogCoordinator.ShowMessageAsync(MainWindowDataContext,
                                                              StringResourceProvider.Instance[StringResourceProvider.Keys.DataIsEmpty].Value,
                                                              StringResourceProvider.Instance[StringResourceProvider.Keys.PleaseRunSpectrometerAndTryToGetSpectralMeasurements].Value);

                return;
            }

            var previousState = IsRealTimeSpectrometerData;

            IsRealTimeSpectrometerData = false;
            var dataName  = StringResourceProvider.Instance[param].Value;
            var @override = false;
            var item      = new ExperimentEntityDataItemViewModel();

            switch (param)
            {
            case "CurrentL":
                if (CurrentDistance == 0)
                {
                    await MetroDialogCoordinator.ShowMessageAsync(MainWindowDataContext,
                                                                  StringResourceProvider.Instance[StringResourceProvider.Keys.DistanceDoesNotDefined].Value,
                                                                  StringResourceProvider.Instance[StringResourceProvider.Keys.PleaseMoveDetectorForSomeDistance].Value);

                    IsRealTimeSpectrometerData = previousState;
                    return;
                }
                @override = SavedData?.DataItems != null &&
                            SavedData.DataItems.Any(x => x.Distance == CurrentDistance);
                if (@override)
                {
                    item = SavedData.DataItems.First(x => x.Distance == CurrentDistance);
                }
                else
                {
                    item.Distance = CurrentDistance;
                    item.IsBase   = BaseDistance == item.Distance;
                }

                dataName = $"L = {item.Distance}{(item.IsBase ? $"({StringResourceProvider.Instance[StringResourceProvider.Keys.Base]})" : "")}";
                break;

            case "Noise":
                @override = SavedData?.DataItems != null &&
                            SavedData.DataItems.Any(x => x.IsNoise);
                if (@override)
                {
                    item = SavedData.DataItems.First(x => x.IsNoise);
                }
                else
                {
                    item.Distance = 0;    //CurrentDistance;
                    item.IsNoise  = true;
                }
                break;

            case "Normalize":
                @override = SavedData?.DataItems != null &&
                            SavedData.DataItems.Any(x => x.IsNormalize);
                if (@override)
                {
                    item = SavedData.DataItems.First(x => x.IsNormalize);
                }
                else
                {
                    item.Distance    = 0; //CurrentDistance;
                    item.IsNormalize = true;
                }


                break;

            default:
                throw new InvalidEnumArgumentException($"'{param}' is undefined value");
            }

            if (@override)
            {
                //MessageDialogResult result = await this.MetroDialogCoordinator.ShowMessageAsync(MainWindowDataContext, "Data already exist", $"Do you wont to replace {dataName}?", MessageDialogStyle.AffirmativeAndNegative);
                MessageDialogResult result = await MetroDialogCoordinator.ShowMessageAsync(MainWindowDataContext,
                                                                                           StringResourceProvider.Instance[StringResourceProvider.Keys.DataAlreadyExist].Value,
                                                                                           $"{StringResourceProvider.Instance[StringResourceProvider.Keys.DoYouWantToReplace].Value} '{dataName}'?",
                                                                                           MessageDialogStyle.AffirmativeAndNegative);

                if (result == MessageDialogResult.Negative)
                {
                    IsRealTimeSpectrometerData = previousState;
                    return;
                }
            }

            item.IntensityArray       = Values.Select(x => x.Intencity).ToArray();
            item.IsAppliedNormalizing = IsNormalize;
            item.IsNoiseRemoved       = IsNoiseRemove;

            if (!@override)
            {
                if (SavedData?.DataItems != null)
                {
                    SavedData.DataItems.Add(item);
                }
                else if (SavedData == null)
                {
                    SavedData = new ExperimentEntityDataViewModel()
                    {
                        WaveLengthArray = Values.Select(x => x.WaveLength).ToArray(),
                        DataItems       = new FullyObservableCollection <ExperimentEntityDataItemViewModel>()
                        {
                            item
                        }
                    };
                }
                else if (SavedData.DataItems == null)
                {
                    SavedData.WaveLengthArray = Values.Select(x => x.WaveLength).ToArray();
                    SavedData.DataItems       = new FullyObservableCollection <ExperimentEntityDataItemViewModel>()
                    {
                        item
                    };
                }
            }
            SetDataToHelper();
            NotifyPropertyChanged(nameof(IsShowSavedDataEnabled));
            IsRealTimeSpectrometerData = previousState;
        }
示例#2
0
        private async void StartAutomaticallyMeasurements()
        {
            //todo rewrite to states and events
            string message = null;
            var    isReady = true;

            if (!_spectrometer.IsSpectrometerReady)
            {
                message =
                    StringResourceProvider.Instance[
                        StringResourceProvider.Keys.PleaseRunSpectrometerAndTryToGetSpectralMeasurements].Value;
                isReady = false;
            }
            if (!_stepper.IsStepperReady)
            {
                message =
                    StringResourceProvider.Instance[
                        StringResourceProvider.Keys.PleaseMoveDetectorForSomeDistance].Value;
                isReady = false;
            }

            if (!isReady)
            {
                IsWait      = true;
                WaitMessage =
                    StringResourceProvider.Instance[StringResourceProvider.Keys.SpectrometerFailedSeeLogForDetails].Value;
                Logger.Warn(message);
                await Task.Delay(3000);

                IsWait = false;
                return;
            }

            try
            {
                _isAutamaticMeasurements = true;
                var newData = new ExperimentEntityDataViewModel();
                newData.WaveLengthArray = Values.ToArray().Select(x => x.WaveLength).ToArray();
                var list = new List <ExperimentEntityDataItemViewModel>();


                foreach (var d in DistanceRange)
                {
                    IsWait  = true;
                    message =
                        string.Format(
                            StringResourceProvider.Instance[StringResourceProvider.Keys.StartMovingToDistance_PLACE_Mm]
                            .Value, d);
                    Logger.Info(message);
                    WaitMessage = message;
                    await _stepper.GoToDistanceAsync(d);

                    //TODO REWRITE!!!
                    await Task.Delay(ExposureTime *3);

                    var item = new ExperimentEntityDataItemViewModel();
                    item.Distance = CurrentDistance;
                    item.IsBase   = BaseDistance == item.Distance;

                    var values = Values.ToArray();
                    item.IntensityArray       = values.Select(x => x.Intencity).ToArray();
                    item.IsAppliedNormalizing = IsNormalize;
                    item.IsNoiseRemoved       = IsNoiseRemove;
                    //item.IsShow = true;
                    list.Add(item);
                }

                if (SavedData?.DataItems?.Any(x => x.IsNoise) ?? false)
                {
                    list.Add(SavedData.DataItems.First(x => x.IsNoise));
                }
                if (SavedData?.DataItems?.Any(x => x.IsNormalize) ?? false)
                {
                    list.Add(SavedData.DataItems.First(x => x.IsNormalize));
                }

                message = $"--=== {StringResourceProvider.Instance[StringResourceProvider.Keys.Saving]} ===--";
                Logger.Info(message);
                WaitMessage       = message;
                newData.DataItems = new FullyObservableCollection <ExperimentEntityDataItemViewModel>(list);
                SavedData         = newData;


                Logger.Info(
                    StringResourceProvider.Instance[
                        StringResourceProvider.Keys.SpectraForAllDistancesSuccessfullyRecieved].Value);
                await _stepper.GoToDistanceAsync(0);

                RetrieveParams();
            }
            catch (Exception e)
            {
                WaitMessage =
                    StringResourceProvider.Instance[StringResourceProvider.Keys.SpectrometerFailedSeeLogForDetails]
                    .Value;
                await Task.Delay(3000);

                Logger.Error(e);
            }
            finally
            {
                _isAutamaticMeasurements = false;
            }
            IsWait = false;
        }