Exemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if(this.m_Disposed) return;
            if(disposing) {
                this.m_CurrentDeckTraversalChangedDispatcher.Dispose();

                // Note: this duplicates code in the CurrentDeckTraversal setter.
                if(this.m_CurrentDeckTraversal != null) {
                    Debug.Assert(this.m_Adapter != null);
                    this.m_Adapter.Dispose();
                    this.m_Adapter = null;
                    using (Synchronizer.Lock(this.CurrentDeckTraversal.SyncRoot)) {
                        using (Synchronizer.Lock(this.CurrentDeckTraversal.Deck.SyncRoot)) {
                            this.CurrentDeckTraversal.Deck.Changed["DeckBackgroundColor"].Remove(new PropertyEventHandler(this.HandleBackgroundColorChanged));
                            this.CurrentDeckTraversal.Deck.Changed["DeckBackgroundTemplate"].Remove(new PropertyEventHandler(this.HandleBackgroundTemplateChanged));
                        }
                    }
                }
            }
            this.m_Disposed = true;
        }
Exemplo n.º 2
0
        public WorkspaceModelAdapter(EventQueue dispatcher, DeckTraversalModelAdapter.IAdaptee viewer, PresenterModel model)
        {
            this.m_EventQueue = dispatcher;
            this.m_Model = model;
            this.m_Viewer = viewer;
            this.m_DeckBGColorChangedDispatcher = new EventQueue.PropertyEventDispatcher( dispatcher, new PropertyEventHandler( this.HandleBackgroundColorChanged ) );
            this.m_DeckBGTemplateChangedDispatcher = new EventQueue.PropertyEventDispatcher(dispatcher, new PropertyEventHandler(this.HandleBackgroundTemplateChanged));

            this.m_CurrentDeckTraversalChangedDispatcher =
                this.m_Model.Workspace.CurrentDeckTraversal.ListenAndInitialize(dispatcher,
                delegate(Property<DeckTraversalModel>.EventArgs args) {
                    if (this.CurrentDeckTraversal != null)
                        using (Synchronizer.Lock(this.CurrentDeckTraversal.SyncRoot))
                        using (Synchronizer.Lock(this.CurrentDeckTraversal.Deck.SyncRoot)){
                            this.CurrentDeckTraversal.Deck.Changed["DeckBackgroundColor"].Remove( this.m_DeckBGColorChangedDispatcher.Dispatcher );
                            this.CurrentDeckTraversal.Deck.Changed["DeckBackgroundTemplate"].Remove(this.m_DeckBGTemplateChangedDispatcher.Dispatcher);
                        }

                    this.CurrentDeckTraversal = args.New;

                    if (this.CurrentDeckTraversal != null) {
                        using (Synchronizer.Lock(this.CurrentDeckTraversal.SyncRoot))
                        using (Synchronizer.Lock(this.CurrentDeckTraversal.Deck.SyncRoot)) {
                            this.CurrentDeckTraversal.Deck.Changed["DeckBackgroundColor"].Add(this.m_DeckBGColorChangedDispatcher.Dispatcher);
                            this.CurrentDeckTraversal.Deck.Changed["DeckBackgroundTemplate"].Add(this.m_DeckBGTemplateChangedDispatcher.Dispatcher);
                        }
                        this.HandleBackgroundColorChanged(this, null);
                        this.HandleBackgroundTemplateChanged(this, null);
                    }
                });
        }