Esempio n. 1
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="isDisposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        public virtual void Dispose(bool isDisposing)
        {
            if (!IsDisposed)
            {
                foreach (var subControllerItem in GetSubControllers())
                {
                    if (null != subControllerItem.Controller)
                    {
                        subControllerItem.Controller.Dispose();
                    }
                    if (null != subControllerItem.SetMemberToNullAction)
                    {
                        subControllerItem.SetMemberToNullAction();
                    }
                }

                ViewObject = null;

                if (null != _suspendToken)
                {
                    _suspendToken.Dispose();
                    _suspendToken = null;
                }

                if ((_clonedCopyOfDoc is IDisposable) && !object.ReferenceEquals(_doc, _clonedCopyOfDoc))
                {
                    ((IDisposable)_clonedCopyOfDoc).Dispose();
                    _clonedCopyOfDoc = default(TModel);
                }

                _isDisposed = true;
            }
        }
        /// <summary>
        /// Should be called by a derived controller class when the instance of the model has changed.
        /// </summary>
        /// <param name="oldInstance">The old instance.</param>
        /// <param name="newInstance">The new instance.</param>
        protected void OnDocumentInstanceChanged(TModel oldInstance, TModel newInstance)
        {
            Altaxo.Main.ISuspendToken newSuspendToken = null;

            if (null != _suspendToken)
            {
                if (newInstance is Altaxo.Main.ISuspendableByToken)
                {
                    newSuspendToken = ((Altaxo.Main.ISuspendableByToken)newInstance).SuspendGetToken();
                }
            }

            // Set the instance
            if (null != _setInstanceInParentNode)
            {
                _setInstanceInParentNode(newInstance);
            }

            // Release old suspend token and store instead the new suspend token
            if (null != _suspendToken)
            {
                _suspendToken.Dispose();
            }

            _suspendToken = newSuspendToken;
        }
Esempio n. 3
0
        /// <summary>
        /// Basic initialization of the document.
        /// Here, it is tried to suspend the event handling of the documnt by calling <see cref="GetSuspendTokenForControllerDocument"/> (but only if <see cref="_useDocumentCopy"/> is <c>true</c>).
        /// </summary>
        /// <param name="initData">If set to <c>true</c>, it indicates that the controller should initialize its model classes..</param>
        /// <exception cref="System.InvalidOperationException">This controller was not initialized with a document.</exception>
        /// <exception cref="System.ObjectDisposedException">The controller was already disposed.</exception>
        protected virtual void Initialize(bool initData)
        {
            if (null == _doc)
            {
                throw new InvalidOperationException("This controller was not initialized with a document.");
            }
            if (IsDisposed)
            {
                throw new ObjectDisposedException("The controller was already disposed. Type: " + GetType().FullName);
            }

            if (initData)
            {
                if (_useDocumentCopy && null == _suspendToken)
                {
                    _suspendToken = GetSuspendTokenForControllerDocument();
                }
            }
        }