示例#1
0
        public virtual void Update(Observable.IObservable <WeatherInfo> subject, WeatherInfo data)
        {
            WeatherStationLocation location;

            if (subject == _subjectInBuilding)
            {
                location = WeatherStationLocation.In;
            }
            else if (subject == _subjectOutBuilding)
            {
                location = WeatherStationLocation.Out;
            }
            else
            {
                throw new ApplicationException("Weather station is undefined");
            }

            foreach (MeasurementStatisticPrinterDuo printer in _printers)
            {
                printer.UpdateStatistic(location, data);
            }

            if (data.WindInfo != null)
            {
                _windSpeedPrinter.UpdateStatistic(location, data);
                _windDirectionPrinter.UpdateStatistic(location, data.WindInfo);
            }

            Console.WriteLine("-----------------------");
        }
示例#2
0
        /// <summary>
        /// </summary>
        /// <param name="collection">A collection instance. The most common case is ConcurrentQuery object.</param>
        /// <param name="observable">An observable instance. Passing this parameter you could choose between event and command-collection based implementations.</param>
        public CollectionBroker([NotNull] IProducerConsumerCollection <T> collection, Observable.IObservable <T> observable)
        {
            _collection = collection;
            _observable = observable;

            IsSelfControlled = false;
        }
示例#3
0
        public virtual void Update(Observable.IObservable <WeatherInfo> subject, WeatherInfo data)
        {
            if (subject == _subjectInBuilding)
            {
                Console.WriteLine($"Location: in building");
            }
            else if (subject == _subjectOutBuilding)
            {
                Console.WriteLine($"Location: out building");
            }
            else
            {
                throw new ApplicationException("Weather station is undefined");
            }

            Console.WriteLine($"Current temperature {data.Temperature}");
            Console.WriteLine($"Current humidity {data.Humidity}");
            Console.WriteLine($"Current pressure {data.Pressure}");
            if (data.WindInfo != null)
            {
                Console.WriteLine($"Current wind direction {data.WindInfo.WindDirection}");
                Console.WriteLine($"Current wind speed {data.WindInfo.WindSpeed}");
            }
            Console.WriteLine("-----------------------");
        }
示例#4
0
 public Display(Observable <WeatherInfo> inSubject, Observable <WeatherInfo> outSubject)
 {
     _subjectInBuilding  = inSubject;
     _subjectOutBuilding = outSubject;
     _subjectInBuilding.RegisterObserver(this);
     _subjectOutBuilding.RegisterObserver(this);
 }
        public AllFieldsFilledDataEntryForm()
        {
            var view  = new AllFieldsFilledDataEntryFormView();
            var ended = new Observable.Publisher <Unit>();

            Ended = ended;
            View  = view;

            var strEntry = LocalValueFieldBuilder.Build(
                view.StringEntry,
                (x, errors) => errors.IfTrueAdd(
                    string.IsNullOrWhiteSpace(x) || x.Length < 4,
                    "Text must be at least 4 chars long"),
                (x, errors) => errors.IfTrueAdd(
                    string.IsNullOrWhiteSpace(x) || x.Length > 10,
                    "Text must be no longer than 10 chars long")
                );

            var intEntry = LocalValueFieldBuilder.BuildNullableInt(
                view.IntEntry,
                (x, errors) => errors.IfTrueAdd(!x.HasValue || x < 1234, "Number must be bigger than 1234")
                );

            var decEntry = LocalValueFieldBuilder.BuildNullableDecimal(
                view.DecimalEntry,
                DecimalFormat.WithTwoDecPlaces,
                (x, errors) => errors.IfTrueAdd(!x.HasValue || x < 5.6m,
                                                "Number must be bigger than " + I18n.Localize(5.6m, DecimalFormat.WithOneDecPlace))
                );

            //this field is used to show that values on screen are not necessarily values within model.
            //In other words: when validator rejected value from user wrong value and error message stays on screen BUT model keeps its last-accepted-value
            var summaryLine = LocalValueFieldBuilder.Build("", view.SummaryLine);

            void UpdateSummaryLine()
            {
                var decVal = !decEntry.Value.HasValue ? "" : I18n.Localize(decEntry.Value.Value, DecimalFormat.WithOneDecPlace);

                summaryLine.DoProgrammaticChange(
                    $@"Accepted vals: Text={strEntry.Value} Int={intEntry.Value} Decimal={decVal}"
                    );
            }

            strEntry.Changed += (_, __, ___, ____, _____) => UpdateSummaryLine();
            intEntry.Changed += (_, __, ___, ____, _____) => UpdateSummaryLine();
            decEntry.Changed += (_, __, ___, ____, _____) => UpdateSummaryLine();

            UpdateSummaryLine();

            var confirm = LocalActionBuilder.Build(view.ConfirmAction, () => ended.Fire(Unit.Instance));

            confirm.BindEnableAndInitializeAsObserving(x => {
                x.Observes(strEntry);
                x.Observes(intEntry);
                x.Observes(decEntry);
            });
        }
示例#6
0
        public StatsDisplay(Observable <WeatherInfo> inSubject, Observable <WeatherInfo> outSubject)
        {
            _subjectInBuilding  = inSubject;
            _subjectOutBuilding = outSubject;
            _subjectInBuilding.RegisterObserver(this);
            _subjectOutBuilding.RegisterObserver(this);

            _windDirectionPrinter = new WindDirectionStatisticPrinterDuo("Wind direction");
            _windSpeedPrinter     = new MeasurementStatisticPrinterDuo("Wind speed", wi => wi.WindInfo.WindSpeed);
        }