Exemple #1
0
        public ProfileStepTileViewModel(int stepId, StepData data)
        {
            if (data.IsRampStep)
            {
                StepDescription = string.Format("{0}. {1} from {2:0}F to {3:0}F over {4}",
                                                stepId,
                                                "Ramp",
                                                TemperatureConvert.ConvertToFarentheit(data.StartingTemp),
                                                TemperatureConvert.ConvertToFarentheit(data.EndingTemp),
                                                StringifyTimeSpan(data.Duration));
            }
            else
            {
                StepDescription = string.Format("{0}. {1} {2:0}F for {3}",
                                                stepId,
                                                "Hold",
                                                TemperatureConvert.ConvertToFarentheit(data.StartingTemp),
                                                StringifyTimeSpan(data.Duration));
            }

            EditStep      = ReactiveCommand.Create();
            EditStepFired = this.WhenAnyObservable(x => x.EditStep).Select(x => stepId);

            DeleteStep      = ReactiveCommand.Create();
            DeleteStepFired = this.WhenAnyObservable(x => x.DeleteStep).Select(x => stepId);
        }
        public CreateProfileViewModel(IScreen hostScreen, IFermentationControllerAPI api)
        {
            HostScreen = hostScreen;

            AllSteps = new ReactiveList <StepData> ();

            StepTiles = AllSteps.CreateDerivedCollection(x => new ProfileStepTileViewModel(x.StepId, x));

            var canAddStep = this.WhenAnyValue(x => x.StepDays, x => x.StepHours, x => x.StepMins)
                             .Select(x => x.Item1 > 0 || x.Item2 > 0 || x.Item3 > 0);

            AddStep = ReactiveCommand.Create(canAddStep);
            AddStep
            .ObserveOn(RxApp.MainThreadScheduler)
            .Select(x => new StepData(TemperatureConvert.ConvertToCelsius(StartingTemp),
                                      TemperatureConvert.ConvertToCelsius(EndingTemp),
                                      new TimeSpan(StepDays,
                                                   StepHours,
                                                   StepMins,
                                                   0),
                                      AllSteps.Count + 1,
                                      IsRampStep))
            .Subscribe(AllSteps.Add);

            var canCommit = this.WhenAnyValue(x => x.Name, x => x.AllSteps).Select(x => !string.IsNullOrWhiteSpace(x.Item1) && x.Item2.Count > 0);

            CommitProfile = ReactiveCommand.CreateAsyncTask(canCommit, (x, ct) => {
                //TODO: create the profile dto
                return(api.StoreProfile(Name, new byte[0]));
            }, RxApp.MainThreadScheduler);

            //on non-ramp steps the starting and ending temp are the same
            this.WhenAnyValue(x => x.StartingTemp, y => y.IsRampStep)
            .Where(x => !x.Item2)
            .Subscribe(x => EndingTemp = StartingTemp);
        }