public SoundSpeedProfileViewModel(IHRCSaveFileService saveFile)
 {
     _saveFileService = saveFile;
     _propertyObserver = new PropertyObserver<SoundSpeedProfileViewModel>(this)
         .RegisterHandler(p => p.SoundSpeedProfile, SoundSpeedProfileChanged);
     var axisRanges = new RangeCollection();
     axisRanges.Add(new Range(0.1, 10));
     DesignTimeData = new SoundSpeedProfileViewModel
     {
         FourAxisSeriesViewModel = new FourAxisSeriesViewModel
         {
             BottomAxis =
             {
                 Visibility = Visibility.Visible,
                 Label = "Sound speed (m/s)",
             },
             LeftAxis =
             {
                 Visibility = Visibility.Visible,
                 Label = "Depth (m)",
                 IsInverted = true,
             },
             TopAxis = { Visibility = Visibility.Collapsed },
             RightAxis = { Visibility = Visibility.Collapsed },
         },
     };
     DesignTimeData.FourAxisSeriesViewModel.BottomAxis.DataRange = axisRanges;
     DesignTimeData.FourAxisSeriesViewModel.LeftAxis.DataRange = axisRanges;
 }
        public void NotifyPropertyChanged_Integer_Subscribe()
        {
            var actionRaisedCount = 0;
            var notifyPropertyChangedTestObject = new NotifyPropertyChangedTestObject {
                IntProperty = 1
            };

            using var observer = PropertyObserver.Observes(
                      notifyPropertyChangedTestObject.IntPropertyExpression,
                      () => actionRaisedCount++,
                      false);
            Assert.AreEqual(0, actionRaisedCount);
            notifyPropertyChangedTestObject.IntProperty = 2;
            Assert.AreEqual(0, actionRaisedCount);

            observer.Subscribe();
            notifyPropertyChangedTestObject.IntProperty = 3;
            Assert.AreEqual(1, actionRaisedCount);
            notifyPropertyChangedTestObject.IntProperty = 4;
            Assert.AreEqual(2, actionRaisedCount);

            observer.Unsubscribe();
            notifyPropertyChangedTestObject.IntProperty = 5;
            Assert.AreEqual(2, actionRaisedCount);
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigPresenter"/> class.
 /// </summary>
 /// <param name="config">The config.</param>
 public ConfigPresenter(ConfigProperties config, GameMetaDataModel game)
 {
     _config = config;
     _game   = game;
     InitializeCommands();
     _gameObserver = new PropertyObserver <GameMetaDataModel>(_game).RegisterHandler(o => o.GameNumber, o => OnPropertyChanged("GameNumber"));
 }
Example #4
0
        public void PropertyObserver_Getter_Fallback_Observes_instance_IntProperty_AutoActivateTrue()
        {
            var instance = new NotifyPropertyChangedClass1()
            {
                Class2 = null
            };
            var callCount = 0;

            using var observes = PropertyObserver.Observes(() => instance.Class2.IntProperty, true, () => callCount++, 99);
            Assert.AreEqual(0, callCount);
            Assert.AreEqual(99, observes.Value);

            instance.Class2 = new NotifyPropertyChangedClass2 {
                IntProperty = 1
            };
            Assert.AreEqual(1, callCount);
            Assert.AreEqual(1, observes.Value);

            instance.Class2.IntProperty = 2;
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(2, observes.Value);

            observes.Deactivate();
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(2, observes.Value);

            instance.Class2.IntProperty = 3;
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(3, observes.Value);

            instance.Class2 = null;
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(99, observes.Value);
        }
        public void PropertyObserver_Observes_instance1_IntProperty_AutoActivateTrue()
        {
            var instance1 = new NotifyPropertyChangedClass1 {
                Class2 = null
            };
            var instance2 = new NotifyPropertyChangedClass1 {
                Class2 = null
            };
            var callCount = 0;

            using var observes = PropertyObserver.Observes(
                      instance1,
                      instance2,
                      (i1, i2) => i1.Class2.IntProperty,
                      true,
                      () => callCount++);
            Assert.AreEqual(0, callCount);

            instance1.Class2 = new NotifyPropertyChangedClass2 {
                IntProperty = 1
            };
            Assert.AreEqual(1, callCount);

            instance1.Class2.IntProperty = 2;
            Assert.AreEqual(2, callCount);

            observes.Deactivate();
            Assert.AreEqual(2, callCount);

            instance1.Class2.IntProperty = 3;
            Assert.AreEqual(2, callCount);
        }
        public void NotifyPropertyChanged_OwnerAndExpression_ObservesIntegerAndBoolean_Test()
        {
            var actionIntegerRaised = false;
            var actionBooleanRaised = false;

            var notifyPropertyChangedTestObject =
                new NotifyPropertyChangedTestObject {
                IntProperty = 1, BoolProperty = false
            };

            using var integerObserver = PropertyObserver.Observes(
                      notifyPropertyChangedTestObject,
                      o => o.IntProperty,
                      () => actionIntegerRaised = true);

            using var booleanObserver = PropertyObserver.Observes(
                      notifyPropertyChangedTestObject,
                      o => o.BoolProperty,
                      () => actionBooleanRaised = true);

            Assert.False(actionIntegerRaised);
            Assert.False(actionBooleanRaised);
            notifyPropertyChangedTestObject.BoolProperty = true;
            Assert.True(actionBooleanRaised);
            Assert.False(actionIntegerRaised);
            notifyPropertyChangedTestObject.IntProperty = 2;
            Assert.True(actionBooleanRaised);
            Assert.True(actionIntegerRaised);
        }
Example #7
0
        public void UnregisterShouldThrowWhenExpressionIsNull()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.UnregisterHandler((Expression <Func <DummyClass, object> >)null);
        }
        public EntityViewModel(IDialogService dialogService)
        {
            _dialogService = dialogService;

            Search = new RelayCommand(PrivateSearch);

            RefreshList = new RelayCommand(() =>
            {
                if (SdtdConsole.Instance.IsConnected == false)
                {
                    _dialogService.ShowInformation("请先连接服务器");
                }
                else
                {
                    RequestData();
                }
            });

            _currentPropertyObserver = new PropertyObserver <EntityViewModel>(this);
            _currentPropertyObserver.RegisterHandler(p => p.SearchText, (vm) => { vm.PrivateSearch(); });

            SdtdConsole.Instance.ReceivedTempListData += OnReceivedTempListData;

            Task.Run(() =>
            {
                Thread.Sleep(100);
                RequestData();
            });
        }
Example #9
0
        public ItemViewModel(IDispatcherService dispatcherService, IDialogService dialogService)
        {
            _dispatcherService = dispatcherService;
            _dialogService     = dialogService;

            ColoredImageDatas = new ObservableCollection <ColoredImageData>();

            Search = new RelayCommand(PrivateSearch);

            currentPropertyObserver = new PropertyObserver <ItemViewModel>(this);
            currentPropertyObserver.RegisterHandler(p => p.SearchText, (vm) => { vm.PrivateSearch(); });

            Task.Run(() =>
            {
                try
                {
                    LoadXml(ColoredImageDatas, XmlPath);
                }
                catch (Exception ex)
                {
                    string title = string.Format("加载 {0} 失败", XmlPath);

                    Log.Error(ex, title);

                    _dispatcherService.InvokeAsync(() =>
                    {
                        _dialogService.ShowInformation(ex.Message, title);
                    });
                }
            });
        }
        protected CoordinateConversionDockpaneViewModel()
        {
            _coordinateConversionView   = new CoordinateConversionView();
            HasInputError               = false;
            IsHistoryUpdate             = true;
            IsToolGenerated             = false;
            AddNewOCCommand             = new CoordinateConversionLibrary.Helpers.RelayCommand(OnAddNewOCCommand);
            ActivatePointToolCommand    = new CoordinateConversionLibrary.Helpers.RelayCommand(OnMapToolCommand);
            FlashPointCommand           = new CoordinateConversionLibrary.Helpers.RelayCommand(OnFlashPointCommand);
            CopyAllCommand              = new CoordinateConversionLibrary.Helpers.RelayCommand(OnCopyAllCommand);
            EditPropertiesDialogCommand = new CoordinateConversionLibrary.Helpers.RelayCommand(OnEditPropertiesDialogCommand);
            Mediator.Register(CoordinateConversionLibrary.Constants.RequestCoordinateBroadcast, OnBCNeeded);
            InputCoordinateHistoryList = new ObservableCollection <string>();
            MapSelectionChangedEvent.Subscribe(OnSelectionChanged);

            var ctvm = CTView.Resources["CTViewModel"] as CoordinateConversionViewModel;

            if (ctvm != null)
            {
                ctvm.SetCoordinateGetter(proCoordGetter);
            }
            configObserver = new PropertyObserver <CoordinateConversionLibraryConfig>(CoordinateConversionViewModel.AddInConfig)
                             .RegisterHandler(n => n.DisplayCoordinateType, n => {
                if (proCoordGetter != null && proCoordGetter.Point != null)
                {
                    InputCoordinate = proCoordGetter.GetInputDisplayString();
                }
            });
        }
Example #11
0
        public ShellViewModel(
            IMessageBoxManager messageBoxManager,
            IWellDataImporter wellDataImporter,
            IWellProvider wellProvider,
            ITankProvider tankProvider,
            IWindowManager windowManager,
            IFactory <AddWellViewModel> wellViewModelFactory,
            IAutoUpdater autoUpdater)
        {
            _messageBoxManager    = messageBoxManager;
            _wellDataImporter     = wellDataImporter;
            _wellProvider         = wellProvider;
            _tankProvider         = tankProvider;
            _windowManager        = windowManager;
            _wellViewModelFactory = wellViewModelFactory;
            _autoUpdater          = autoUpdater;
            WellItems             = new BindableCollection <WellModel>();
            TankItems             = new BindableCollection <TankModel>();
            MessageQueue          = new SnackbarMessageQueue(TimeSpan.FromSeconds(2))
            {
                IgnoreDuplicate = true
            };

            _propertyObserver = new PropertyObserver <ShellViewModel>(this);

            _propertyObserver.OnChangeOf(x => x.SelectedWell).Do((vm) => LoadTanks(vm.SelectedWell).ConfigureAwait(false));
        }
        public OutputCoordinateViewModel()
        {
            ConfigCommand = new RelayCommand(OnConfigCommand);
            ExpandCommand = new RelayCommand(OnExpandCommand);
            DeleteCommand = new RelayCommand(OnDeleteCommand);
            CopyCommand = new RelayCommand(OnCopyCommand);

            Mediator.Register(CoordinateConversionLibrary.Constants.AddNewOutputCoordinate, OnAddNewOutputCoordinate);
            Mediator.Register(CoordinateConversionLibrary.Constants.CopyAllCoordinateOutputs, OnCopyAllCoordinateOutputs);

            //for testing without a config file, init a few sample items
            //OutputCoordinateList = new ObservableCollection<OutputCoordinateModel>();
            ////var tempProps = new Dictionary<string, string>() { { "Lat", "70.49N" }, { "Lon", "40.32W" } };
            ////var mgrsProps = new Dictionary<string, string>() { { "GZone", "17T" }, { "GSquare", "NE" }, { "Northing", "86309" }, { "Easting", "77770" } };
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "DD", CType = CoordinateType.DD, OutputCoordinate = "70.49N 40.32W" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "DMS", CType = CoordinateType.DMS, OutputCoordinate = "40°26'46\"N,79°58'56\"W", Format = "A0°B0'C0\"N X0°Y0'Z0\"E" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "MGRS", CType = CoordinateType.MGRS, OutputCoordinate = @"", Format = "Z S X00000 Y00000" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "UTM", CType = CoordinateType.UTM, OutputCoordinate = @"", Format = "Z#H X0 Y0" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "GARS", CType = CoordinateType.GARS, OutputCoordinate = @"", Format = "X#YQK" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "USNG", CType = CoordinateType.USNG, OutputCoordinate = @"", Format = "Z S X0 Y0" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "DDM", CType = CoordinateType.DDM, OutputCoordinate = @"", Format = "A0 B0.0### N X0 Y0.0### E" });

            //DefaultFormatList = new ObservableCollection<DefaultFormatModel>();

            //DefaultFormatList.Add(new DefaultFormatModel { CType = CoordinateType.DD, DefaultNameFormatDictionary = new SerializableDictionary<string, string> { { "70.49N 40.32W", "Y0.0#N X0.0#E" }, { "70.49N,40.32W", "Y0.0#N,X0.0#E" } } });

            configObserver = new PropertyObserver<CoordinateConversionLibraryConfig>(CoordinateConversionViewModel.AddInConfig)
            .RegisterHandler(n => n.OutputCoordinateList, n=> RaisePropertyChanged(()=> OutputCoordinateList));
        }
Example #13
0
 private void RegisterPropertiesChanged()
 {
     SettingsObserver = new PropertyObserver <Settings>(Settings)
                        .RegisterHandler(n => n.IsMoving, MovingCameraHandler)
                        .RegisterHandler(n => n.IsStatic, StaticCameraHandler)
                        .RegisterHandler(n => n.IsObserving, ObservingCameraHandler);
 }
Example #14
0
        public void RegisterShouldThrowWhenPropertyIsEmpty()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.RegisterHandler("", src => { });
        }
Example #15
0
        public void RegisterShouldThrowWhenHandlerIsNull2()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.RegisterHandler(src => src.Value, null);
        }
        protected CoordinateConversionDockpaneViewModel() 
        {
            _coordinateConversionView = new CoordinateConversionView();
            HasInputError = false;
            IsHistoryUpdate = true;
            IsToolGenerated = false;
            AddNewOCCommand = new CoordinateConversionLibrary.Helpers.RelayCommand(OnAddNewOCCommand);
            ActivatePointToolCommand = new CoordinateConversionLibrary.Helpers.RelayCommand(OnMapToolCommand);
            FlashPointCommand = new CoordinateConversionLibrary.Helpers.RelayCommand(OnFlashPointCommand);
            CopyAllCommand = new CoordinateConversionLibrary.Helpers.RelayCommand(OnCopyAllCommand);
            EditPropertiesDialogCommand = new CoordinateConversionLibrary.Helpers.RelayCommand(OnEditPropertiesDialogCommand);
            Mediator.Register(CoordinateConversionLibrary.Constants.RequestCoordinateBroadcast, OnBCNeeded);
            InputCoordinateHistoryList = new ObservableCollection<string>();
            MapSelectionChangedEvent.Subscribe(OnSelectionChanged);

            var ctvm = CTView.Resources["CTViewModel"] as CoordinateConversionViewModel;
            if (ctvm != null)
            {
                ctvm.SetCoordinateGetter(proCoordGetter);
            }
            configObserver = new PropertyObserver<CoordinateConversionLibraryConfig>(CoordinateConversionViewModel.AddInConfig)
            .RegisterHandler(n => n.DisplayCoordinateType, n => {
                if(proCoordGetter != null && proCoordGetter.Point != null)
                {
                    InputCoordinate = proCoordGetter.GetInputDisplayString();
                }
            });
        }
Example #17
0
        public void PropertyObserver_Observes_instance_IntProperty_AutoActivateFalse()
        {
            var instance = new NotifyPropertyChangedClass1()
            {
                Class2 = null
            };
            var callCount = 0;

            using var observes = PropertyObserver.Observes(() => instance.Class2.IntProperty, false, () => callCount++);
            Assert.AreEqual(0, callCount);

            instance.Class2 = new NotifyPropertyChangedClass2 {
                IntProperty = 1
            };
            Assert.AreEqual(0, callCount);

            observes.Activate();
            Assert.AreEqual(1, callCount);

            instance.Class2.IntProperty = 2;
            Assert.AreEqual(2, callCount);

            observes.Deactivate();
            Assert.AreEqual(2, callCount);

            instance.Class2.IntProperty = 3;
            Assert.AreEqual(2, callCount);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigPresenter"/> class.
 /// </summary>
 /// <param name="config">The config.</param>
 public ConfigPresenter(ConfigProperties config, GameMetaDataModel game)
 {
     _config = config;
     _game = game;
     InitializeCommands();
     _gameObserver = new PropertyObserver<GameMetaDataModel>(_game).RegisterHandler(o => o.GameNumber, o => OnPropertyChanged("GameNumber"));
 }
        public TabBaseViewModel()
        {
            //properties
            LineType = LineTypes.Geodesic;
            LineDistanceType = DistanceTypes.Meters;

            //commands
            SaveAsCommand = new RelayCommand(OnSaveAs);
            ClearGraphicsCommand = new RelayCommand(OnClearGraphics);
            ActivateToolCommand = new RelayCommand(OnActivateTool);
            EnterKeyCommand = new RelayCommand(OnEnterKeyCommand);
            EditPropertiesDialogCommand = new RelayCommand(OnEditPropertiesDialogCommand);

            // Mediator
            Mediator.Register(Constants.NEW_MAP_POINT, OnNewMapPointEvent);
            Mediator.Register(Constants.MOUSE_MOVE_POINT, OnMouseMoveEvent);
            Mediator.Register(Constants.TAB_ITEM_SELECTED, OnTabItemSelected);

            configObserver = new PropertyObserver<DistanceAndDirectionConfig>(DistanceAndDirectionConfig.AddInConfig)
            .RegisterHandler(n => n.DisplayCoordinateType, n =>
            {
                RaisePropertyChanged(() => Point1Formatted);
                RaisePropertyChanged(() => Point2Formatted);
            });

        }
        public GameNoticeViewModel(IDispatcherService dispatcherService, string functionTag) : base(dispatcherService, functionTag)
        {
            SendWelcomeNotice = new RelayCommand(() =>
            {
                SdtdConsole.Instance.SendGlobalMessage(WelcomeNotice);
            });

            SendAlternateNotice = new RelayCommand(() =>
            {
                SdtdConsole.Instance.SendGlobalMessage(AlternateNotice);
            });

            Timer = new Timer()
            {
                AutoReset = true, Interval = AlternateInterval * 1000
            };
            Timer.Elapsed += OnTimer_Elapsed;

            _currentViewModelObserver = new PropertyObserver <GameNoticeViewModel>(this);
            _currentViewModelObserver.RegisterHandler(currentViewModel => currentViewModel.AlternateInterval,
                                                      (vm) =>
            {
                if (AlternateInterval > 0)
                {
                    Timer.Interval = AlternateInterval * 1000;
                }
            });
        }
Example #21
0
        public void RegisterShouldThrowWhenPropertyIsNull()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.RegisterHandler((string)null, src => { });
        }
        public void DisposeTest()
        {
            string actualValue = null;

            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };
            WeakReference wr = new WeakReference(obj);

            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            po.RegisterHandler(o => o.SValue, (oo) => actualValue = oo.SValue);

            obj.SValue = "1";
            Assert.AreEqual("1", actualValue);

            po.Dispose();
            obj.SValue = "2";
            Assert.AreEqual("1", actualValue);

#if !DEBUG
            obj = null;
            GC.Collect(2, GCCollectionMode.Forced);
            Assert.IsFalse(wr.IsAlive);
#endif
        }
        public ProTabBaseViewModel()
        {
            //properties
            LineType         = LineTypes.Geodesic;
            LineDistanceType = DistanceTypes.Meters;

            //commands
            SaveAsCommand        = new ArcGIS.Desktop.Framework.RelayCommand(() => OnSaveAs());
            ClearGraphicsCommand = new ArcGIS.Desktop.Framework.RelayCommand(() => OnClearGraphics());
            //ActivateToolCommand = new RelayCommand(OnActivateTool);
            EnterKeyCommand             = new DistanceAndDirectionLibrary.Helpers.RelayCommand(OnEnterKeyCommand);
            EditPropertiesDialogCommand = new ArcGIS.Desktop.Framework.RelayCommand(() => OnEditPropertiesDialog());

            // Mediator
            Mediator.Register(DistanceAndDirectionLibrary.Constants.NEW_MAP_POINT, OnNewMapPointEvent);
            Mediator.Register(DistanceAndDirectionLibrary.Constants.MOUSE_MOVE_POINT, OnMouseMoveEvent);
            Mediator.Register(DistanceAndDirectionLibrary.Constants.TAB_ITEM_SELECTED, OnTabItemSelected);

            configObserver = new PropertyObserver <DistanceAndDirectionConfig>(DistanceAndDirectionConfig.AddInConfig)
                             .RegisterHandler(n => n.DisplayCoordinateType, n =>
            {
                RaisePropertyChanged(() => Point1Formatted);
                RaisePropertyChanged(() => Point2Formatted);
            });
        }
Example #24
0
        public OutputCoordinateViewModel()
        {
            ConfigCommand = new RelayCommand(OnConfigCommand);
            ExpandCommand = new RelayCommand(OnExpandCommand);
            DeleteCommand = new RelayCommand(OnDeleteCommand);
            CopyCommand   = new RelayCommand(OnCopyCommand);

            Mediator.Register(CoordinateConversionLibrary.Constants.AddNewOutputCoordinate, OnAddNewOutputCoordinate);
            Mediator.Register(CoordinateConversionLibrary.Constants.CopyAllCoordinateOutputs, OnCopyAllCoordinateOutputs);

            //for testing without a config file, init a few sample items
            //OutputCoordinateList = new ObservableCollection<OutputCoordinateModel>();
            ////var tempProps = new Dictionary<string, string>() { { "Lat", "70.49N" }, { "Lon", "40.32W" } };
            ////var mgrsProps = new Dictionary<string, string>() { { "GZone", "17T" }, { "GSquare", "NE" }, { "Northing", "86309" }, { "Easting", "77770" } };
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "DD", CType = CoordinateType.DD, OutputCoordinate = "70.49N 40.32W" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "DMS", CType = CoordinateType.DMS, OutputCoordinate = "40°26'46\"N,79°58'56\"W", Format = "A0°B0'C0\"N X0°Y0'Z0\"E" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "MGRS", CType = CoordinateType.MGRS, OutputCoordinate = @"", Format = "Z S X00000 Y00000" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "UTM", CType = CoordinateType.UTM, OutputCoordinate = @"", Format = "Z#H X0 Y0" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "GARS", CType = CoordinateType.GARS, OutputCoordinate = @"", Format = "X#YQK" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "USNG", CType = CoordinateType.USNG, OutputCoordinate = @"", Format = "Z S X0 Y0" });
            //OutputCoordinateList.Add(new OutputCoordinateModel { Name = "DDM", CType = CoordinateType.DDM, OutputCoordinate = @"", Format = "A0 B0.0### N X0 Y0.0### E" });

            //DefaultFormatList = new ObservableCollection<DefaultFormatModel>();

            //DefaultFormatList.Add(new DefaultFormatModel { CType = CoordinateType.DD, DefaultNameFormatDictionary = new SerializableDictionary<string, string> { { "70.49N 40.32W", "Y0.0#N X0.0#E" }, { "70.49N,40.32W", "Y0.0#N,X0.0#E" } } });

            configObserver = new PropertyObserver <CoordinateConversionLibraryConfig>(CoordinateConversionViewModel.AddInConfig)
                             .RegisterHandler(n => n.OutputCoordinateList, n => RaisePropertyChanged(() => OutputCoordinateList));
        }
        public void PropertyObserver_Getter_Fallback_Observes_instance_StringProperty_AutoActivateTrue()
        {
            var instance = new NotifyPropertyChangedClass1()
            {
                StringProperty = null
            };
            var callCount = 0;

            using var observes = PropertyObserver.Observes(() => instance.StringProperty, true, () => callCount++, "Fallback");
            Assert.AreEqual(0, callCount);
            Assert.AreEqual("Fallback", observes.Value);

            instance.StringProperty = "1";
            Assert.AreEqual(1, callCount);
            Assert.AreEqual("1", observes.Value);

            instance.StringProperty = "2";
            Assert.AreEqual(2, callCount);
            Assert.AreEqual("2", observes.Value);

            observes.Deactivate();
            Assert.AreEqual(2, callCount);
            Assert.AreEqual("2", observes.Value);

            instance.StringProperty = "3";
            Assert.AreEqual(2, callCount);
            Assert.AreEqual("3", observes.Value);

            instance.StringProperty = null;
            Assert.AreEqual(2, callCount);
            Assert.AreEqual("Fallback", observes.Value);
        }
        public FourAxisSeriesViewModel()
        {
            XAxis = BottomAxis;
            YAxis = LeftAxis;
            TopAxis.Visibility = Visibility.Collapsed;
            RightAxis.Visibility = Visibility.Collapsed;
            TopAxis.Label = "Top Axis";
            BottomAxis.Label = "Bottom Axis";
            LeftAxis.Label = "Left Axis";
            RightAxis.Label = "Right Axis";
            XAxis.Autorange = true;
            YAxis.Autorange = true;
            XAxisTicks = XAxis.AxisTicks;
            YAxisTicks = YAxis.AxisTicks;

            _propertyObserver = new PropertyObserver<FourAxisSeriesViewModel>(this)
                .RegisterHandler(d => d.DataSeriesCollection, DataSeriesCollectionPropertyChanged)
                .RegisterHandler(d => d.MouseLocation, () =>
                {
                    TopAxis.MouseDataLocation = IsMouseOver && TopAxis.Visibility == Visibility.Visible && TopAxis.PositionToValue != null ? TopAxis.PositionToValue(MouseLocation.X) : double.NaN;
                    BottomAxis.MouseDataLocation = IsMouseOver && BottomAxis.Visibility == Visibility.Visible && BottomAxis.PositionToValue != null ? BottomAxis.PositionToValue(MouseLocation.X) : double.NaN;
                    LeftAxis.MouseDataLocation = IsMouseOver && LeftAxis.Visibility == Visibility.Visible && LeftAxis.PositionToValue != null ? LeftAxis.PositionToValue(MouseLocation.Y) : double.NaN;
                    RightAxis.MouseDataLocation = IsMouseOver && RightAxis.Visibility == Visibility.Visible && RightAxis.PositionToValue != null ? RightAxis.PositionToValue(MouseLocation.Y) : double.NaN;
                    //Debug.WriteLine("Mouse data locations: Bottom: {0}, Left: {1}, Top: {2}, Right: {3}", BottomAxis.MouseDataLocation, LeftAxis.MouseDataLocation, TopAxis.MouseDataLocation, RightAxis.MouseDataLocation);
                });

            if (DataSeriesCollection != null) DataSeriesCollectionPropertyChanged();
            MajorTickLineColor = Colors.Black;
            MinorTickLineColor = Colors.LightGray;
        }
Example #27
0
        public void RegisterShouldThrowWhenPropertyIsWrong()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.RegisterHandler("Misspelled Property", src => { });
        }
 public ArchiveTweetCommand(Tweet tweet)
 {
     _tweet = tweet;
     _observer = new PropertyObserver<Tweet>(_tweet).
         RegisterHandler(x => x.IsArchived,
                         x => CanExecuteChanged(this, EventArgs.Empty));
 }
Example #29
0
        public void UnregisterShouldThrowWhenExpressionIsWrong()
        {
            DummyClass source = new DummyClass();
            PropertyObserver <DummyClass> observer = new PropertyObserver <DummyClass>(source);

            observer.UnregisterHandler(src => src);
        }
Example #30
0
        public void PropertyObserver_Observes_instance1_StringProperty_AutoActivateTrue()
        {
            var instance1 = new NotifyPropertyChangedClass1();
            var instance2 = new NotifyPropertyChangedClass1();
            var callCount = 0;

            using var observes = PropertyObserver.Observes(
                      instance1,
                      instance2,
                      (i1, i2) => i1.StringProperty,
                      true,
                      () => callCount++);
            Assert.AreEqual(0, callCount);

            instance1.StringProperty = "1";
            Assert.AreEqual(1, callCount);

            instance1.StringProperty = "2";
            Assert.AreEqual(2, callCount);

            observes.Deactivate();
            Assert.AreEqual(2, callCount);

            instance1.StringProperty = "3";
            Assert.AreEqual(2, callCount);
        }
Example #31
0
        /// <summary> Implements property observers when a new viewmodel is applied. </summary>
        /// <param name="sender"> The sender.  </param>
        /// <param name="e"> The event arguments.  </param>
        private void ScoreboardDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var viewmodel = e.NewValue as ScoreboardControlViewModel;

            if (viewmodel == null)
            {
                return;
            }

            this.DataContext = viewmodel;

            // Unregistering handlers aren't necessary thanks to weak references.
            this.playerOneObserver = new PropertyObserver <Player>(viewmodel.Player1).RegisterHandler(
                n => n.Color, this.Player1ColorChanged);
            this.playerTwoObserver = new PropertyObserver <Player>(viewmodel.Player2).RegisterHandler(
                n => n.Color, this.Player2ColorChanged);

            this.Player1ColorChanged(viewmodel.Player1);
            this.Player2ColorChanged(viewmodel.Player2);

            this.previousSubbarIndex = 0;
            viewmodel.SubbarText.CollectionChanged += this.SubbarTextCollectionChanged;

            this.SubbarTextCollectionChanged(viewmodel.SubbarText, null);

            this.previousAnnouncementIndex = 0;
            viewmodel.AnnouncementText.CollectionChanged += this.AnnouncementTextCollectionChanged;

            this.AnnouncementTextCollectionChanged(viewmodel.AnnouncementText, null);
        }
        public void PropertyObserver_ValueGetter_Fallback_Observes_instance1_IntProperty_AutoActivateFalse()
        {
            var instance1 = new NotifyPropertyChangedClass1 {
                Class2 = null
            };
            var instance2 = new NotifyPropertyChangedClass1 {
                Class2 = null
            };
            var callCount = 0;
            var value     = -1;

            using var observes = PropertyObserver.Observes(
                      instance1,
                      instance2,
                      (i1, i2) => i1.Class2.IntProperty,
                      false,
                      v =>
            {
                value = v;
                callCount++;
            },
                      99);

            Assert.AreEqual(0, callCount);
            Assert.AreEqual(-1, value);
            Assert.AreEqual(99, observes.Value);

            instance1.Class2 = new NotifyPropertyChangedClass2 {
                IntProperty = 1
            };
            Assert.AreEqual(0, callCount);
            Assert.AreEqual(-1, value);
            Assert.AreEqual(1, observes.Value);

            observes.Activate();
            Assert.AreEqual(1, callCount);
            Assert.AreEqual(1, value);
            Assert.AreEqual(1, observes.Value);

            instance1.Class2.IntProperty = 2;
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(2, value);
            Assert.AreEqual(2, observes.Value);

            observes.Deactivate();
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(2, value);
            Assert.AreEqual(2, observes.Value);

            instance1.Class2.IntProperty = 3;
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(2, value);
            Assert.AreEqual(3, observes.Value);

            instance1.Class2 = null;
            Assert.AreEqual(2, callCount);
            Assert.AreEqual(2, value);
            Assert.AreEqual(99, observes.Value);
        }
Example #33
0
 public MainViewModel()
 {
     AppSettingVM = new AppSettingsViewModel();
     _observer =
       new PropertyObserver<AppSettingsViewModel>(this.AppSettingVM)
          .RegisterHandler(n => n.AppFolder, n => OnAppFolderChanged());
     LoadCaseFiles();
 }
 public BarSeriesViewModel()
 {
     _propertyObserver = new PropertyObserver<BarSeriesViewModel>(this)
         .RegisterHandler(d => d.StrokeThickness, RenderPropertiesChanged)
         .RegisterHandler(d => d.Stroke, RenderPropertiesChanged)
         .RegisterHandler(d => d.Fill, RenderPropertiesChanged);
     LegendItems.Add(new LegendItemViewModel(this));
 }
 public MarkTweetAsReadCommand(ITweet tweet, ITweetSink tweetSink)
 {
     _tweet = tweet;
     _tweetSink = tweetSink;
     _observer = new PropertyObserver<ITweet>(_tweet).
         RegisterHandler(x => x.IsRead, 
                         x => CanExecuteChanged(this, EventArgs.Empty));
 }
Example #36
0
        public void Start(ITweetSink tweetSink)
        {
            _tweetSink = tweetSink;

            _statusObserver = new PropertyObserver<ITwitterClient>(_client).
                RegisterHandler(x => x.AuthorizationStatus,
                                y => PollIfAuthorized());
            PollIfAuthorized();
        }
Example #37
0
        public AddSalaryViewModel(EditableSalaryViewModel editableSalaryViewModel)
        {
            this.editableSalaryViewModel = editableSalaryViewModel;
            addCommand = new RelayCommand(Add);

            editableSalaryViewModelObserver = new PropertyObserver <EditableSalaryViewModel>(EditableSalaryViewModel);
            editableSalaryViewModelObserver.RegisterHandler(x => x.HasErrors, x => RefreshCommands());
            EditableSalaryViewModel.Validate();
        }
        public PlayerControlsViewModel(TimeManager timeManager)
        {
            this.timeManager = timeManager;

            Observer = new PropertyObserver<TimeManager>(this.timeManager);
            Observer.RegisterHandler(n => n.FactorTemporal, n => base.RaisePropertyChanged("TimeLapse"))
                    .RegisterHandler(n => n.IsPlaying, n => base.RaisePropertyChanged("IsPlaying"))
                    .RegisterHandler(n => n.ActualTime, n => base.RaisePropertyChanged("ActualTime"));
        }
 public RAMGeoEngine()
 {
     PluginSubtype = PluginSubtype.RAMGeo;
     ConfigurationControl = new RAMGeoConfigurationControl { DataContext = this };
     Initialize();
     _propertyObserver = new PropertyObserver<RAMGeoEngine>(this)
         .RegisterHandler(p => p.MinimumOutputRangeResolution, Save)
         .RegisterHandler(p => p.MinimumOutputDepthResolution, Save);
 }
        public void UnregisterHandlerNullTest()
        {
            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };
            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            Assert.ThrowsException <ArgumentNullException>(() => po.UnregisterHandler(null));
        }
        public void NoTargetsTest()
        {
            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };
            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            obj.IValue = 5;
        }
        protected AuthorizationCommand(ITwitterClient client, AuthorizationStatus executableStatus)
        {
            Client = client;
            _executableStatus = executableStatus;

            _observer = new PropertyObserver<ITwitterClient>(Client).
                RegisterHandler(x => x.AuthorizationStatus,
                                y => OnCanExecuteChanged());
        }
        public void UnregisterHandlerNullTest()
        {
            TestObject obj = new TestObject {
                SValue = "Test String", IValue = 10
            };
            PropertyObserver <TestObject> po = new PropertyObserver <TestObject>(obj);

            po.UnregisterHandler(null);
        }
 public ImageSeriesViewModel()
 {
     _propertyObserver = new PropertyObserver<ImageSeriesViewModel>(this)
         .RegisterHandler(d => d.ImageSource, RenderShapes)
         .RegisterHandler(d => d.Top, RenderShapes)
         .RegisterHandler(d => d.Left, RenderShapes)
         .RegisterHandler(d => d.Bottom, RenderShapes)
         .RegisterHandler(d => d.Right, RenderShapes);
 }
 private void OnDataContextChanged()
 {
     if (viewModelObserver != null) viewModelObserver.Dispose();
     if (ViewModel == null) return;
     viewModelObserver = new PropertyObserver<PagerViewModel>(ViewModel)
                     .RegisterHandler(m => m.TotalPageButtons, InsertPages)
                     .RegisterHandler(m => m.TotalPages, InsertPages)
                     .RegisterHandler(m => m.CurrentPage, InsertPages);
 }
 protected SeriesViewModelBase()
 {
     _propertyObserver = new PropertyObserver<SeriesViewModelBase>(this)
         .RegisterHandler(d => d.SeriesData, SeriesDataChanged)
         .RegisterHandler(d => d.ItemToPoint, ProcessSeriesData)
         .RegisterHandler(d => d.XAxis, XAxisChanged)
         .RegisterHandler(d => d.YAxis, YAxisChanged);
     _pointsObserver = new CollectionObserver(Points).RegisterHandler(PointsCollectionChanged);
 }
Example #47
0
 private void LoadPackageCombo()
 {
     using (var releaseService = new Service.Release.Front.ReleaseService(_Group.GetEnvironment().GetSQLExtendConnectionString()))
     {
         cboPackage.DisplayMember = PropertyObserver.GetPropertyName <EquinoxeExtend.Shared.Object.Release.Package>(x => x.PackageIdStatusString);
         cboPackage.ValueMember   = PropertyObserver.GetPropertyName <EquinoxeExtend.Shared.Object.Release.Package>(x => x.PackageId);
         cboPackage.DataSource    = releaseService.GetAllowedPackagesForMainTask(_MainTask);
     }
 }
        public ModuleLoader(TestHarnessModel testHarness)
        {
            // Store values.
            this.testHarness = testHarness;

            // Wire up events.
            testHarness.Settings.Cleared += delegate { AddModules(); };
            settingsoObserver = new PropertyObserver<TestHarnessSettings>(testHarness.Settings)
                .RegisterHandler(m => m.RecentSelections, () => LoadRecentSelectionsModule(RecentSelectionsModule));
        }
        public LegendItemViewModel(SeriesViewModelBase dataSeries)
        {
            DataSeries = dataSeries;
            _propertyObserver = new PropertyObserver<SeriesViewModelBase>(dataSeries)
                .RegisterHandler(s => s.SampleImageSource, series => { SampleImageSource = series.SampleImageSource; })
                .RegisterHandler(s => s.SeriesName, series => { SeriesName = series.SeriesName; });

            SampleImageSource = dataSeries.SampleImageSource;
            SeriesName = dataSeries.SeriesName;
        }
Example #50
0
        public TweetRating(IAuthorizer client, ITweet tweet)
        {
            _client = client;
            _tweet = tweet;

            _observer = new PropertyObserver<IAuthorizer>(_client).
                RegisterHandler(x => x.AuthenticatedUser,
                                x => UpdateIsMention());
            UpdateIsMention();
        }
Example #51
0
        public void RegisteredHandlersAreInvoked()
        {
            ObservableThing thing = new ObservableThing();
            PropertyObserver<ObservableThing> target = new PropertyObserver<ObservableThing>(thing);
            bool wasInvoked = false;
            target.RegisterHandler(t => t.SomeProperty, t => wasInvoked = (t == thing));

            thing.SomeProperty = "whatever";

            Assert.IsTrue(wasInvoked);
        }
        public NumberChangeLogViewModel()
        {
            this.Number = new NumberViewModel();
            this.ChangeLog = new ObservableCollection<string>();

            _observer =
                new PropertyObserver<NumberViewModel>(this.Number)
                   .RegisterHandler(n => n.Value, n => Log("Value: " + n.Value))
                   .RegisterHandler(n => n.IsNegative, this.AppendIsNegative)
                   .RegisterHandler(n => n.IsEven, this.AppendIsEven);
        }
        public ViewTestButtonViewModel(ViewTest model)
        {
            // Setup initial conditions.
            this.model = model;
            Click = new DelegateCommand<Button>(button => OnClick());
            ParametersViewModel = new ViewTestParametersViewModel(model);

            // Wire up events.
            modelObserver = new PropertyObserver<ViewTest>(model)
                .RegisterHandler(m => m.ExecuteCount, m => OnPropertyChanged<T>(o => o.ExecuteCount));
        }
 public BellhopEngine() 
 {
     PluginSubtype = PluginSubtype.Bellhop;
     ConfigurationControl = new BellhopConfigurationControl { DataContext = this };
     Initialize();
     _propertyObserver = new PropertyObserver<BellhopEngine>(this)
         .RegisterHandler(p => p.RangeCellSize, Save)
         .RegisterHandler(p => p.DepthCellSize, Save)
         .RegisterHandler(p => p.UseSurfaceReflection, Save)
         .RegisterHandler(p => p.RayCount, Save);
 }
        public ApplicationOptionsViewModel(IPluginManagerService pluginManagerService)
        {
            PluginManagerService = pluginManagerService;
            Globals.AppSettings = AppSettings.Load();
            AppSettings = Globals.AppSettings;

            AvailableTransmissionLossEngines.AddRange(from key in PluginManagerService[PluginType.TransmissionLossCalculator].Keys
                                                      select (PluginBase)PluginManagerService[PluginType.TransmissionLossCalculator][key].DefaultPlugin);
            SelectedTransmissionLossEngine = AvailableTransmissionLossEngines.FirstOrDefault(engine => engine.PluginIdentifier == AppSettings.SelectedTransmissionLossEngine);
            _propertyObserver = new PropertyObserver<ApplicationOptionsViewModel>(this)
                .RegisterHandler(p => p.SelectedTransmissionLossEngine, () => { Globals.AppSettings.SelectedTransmissionLossEngine = SelectedTransmissionLossEngine.PluginIdentifier; });
        }
        public ClassNodeViewModel(ViewTestClass model)
        {
            // Setup initial conditions.
            Model = model;

            // Wire up events.
            modelObserver = new PropertyObserver<ViewTestClass>(model)
                    .RegisterHandler(m => m.DisplayName, m => OnPropertyChanged<T>(o => o.DisplayName))
                    .RegisterHandler(m => m.IsCurrent, m => FireCurrentChanged());
            harnessObserver = new PropertyObserver<TestHarnessModel>(TestHarnessModel.Instance)
                    .RegisterHandler(m => m.CurrentClass, m => FireCurrentChanged());
        }
        /// <summary>Constructor.</summary>
        public DialogContent()
        {
            // Setup initial conditions.
            Content = new ViewTemplate { ViewModel = this };

            // Wire up events.
            propertyObserver = new PropertyObserver<DialogContent>(this)
                .RegisterHandler(m => m.Width, m => SyncSizeOnParent())
                .RegisterHandler(m => m.Height, m => SyncSizeOnParent());

            contentPropertyObserver = new PropertyObserver<IViewTemplate>(Content)
                .RegisterHandler(m => m.Template, m => SyncTemplateOnParent());
        }
Example #58
0
        public DirectoryViewModel()
        {
            ExecuteItemCommand = new DelegateCommand(ExecuteExecuteItem, CanExecuteExecuteItem);
            History = new History<IDirectoryViewItem>();
            FileSystem = new WindowsFileSystem();

            propObserver = new PropertyObserver<DirectoryViewModel>(this);
            propObserver.RegisterHandler(x => x.SearchText, ManageSearch);

            fileSystemWatcher = new FileSystemWatcher { IncludeSubdirectories = false, };
            fileSystemWatcher.Created += fileSystemWatcher_Changed;
            fileSystemWatcher.Renamed += fileSystemWatcher_Changed;
            fileSystemWatcher.Deleted += fileSystemWatcher_Changed;
        }
 void XAxisChanged()
 {
     if (_xAxisObserver != null) _xAxisObserver.UnregisterHandler(x => x.ValueToPosition);
     if (XAxis == null)
     {
         _xAxisObserver = null;
         if (_oldXAxis != null) _oldXAxis.DataRange.Remove(XRange);
         return;
     }
     _xAxisObserver = new PropertyObserver<DataAxisViewModel>(XAxis)
         .RegisterHandler(x => x.ValueToPosition, XAxisValueToPositionChanged);
     XAxis.DataRange.Add(XRange);
     _oldXAxis = XAxis;
 }
 private void OnDataContextChanged()
 {
     if (dropShadowObserver != null) dropShadowObserver.Dispose();
     if (ViewModel != null)
     {
         dropShadowObserver = new PropertyObserver<IDropShadowEffect>(ViewModel.DropShadow)
                         .RegisterHandler(m => m.Opacity, UpdateShadow)
                         .RegisterHandler(m => m.Color, UpdateShadow)
                         .RegisterHandler(m => m.Direction, UpdateShadow)
                         .RegisterHandler(m => m.BlurRadius, UpdateShadow)
                         .RegisterHandler(m => m.ShadowDepth, UpdateShadow);
     }
     UpdateShadow();
 }