Example #1
0
        public COMObject(Core factory, COMObject replacedObject)
        {
            // copy current factory info or set default
            if (null == factory)
            {
                factory = Core.Default;
            }
            Factory = factory;

            // copy proxy
            _underlyingObject = replacedObject.UnderlyingObject;
            _parentObject     = replacedObject.ParentObject;
            _instanceType     = replacedObject.InstanceType;

            // copy childs
            foreach (COMObject item in replacedObject.ChildObjects)
            {
                AddChildObject(item);
            }

            // remove old object from parent chain
            if (!Object.ReferenceEquals(replacedObject.ParentObject, null))
            {
                COMObject parentObject = replacedObject.ParentObject;
                parentObject.RemoveChildObject(replacedObject);

                // add himself as child to parent object
                parentObject.AddChildObject(this);
            }

            Factory.RemoveObjectFromList(replacedObject);
            Factory.AddObjectToList(this);
        }
Example #2
0
        public COMObject(COMObject replacedObject)
        {
            Factory.CheckInitialize();

            // copy proxy
            _underlyingObject = replacedObject.UnderlyingObject;
            _parentObject     = replacedObject.ParentObject;
            _instanceType     = replacedObject.InstanceType;

            // copy childs
            foreach (COMObject item in replacedObject.ListChildObjects)
            {
                AddChildObject(item);
            }

            // remove old object from parent chain
            if (!Object.ReferenceEquals(replacedObject.ParentObject, null))
            {
                COMObject parentObject = replacedObject.ParentObject;
                parentObject.RemoveChildObject(replacedObject);

                // add himself as child to parent object
                parentObject.AddChildObject(this);
            }

            Factory.RemoveObjectFromList(replacedObject);
            Factory.AddObjectToList(this);
        }
Example #3
0
        /// <summary>
        /// NetOffice method: dispose instance and all child instances
        /// </summary>
        /// <param name="disposeEventBinding">dispose event exported proxies with one or more event recipients</param>
        public virtual void Dispose(bool disposeEventBinding)
        {
            // skip check
            bool cancel = RaiseOnDispose();

            if (cancel)
            {
                return;
            }

            // in case object export events and
            // disposeEventBinding == true we dont remove the object from parents child list
            bool removeFromParent = true;

            // set disposed flag
            _isCurrentlyDisposing = true;

            // in case of object implements also event binding we dispose them
            IEventBinding eventBind = this as IEventBinding;

            if (disposeEventBinding)
            {
                if (!Object.ReferenceEquals(eventBind, null))
                {
                    eventBind.DisposeEventBridge();
                }
            }
            else
            {
                if (!Object.ReferenceEquals(eventBind, null) && (eventBind.EventBridgeInitialized))
                {
                    removeFromParent = false;
                }
            }

            // child proxy dispose
            DisposeChildInstances(disposeEventBinding);


            // remove himself from parent childlist
            if ((!Object.ReferenceEquals(_parentObject, null)) && (true == removeFromParent))
            {
                _parentObject.RemoveChildObject(this);
                _parentObject = null;
            }

            // call quit automaticly if wanted
            if (_callQuitInDispose)
            {
                CallQuit(Settings, Invoker, this);
            }

            // release proxy
            ReleaseCOMProxy();

            // clear supportList reference
            _listSupportedEntities = null;

            _isDisposed           = true;
            _isCurrentlyDisposing = false;
        }
Example #4
0
        /// <summary>
        /// Try to replace new created instance on CreateInstance event
        /// </summary>
        /// <param name="caller">parent instance</param>
        /// <param name="instance">origin instance</param>
        /// <param name="comProxyType">type of native com proxy</param>
        /// <returns>replace instance or origin instance</returns>
        private COMObject TryReplaceInstance(COMObject caller, COMObject instance, Type comProxyType)
        {
            Type typeToReplace = null;
            RaiseCreateInstance(instance, ref typeToReplace);
            instance.DisposeChildInstances();

            if (null != typeToReplace)
            {
                COMObject replaceInstance = Activator.CreateInstance(typeToReplace, new object[] { caller, instance.UnderlyingObject, comProxyType }) as COMObject;
                if (null != replaceInstance)
                {
                    caller.RemoveChildObject(instance);
                    RemoveObjectFromList(instance);
                    return replaceInstance;
                }
            }

            return instance;
        }