public void FilteredHandlerLifeCycleTest()
        {
            var handler1Called = false;
            var handler2Called = false;
            var handler3Called = false;

            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher);

            listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handler1Called = true; });
            listener.RegisterHandler("Dummy2", (sender, e) => { e.PropertyName.Is("Dummy2"); handler2Called = true; });
            listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handler3Called = true; });

            publisher.RaisePropertyChanged("Dummy1");
            publisher.RaisePropertyChanged("Dummy2");

            handler1Called.Is(true);
            handler2Called.Is(true);
            handler3Called.Is(true);

            //------------------
            handler1Called = false;
            handler2Called = false;
            handler3Called = false;

            listener.Dispose();
            publisher.RaisePropertyChanged("Dummy1");
            publisher.RaisePropertyChanged("Dummy2");

            handler1Called.Is(false);
            handler2Called.Is(false);
            handler3Called.Is(false);
        }
            public HandlerMemoryLeakTestClass(INotifyPropertyChanged publisher)
            {
                Listener = new PropertyChangedEventListener(publisher);

                // This handler refers "this".
                PropertyChangedEventHandler handler = (sender, e) => { ToString(); };

                Listener.RegisterHandler(handler);
                Listener.RegisterHandler("Dummy1", handler);
            }
        public InformationViewModel()
        {
            /*listener.RegisterHandler(
             * () => model.Value, (s, e) =>
             *      // Value プロパティが変更した時にだけ実行する処理
             * });*/

            listener = new PropertyChangedEventListener(Kancolle);

            listener.RegisterHandler(() => Kancolle.IsRegistered, (s, e) => Register());
            listener.RegisterHandler(() => Kancolle.Fleets, (s, e) => UpdateFleets());
            listener.RegisterHandler(() => Kancolle.Ships, (s, e) => UpdateShips());

            this.CompositeDisposable.Add(listener);
        }
        public MainWindowViewModel()
        {
            #region Timerモデル生成および聞き耳設定
            _timerModel = new TimerModel();
            var timerListener = new PropertyChangedEventListener(_timerModel);

            timerListener.RegisterHandler("NowTimerStatus", (sender, e) =>
            {
                if (_timerModel.NowTimerStatus == TimerModel.TimerStatus.CountDown)
                {
                    StartPauseButtonContent = "PAUSE";
                    TimerValueListIsEnable = false;
                }
                else
                {
                    StartPauseButtonContent = "START";
                    TimerValueListIsEnable = true;
                }
            });

            timerListener.RegisterHandler("TimerRemainValue", (sender, e) =>
            {
                RemainTime = _timerModel.TimerRemainValue.ToString(@"hh\:mm\:ss\:fff");
            });
            this.CompositeDisposable.Add(timerListener);
            #endregion

            #region Timer値リストモデル生成および聞き耳設定
            _timerValueListModel = TimerListFactory.Create();
            var timerValueListListener = new PropertyChangedEventListener(_timerValueListModel);

            timerValueListListener.RegisterHandler("TimerValueListModel", (sender, e) =>
            {
                TimerValueList = _timerValueListModel.getEditTimerValueList();

                // コンボボックス表示用文字列再構築
                TimerValueStrList.Clear();
                foreach(TimeSpan ts in TimerValueList)
                {
                    TimerValueStrList.Add(MyUtil.TimeSpanTo24hStr(ts));
                }
                RaisePropertyChanged("TimerValueStrList");
            });

            this.CompositeDisposable.Add(timerValueListListener);

            #endregion
        }
Exemple #5
0
        /* コマンド、プロパティの定義にはそれぞれ
         *
         *  lvcom   : ViewModelCommand
         *  lvcomn  : ViewModelCommand(CanExecute無)
         *  llcom   : ListenerCommand(パラメータ有のコマンド)
         *  llcomn  : ListenerCommand(パラメータ有のコマンド・CanExecute無)
         *  lprop   : 変更通知プロパティ(.NET4.5ではlpropn)
         *
         * を使用してください。
         *
         * Modelが十分にリッチであるならコマンドにこだわる必要はありません。
         * View側のコードビハインドを使用しないMVVMパターンの実装を行う場合でも、ViewModelにメソッドを定義し、
         * LivetCallMethodActionなどから直接メソッドを呼び出してください。
         *
         * ViewModelのコマンドを呼び出せるLivetのすべてのビヘイビア・トリガー・アクションは
         * 同様に直接ViewModelのメソッドを呼び出し可能です。
         */

        /* ViewModelからViewを操作したい場合は、View側のコードビハインド無で処理を行いたい場合は
         * Messengerプロパティからメッセージ(各種InteractionMessage)を発信する事を検討してください。
         */

        /* Modelからの変更通知などの各種イベントを受け取る場合は、PropertyChangedEventListenerや
         * CollectionChangedEventListenerを使うと便利です。各種ListenerはViewModelに定義されている
         * CompositeDisposableプロパティ(LivetCompositeDisposable型)に格納しておく事でイベント解放を容易に行えます。
         *
         * ReactiveExtensionsなどを併用する場合は、ReactiveExtensionsのCompositeDisposableを
         * ViewModelのCompositeDisposableプロパティに格納しておくのを推奨します。
         *
         * LivetのWindowテンプレートではViewのウィンドウが閉じる際にDataContextDisposeActionが動作するようになっており、
         * ViewModelのDisposeが呼ばれCompositeDisposableプロパティに格納されたすべてのIDisposable型のインスタンスが解放されます。
         *
         * ViewModelを使いまわしたい時などは、ViewからDataContextDisposeActionを取り除くか、発動のタイミングをずらす事で対応可能です。
         */

        /* UIDispatcherを操作する場合は、DispatcherHelperのメソッドを操作してください。
         * UIDispatcher自体はApp.xaml.csでインスタンスを確保してあります。
         *
         * LivetのViewModelではプロパティ変更通知(RaisePropertyChanged)やDispatcherCollectionを使ったコレクション変更通知は
         * 自動的にUIDispatcher上での通知に変換されます。変更通知に際してUIDispatcherを操作する必要はありません。
         */

        public void Initialize()
        {
            var listener = new PropertyChangedEventListener(drawer);

            listener.RegisterHandler(() => drawer.Method, (s, ev) => RaisePropertyChanged(() => Method));
            CompositeDisposable.Add(listener);
        }
Exemple #6
0
        public Stream()
        {
            _ps = new PlayStream();

            _listener = new PropertyChangedEventListener(_ps);
            _listener.RegisterHandler(UpdateHandlerProxy);
        }
Exemple #7
0
        public Model()
        {
            _s = new Stream();

            _listener = new PropertyChangedEventListener(_s);
            _listener.RegisterHandler(UpdateHandlerProxy);
        }
        public void BasicConstructorLifeCycleTest()
        {
            var listenerSuccess = false;

            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher, (sender, e) => listenerSuccess = true);

            //------------------
            listenerSuccess.Is(false);

            publisher.RaisePropertyChanged(string.Empty);

            listenerSuccess.Is(true);

            //------------------
            listenerSuccess = false;

            listener.Dispose();
            publisher.RaisePropertyChanged(string.Empty);

            listenerSuccess.Is(false);

            try
            {
                listener.RegisterHandler((sender, e) => listenerSuccess = true);
            }
            catch (Exception e)
            {
                e.GetType().Is(typeof(ObjectDisposedException));
            }
        }
        public void SourceReferenceMemoryLeakTest()
        {
            var handler1Called = false;

            var publisherStrongReference = new TestEventPublisher();
            var publisherWeakReference   = new WeakReference <TestEventPublisher>(publisherStrongReference);

            var listener = new PropertyChangedEventListener(publisherStrongReference);

            listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handler1Called = true; });

            publisherStrongReference.RaisePropertyChanged("Dummy1");

            handler1Called.Is(true);

            listener.Dispose();
            publisherStrongReference = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            TestEventPublisher resultPublisher = null;

            publisherWeakReference.TryGetTarget(out resultPublisher).Is(false);
            resultPublisher.IsNull();
        }
        public void BasicConstructorLifeCycleTest()
        {
            var listenerSuccess = false;

            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher, (sender, e) => listenerSuccess = true);

            //------------------
            listenerSuccess.Is(false);

            publisher.RaisePropertyChanged(string.Empty);

            listenerSuccess.Is(true);

            //------------------
            listenerSuccess = false;

            listener.Dispose();
            publisher.RaisePropertyChanged(string.Empty);

            listenerSuccess.Is(false);

            try
            {
                listener.RegisterHandler((sender, e) => listenerSuccess = true);
            }
            catch (Exception e)
            {
                e.GetType().Is(typeof(ObjectDisposedException));
            }

        }
Exemple #11
0
        public MainViewModel()
        {
            // 画面デザイン時は処理しない(これにより画面デザインがプレビュー反映されなくなったが、保留)
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                return;
            }

            SolutionExplorerVM = new SolutionExplorerViewModel();
            Anchorables        = new ObservableCollection <AnchorablePaneViewModel>();
            Anchorables.Add(SolutionExplorerVM);

            Documents = new ObservableCollection <DocumentPaneViewModel>();

            // ソリューションエクスプローラーペインからの、プロパティ変更通知を受け取る
            // (ソリューションエクスプローラーツリー内のソースノードを、クリックした際のイベント処理を引き継ぐ)
            var listener = new PropertyChangedEventListener(SolutionExplorerVM);

            listener.RegisterHandler(SolutionExplorerVM_PropertyChanged);
            CompositeDisposable.Add(listener);

            // MainView 側、ComboBox の初期選択項目と同じ値にする
            FontSize    = 18;
            Util.MainVM = this;
        }
        public void MultipleHandlerLifeCycleTest()
        {
            var handler1Success = false;
            var handler2Success = false;

            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher);

            //------------------
            handler1Success.Is(false);
            handler2Success.Is(false);

            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(false);
            handler2Success.Is(false);

            //------------------
            listener.RegisterHandler((sender, e) => handler1Success = true);

            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(true);
            handler2Success.Is(false);

            //------------------
            handler1Success = false;
            handler2Success = false;

            listener.RegisterHandler((sender, e) => handler2Success = true);

            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(true);
            handler2Success.Is(true);

            //------------------
            handler1Success = false;
            handler2Success = false;

            listener.Dispose();
            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(false);
            handler2Success.Is(false);
        }
        public void MultipleHandlerLifeCycleTest()
        {
            var handler1Success = false;
            var handler2Success = false;

            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher);

            //------------------
            handler1Success.Is(false);
            handler2Success.Is(false);

            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(false);
            handler2Success.Is(false);

            //------------------
            listener.RegisterHandler((sender, e) => handler1Success = true);

            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(true);
            handler2Success.Is(false);

            //------------------
            handler1Success = false;
            handler2Success = false;

            listener.RegisterHandler((sender, e) => handler2Success = true);

            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(true);
            handler2Success.Is(true);

            //------------------
            handler1Success = false;
            handler2Success = false;

            listener.Dispose();
            publisher.RaisePropertyChanged(string.Empty);

            handler1Success.Is(false);
            handler2Success.Is(false);
        }
Exemple #14
0
        public MainWindowViewModel()
        {
            mModel = new Model();
            var listener = new PropertyChangedEventListener(mModel);

            listener.RegisterHandler(nameof(Model.BindText), (s, e) => { RaisePropertyChanged(nameof(BindText)); });
            CompositeDisposable.Add(listener);
        }
Exemple #15
0
        public void Initialize()
        {
            _model = new Model();

            var modelListener = new PropertyChangedEventListener(_model);

            modelListener.RegisterHandler(ModelUpdateHandler);
            CompositeDisposable.Add(modelListener);

            _model.StartWatching();
        }
Exemple #16
0
        public MainWindowViewModel(MainWindowState state)
        {
            _state = state;

            var stateListener = new PropertyChangedEventListener(_state);

            stateListener.RegisterHandler(nameof(_state.Mode), (_, __) => RaisePropertyChanged(nameof(Mode)));
            CompositeDisposable.Add(stateListener);

            UserScreenCommand    = new ViewModelCommand(() => _state.Mode = MainWindowMode.User);
            ProductScreenCommand = new ViewModelCommand(() => _state.Mode = MainWindowMode.Product);
        }
Exemple #17
0
        static InputModel()
        {
            _disposables = new CompositeDisposable();
            _core = new InputCoreModel();
            _accounts = new AccountSelectorModel(_core);

            // link property changing
            var icmpc = new PropertyChangedEventListener(_core);
            icmpc.RegisterHandler(() => _core.CurrentInputData,
                                (o, e) => _accounts.CurrentInputDataChanged());
            _disposables.Add(icmpc);
            SetEventPropagation();
        }
        public async void Initialize()
        {
            _LogList = new List <string>();

            _loxiv = new LoXIV();

            var loxivListener = new PropertyChangedEventListener(_loxiv);

            loxivListener.RegisterHandler(LoXIVUpdateHandler);
            CompositeDisposable.Add(loxivListener);

            await Task.Run(() => _loxiv.StartReadLogLoop());
        }
Exemple #19
0
        public Model()
        {
            checkFfxiv = new CheckFFXIV();
            _se        = new SE.SE();

            var listener = new PropertyChangedEventListener(checkFfxiv);

            listener.RegisterHandler(UpdateHandlerProxy);

            _timer          = new Timer();
            _timer.Elapsed += (sender, args) => checkFfxiv.Check();
            _timer.Interval = Config.Wait;
        }
Exemple #20
0
        static InputModel()
        {
            _disposables = new CompositeDisposable();
            _core        = new InputCoreModel();
            _accounts    = new AccountSelectorModel(_core);

            // link property changing
            var icmpc = new PropertyChangedEventListener(_core);

            icmpc.RegisterHandler(() => _core.CurrentInputData,
                                  (o, e) => _accounts.CurrentInputDataChanged());
            _disposables.Add(icmpc);
            SetEventPropagation();
        }
        public void MultiThreadHandlerTest()
        {
            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher);

            var handlerCalledCount = 0;

            var parentTask = new Task(() =>
            {
                var tf = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent);

                for (int i = 0; i < 50; i++)
                {
                    tf.StartNew(() =>
                    {
                        for (int f = 0; f < 500; f++)
                        {
                            listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handlerCalledCount++; });
                        }
                    });
                }
            });

            parentTask.Start();
            parentTask.Wait();

            handlerCalledCount.Is(0);

            publisher.RaisePropertyChanged("Dummy1");

            handlerCalledCount.Is(25000);

            handlerCalledCount = 0;

            listener.Dispose();
            publisher.RaisePropertyChanged("Dummy1");

            handlerCalledCount.Is(0);
        }
        public async void Initialize()
        {
            if (Settings.Initialize() == false)
            {
                var cw = new ConfigWindow();
                cw.Topmost = true;
                cw.ShowDialog();

                APIhelper.BuildBaseUrl();
            }

            _model = new Model();
            _sw    = new Stopwatch();

            var modelListener = new PropertyChangedEventListener(_model);

            modelListener.RegisterHandler(ModelUpdateHandler);
            CompositeDisposable.Add(modelListener);

            _timer = new Timer {
                Interval = 100
            };
            _timer.Elapsed += (sender, e) => Timer_Tick();
            _timer.Start();

            PlayState = State.Stopped;

            Volume       = Settings.Volume;
            VolumeString = Convert.ToInt32(Volume * 100) + " %";

            CurrentRepeatState = (RepeatState)Settings.RepeatState;

            LibraryListHeaderImage  = null;
            LibraryListHeaderTitle  = null;
            LibraryListHeaderArtist = null;

            await Task.Run(() => _model.GetIndex());
        }
Exemple #23
0
        public void Initialize()
        {
            var ui = new UpdateInfomation();

            uip = ui.GetUpdateInfomation();

            Name       = uip.AppricationName;
            Infomation = uip.Infomation;

            var listener = new PropertyChangedEventListener(m);

            listener.RegisterHandler((sender, e) => UpdateHandler(sender, e));
            this.CompositeDisposable.Add(listener);

            if (uip.CanAutoUpdate == true)
            {
                Update();
            }
            else
            {
                CantUpdate();
            }
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainViewModel()
        {
            //設定ファイルの読み込み
            Settings = new Settings();

            //セレクターのサイズの初期化
            MouseSelectorPosition.GridSize = Settings.PalletCellSize;
            FontSize = 9;
            StageModel.Dir = new DirectoryInfo(Settings.StageDataDirectory);

            _model = new MainModel(Settings);

            MapChipPalletViewModel = new MapChipPalletViewModel(Settings);
            ObjectChipPalletViewModel = new ObjectChipPalletViewModel(Settings);

            MapChipPalletViewModel.PalletEnterEvent += chip => _model.CurrentPositionMapChip = chip.ID == 0 ? null : chip;
            ObjectChipPalletViewModel.PalletEnterEvent += chip => _model.CurrentPositionObjectChip = chip.ID == 0 ? null : chip;

            PalletViewModelManager = new PalletViewModelManager(MapChipPalletViewModel, ObjectChipPalletViewModel);

            StageViewModels = ViewModelHelper.CreateReadOnlyDispatcherCollection(
                _model.StageModels,
                m =>
                {
                    var vm = new StageViewModel(m, this);
                    vm.PropertyChanged += (sender, args) => RaiseModelPropertyChanged(args.PropertyName);
                    return vm;
                },
                DispatcherHelper.UIDispatcher);

            //TreeViewの要素リストを監視
            MapViewModels = ViewModelHelper.CreateReadOnlyDispatcherCollection(
                _model.MapModels,
                model =>
                {
                    var vm = new MapViewModel(model);
                    vm.PropertyChanged += (sender, args) => RaiseModelPropertyChanged(args.PropertyName);
                    return vm;
                },
                DispatcherHelper.UIDispatcher);

            //MainModelのプロパティ変更を監視
            Listener = new PropertyChangedEventListener(_model);
            Listener.RegisterHandler((sender, args) => RaisePropertyChanged(args.PropertyName));
            Listener.RegisterHandler("CurrentMap", (sender, args) => CurrentMapChenged());
            Listener.RegisterHandler("Scale", (sender, args) =>
            {
                RaisePropertyChanged("MapWidth");
                RaisePropertyChanged("MapHeight");
            });
            Listener.RegisterHandler("CurrentPosition", (sender, args) => _model.UpdateMousePositionProperty());
            CompositeDisposable.Add(Listener);

            ChangeMapInitialize();
        }
            public HandlerMemoryLeakTestClass(INotifyPropertyChanged publisher)
            {
                Listener = new PropertyChangedEventListener(publisher);

                // This handler refers "this".
                PropertyChangedEventHandler handler = (sender, e) => { ToString(); };
                Listener.RegisterHandler(handler);
                Listener.RegisterHandler("Dummy1", handler);
            }
        public void SourceReferenceMemoryLeakTest()
        {
            var handler1Called = false;

            var publisherStrongReference = new TestEventPublisher();
            var publisherWeakReference = new WeakReference<TestEventPublisher>(publisherStrongReference);

            var listener = new PropertyChangedEventListener(publisherStrongReference);
            listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handler1Called = true; });

            publisherStrongReference.RaisePropertyChanged("Dummy1");

            handler1Called.Is(true);

            listener.Dispose();
            publisherStrongReference = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            TestEventPublisher resultPublisher = null;
            publisherWeakReference.TryGetTarget(out resultPublisher).Is(false);
            resultPublisher.IsNull();
        }
        public void MultiThreadHandlerTest()
        {
            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher);

            var handlerCalledCount = 0;

            var parentTask = new Task(() =>
            {
                var tf = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent);

                for (int i = 0; i < 50; i++)
                {
                    tf.StartNew(() =>
                            {
                                for (int f = 0; f < 500; f++)
                                {
                                    listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handlerCalledCount++; });
                                }

                            });
                }
            });

            parentTask.Start();
            parentTask.Wait();

            handlerCalledCount.Is(0);

            publisher.RaisePropertyChanged("Dummy1");

            handlerCalledCount.Is(25000);

            handlerCalledCount = 0;

            listener.Dispose();
            publisher.RaisePropertyChanged("Dummy1");

            handlerCalledCount.Is(0);
        }
        public void FilteredHandlerLifeCycleTest()
        {
            var handler1Called = false;
            var handler2Called = false;
            var handler3Called = false;

            var publisher = new TestEventPublisher();

            var listener = new PropertyChangedEventListener(publisher);

            listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handler1Called = true; });
            listener.RegisterHandler("Dummy2", (sender, e) => { e.PropertyName.Is("Dummy2"); handler2Called = true; });
            listener.RegisterHandler("Dummy1", (sender, e) => { e.PropertyName.Is("Dummy1"); handler3Called = true; });

            publisher.RaisePropertyChanged("Dummy1");
            publisher.RaisePropertyChanged("Dummy2");

            handler1Called.Is(true);
            handler2Called.Is(true);
            handler3Called.Is(true);

            //------------------
            handler1Called = false;
            handler2Called = false;
            handler3Called = false;

            listener.Dispose();
            publisher.RaisePropertyChanged("Dummy1");
            publisher.RaisePropertyChanged("Dummy2");

            handler1Called.Is(false);
            handler2Called.Is(false);
            handler3Called.Is(false);
        }