Beispiel #1
0
 public static void MethodWithoutSafeMode(COMObject comObject, string name, object[] paramsArray)
 {
     try
     {
         comObject.InstanceType.InvokeMember(name, BindingFlags.InvokeMethod | BindingFlags.GetProperty, null, comObject.UnderlyingObject, paramsArray, Settings.ThreadCulture);
     }
     catch (Exception throwedException)
     {
         DebugConsole.WriteException(throwedException);
         throw new System.Runtime.InteropServices.COMException(_exceptionMessage, throwedException);
     }
 }
Beispiel #2
0
 /// <summary>
 /// returns enumerator with scalar variables
 /// </summary>
 /// <param name="comObject"></param>
 /// <returns></returns>
 public static IEnumerator GetScalarEnumeratorAsProperty(COMObject comObject)
 {
     object enumProxy = Invoker.PropertyGet(comObject, "_NewEnum");
     COMObject enumerator = new COMObject(comObject, enumProxy, true);
     Invoker.MethodWithoutSafeMode(enumerator, "Reset", null);
     bool isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
     while (true == isMoveNextTrue)
     {
         object item = Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null);
         isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
         yield return item;
     }
 }
Beispiel #3
0
 /// <summary>
 /// returns enumerator with com proxies
 /// </summary>
 /// <param name="comObject"></param>
 /// <returns></returns>
 public static IEnumerator GetProxyEnumeratorAsMethod(COMObject comObject)
 {
     object enumProxy = Invoker.MethodReturn(comObject, "_NewEnum");
     COMObject enumerator = new COMObject(comObject, enumProxy, true);
     Invoker.MethodWithoutSafeMode(enumerator, "Reset", null);
     bool isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
     while (true == isMoveNextTrue)
     {
         object itemProxy = Invoker.PropertyGetWithoutSafeMode(enumerator, "Current", null);
         COMObject returnClass = LateBindingApi.Core.Factory.CreateObjectFromComProxy(enumerator, itemProxy);
         isMoveNextTrue = (bool)Invoker.MethodReturnWithoutSafeMode(enumerator, "MoveNext", null);
         yield return returnClass;
     }
 }
Beispiel #4
0
        /// <summary>
        /// perform method as latebind call with parameters
        /// </summary>
        /// <param name="comObject">target object</param>
        /// <param name="name">name of method</param>
        /// <param name="paramsArray">array with parameters</param>
        public static void Method(COMObject comObject, string name, object[] paramsArray)
        {
            try
            {
                if( (Settings.EnableSafeMode) && (!comObject.EntityIsAvailable(name,SupportEntityType.Method)))
                    throw new EntityNotSupportedException(string.Format("Method {0} is not available.", name));

                comObject.InstanceType.InvokeMember(name, BindingFlags.InvokeMethod | BindingFlags.GetProperty, null, comObject.UnderlyingObject, paramsArray, Settings.ThreadCulture);
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw new System.Runtime.InteropServices.COMException(_exceptionMessage, throwedException);
            }
        }
Beispiel #5
0
        public COMObject(COMObject replacedObject)
        {
            // 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 (null != replacedObject.ParentObject)
            {
                COMObject parentObject = replacedObject.ParentObject;
                parentObject.RemoveChildObject(replacedObject);

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

            Factory.RemoveObjectFromList(replacedObject);
            Factory.AddObjectToList(this);
        }
Beispiel #6
0
        /// <summary>
        /// perform property set as latebind call
        /// </summary>
        /// <param name="comObject">target object</param>
        /// <param name="name">name of property</param>
        /// <param name="value">value array to be set</param>
        /// <param name="paramModifiers">array with modifiers correspond paramsArray</param>
        public static void PropertySet(COMObject comObject, string name, object[] value, ParameterModifier[] paramModifiers)
        {
            try
            {
                if ((Settings.EnableSafeMode) && (!comObject.EntityIsAvailable(name, SupportEntityType.Property)))
                    throw new EntityNotSupportedException(string.Format("Property {0} is not available.", name));

                comObject.InstanceType.InvokeMember(name, BindingFlags.SetProperty, null, comObject.UnderlyingObject, value, paramModifiers, Settings.ThreadCulture, null);
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw new System.Runtime.InteropServices.COMException(_exceptionMessage, throwedException);
            }
        }
Beispiel #7
0
        public static string GetConnectionPoint(COMObject comProxy, ref IConnectionPoint point, params string[] sinkIds)
        {
            if (null == sinkIds)
                return null;

            IConnectionPointContainer connectionPointContainer = (IConnectionPointContainer)comProxy.UnderlyingObject;

            if (Settings.EnableDebugOutput)
                DebugConsole.WriteLine(comProxy.UnderlyingTypeName + ".GetConnectionPoint");

            if (Settings.EnableDebugOutput)
                DebugConsole.WriteLine(comProxy.UnderlyingTypeName + ".FindConnectionPoint");

            string id = FindConnectionPoint(connectionPointContainer, ref point, sinkIds);

            if (Settings.EnableDebugOutput)
                DebugConsole.WriteLine(comProxy.UnderlyingTypeName + ".FindConnectionPoint sucseed");

            if (null == id)
            {
                if (Settings.EnableDebugOutput)
                    DebugConsole.WriteLine(comProxy.UnderlyingTypeName + ".EnumConnectionPoint");
                id = EnumConnectionPoint(connectionPointContainer, ref point, sinkIds);
                if (Settings.EnableDebugOutput)
                    DebugConsole.WriteLine(comProxy.UnderlyingTypeName + ".EnumConnectionPoint sucseed");
            }

            if (Settings.EnableDebugOutput)
                DebugConsole.WriteLine(comProxy.UnderlyingTypeName + ".GetConnectionPoint passed.");

            if (null != id)
                return id;
            else
                throw new COMException("Specified instance doesnt implement the target event interface.");
        }
Beispiel #8
0
 /// <summary>
 /// perform method as latebind call without parameters 
 /// </summary>
 /// <param name="comObject">target object</param>
 /// <param name="name">name of method</param>
 public static void Method(COMObject comObject, string name)
 {
     Method(comObject, name, null);
 }
Beispiel #9
0
        /// <summary>
        /// perform property set as latebind call
        /// </summary>
        /// <param name="comObject">target object</param>
        /// <param name="name">name of property</param>
        /// <param name="paramsArray">array with parameters</param> 
        /// <param name="value">value to be set</param>
        public static void PropertySet(COMObject comObject, string name, object[] paramsArray, object value)
        {
            try
            {
                if ((Settings.EnableSafeMode) && (!comObject.EntityIsAvailable(name, SupportEntityType.Property)))
                    throw new EntityNotSupportedException(string.Format("Property {0} is not available.", name));

                object[] newParamsArray = new object[paramsArray.Length + 1];
                for (int i = 0; i < paramsArray.Length; i++)
                    newParamsArray[i] = paramsArray[i];
                newParamsArray[newParamsArray.Length - 1] = value;

                comObject.InstanceType.InvokeMember(name, BindingFlags.SetProperty, null, comObject.UnderlyingObject, newParamsArray, Settings.ThreadCulture);
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw new System.Runtime.InteropServices.COMException(_exceptionMessage, throwedException);
            }
        }
Beispiel #10
0
		public IRibbonControl_SinkHelper(COMObject eventClass, IConnectionPoint connectPoint): base(eventClass)
		{
			_eventClass = eventClass;
			_eventBinding = (IEventBinding)eventClass;
			SetupEventBinding(connectPoint);
		}
Beispiel #11
0
        /// <summary>
        /// perform property get as latebind call with return value
        /// </summary>
        /// <param name="comObject">target object</param>
        /// <param name="name">name of property</param>
        /// <returns>any return value</returns>
        public static object PropertyGet(COMObject comObject, string name)
        {
            try
            {
                if ((Settings.EnableSafeMode) && (!comObject.EntityIsAvailable(name, SupportEntityType.Property)))
                    throw new EntityNotSupportedException(string.Format("Property {0} is not available.", name));

                object returnValue = comObject.InstanceType.InvokeMember(name, BindingFlags.GetProperty, null, comObject.UnderlyingObject, null, Settings.ThreadCulture);
                return returnValue;
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw new System.Runtime.InteropServices.COMException(_exceptionMessage, throwedException);
            }
        }
Beispiel #12
0
		public Global(COMObject parentObject, object comProxy, NetRuntimeSystem.Type comProxyType) : base(parentObject, comProxy, comProxyType)
		{
			
		}
Beispiel #13
0
        /// <summary>
        ///  creates a new COMObject array
        /// </summary>
        /// <param name="caller">parent there have created comProxy</param>
        /// <param name="comProxyArray">new created proxy array</param>
        /// <returns>corresponding Wrapper class Instance array or plain COMObject array</returns>
        public static COMObject[] CreateObjectArrayFromComProxy(COMObject caller, object[] comProxyArray)
        {
            bool isLocked = false;
            try
            {
                if (null == comProxyArray)
                    return null;
                
                if (Settings.EnableThreadSafe)
                {
                    Monitor.Enter(_comObjectLock);
                    isLocked = true;
                }

                Type comVariantType = null;
                COMObject[] newVariantArray = new COMObject[comProxyArray.Length];
                for (int i = 0; i < comProxyArray.Length; i++)
                {
                    comVariantType = comProxyArray[i].GetType();
                    IFactoryInfo factoryInfo = GetFactoryInfo(comProxyArray[i]);
                    string className = TypeDescriptor.GetClassName(comProxyArray[i]);
                    string fullClassName = factoryInfo.AssemblyNamespace + "." + className;
                    newVariantArray[i] = CreateObjectFromComProxy(factoryInfo, caller, comProxyArray[i], comVariantType, className, fullClassName);
                }
                return newVariantArray;
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw throwedException;
            }
            finally
            {
                if (isLocked)
                {
                    Monitor.Exit(_comObjectLock);
                    isLocked = false;
                }
            }
        }
Beispiel #14
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)
        {
            // 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 (null != eventBind)
                    eventBind.DisposeEventBridge();
            }
            else
            {
                if ((null != eventBind) && (eventBind.EventBridgeInitialized))
                    removeFromParent = false;
            }

            // child proxy dispose
            DisposeChildInstances(disposeEventBinding);

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

            // call quit automaticly if wanted
            if (_callQuitInDispose)
                CallQuit(_underlyingObject);

            // release proxy
            ReleaseCOMProxy();

            // clear supportList reference
            _listSupportedEntities = null;

            _isDisposed = true;
            _isCurrentlyDisposing = false;
        }
Beispiel #15
0
        /// <summary>
        /// creates a new COMObject based on classType of comProxy 
        /// </summary>
        /// <param name="caller">parent there have created comProxy</param>
        /// <param name="comProxy">new created proxy</param>
        /// <param name="comProxyType">Type of comProxy</param>
        /// <returns>corresponding Wrapper class Instance or plain COMObject</returns>
        public static COMObject CreateObjectFromComProxy(COMObject caller, object comProxy, Type comProxyType)
        {
            bool isLocked = false;
            try
            {
                if (null == comProxy)
                    return null;

                if (Settings.EnableThreadSafe)
                {
                    Monitor.Enter(_comObjectLock);
                    isLocked = true;
                }

                IFactoryInfo factoryInfo = GetFactoryInfo(comProxy);

                string className = TypeDescriptor.GetClassName(comProxy);
                string fullClassName = factoryInfo.AssemblyNamespace + "." + className;

                // create new classType
                COMObject newObject = CreateObjectFromComProxy(factoryInfo, caller, comProxy, comProxyType, className, fullClassName);
                return newObject;
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw throwedException;
            }
            finally
            {
                if (isLocked)
                {
                    Monitor.Exit(_comObjectLock);
                    isLocked = false;
                }
            }
        }
Beispiel #16
0
 public void RemoveChildObject(COMObject childObject)
 {
     bool isLocked = false;
     try
     {
         _listChildObjects.Remove(childObject);
     }
     catch (Exception throwedException)
     {
         DebugConsole.WriteException(throwedException);
         throw (throwedException);
     }
     finally
     {
         if (isLocked)
         {
             Monitor.Exit(_childListLock);
             isLocked = false;
         }
     }
 }
Beispiel #17
0
        public void AddChildObject(COMObject childObject)
        {
            bool isLocked = false;
            try
            {
                if (Settings.EnableThreadSafe)
                {
                    Monitor.Enter(_childListLock);
                    isLocked = true;
                }

                _listChildObjects.Add(childObject);
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw (throwedException);
            }
            finally
            {
                if (isLocked)
                {
                    Monitor.Exit(_childListLock);
                    isLocked = false;
                }
            }
        }
Beispiel #18
0
        public COMObject(COMObject parentObject, object comProxy, Type comProxyType)
        {
            _parentObject = parentObject;
            _underlyingObject = comProxy;
            _instanceType = comProxyType;

            if (null != parentObject)
                _parentObject.AddChildObject(this);

            Factory.AddObjectToList(this);
        }
Beispiel #19
0
        public COMObject(COMObject parentObject, object comProxy, bool isEnumerator)
        {
            _parentObject = parentObject;
            _underlyingObject = comProxy;
            _isEnumerator = isEnumerator;
            _instanceType = comProxy.GetType();

            if (null != parentObject)
                _parentObject.AddChildObject(this);

            Factory.AddObjectToList(this);
        }
Beispiel #20
0
        /// <summary>
        /// remove object from global list
        /// </summary>
        /// <param name="proxy"></param>
        internal static void RemoveObjectFromList(COMObject proxy)
        {
            bool isLocked = false;
            try
            {
                if (Settings.EnableThreadSafe)
                {
                    Monitor.Enter(_globalObjectList);
                    isLocked = true;
                }

                _globalObjectList.Remove(proxy);

                if (null != ProxyCountChanged)
                    ProxyCountChanged(_globalObjectList.Count);
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
            }
            finally
            {
                if (isLocked)
                {
                    Monitor.Exit(_globalObjectList);
                    isLocked = false;
                }
            }
        }
Beispiel #21
0
        /// <param name="parentObject">object there has created the proxy</param>
        /// <param name="comProxy">inner wrapped COM proxy</param>
		public Global(COMObject parentObject, object comProxy) : base(parentObject, comProxy)
		{
			
		}
Beispiel #22
0
        /// <summary>
        /// creates a new COMObject array based on wrapperClassType
        /// </summary>
        /// <param name="caller"></param>
        /// <param name="comProxyArray"></param>
        /// <param name="wrapperClassType"></param>
        /// <returns></returns>
        public static COMObject[] CreateKnownObjectArrayFromComProxy(COMObject caller, object[] comProxyArray, Type wrapperClassType)
        {
            bool isLocked = false;
            try
            {
                if (null == comProxyArray)
                    return null;

                if (Settings.EnableThreadSafe)
                {
                    Monitor.Enter(_comObjectLock);
                    isLocked = true;
                }

                Type comVariantType = null;
                COMObject[] newVariantArray = new COMObject[comProxyArray.Length];
                for (int i = 0; i < comProxyArray.Length; i++)
                    newVariantArray[i] = Activator.CreateInstance(wrapperClassType, new object[] { caller, comProxyArray[i], comVariantType }) as COMObject;

                return newVariantArray;
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw throwedException;
            }
            finally
            {
                if (isLocked)
                {
                    Monitor.Exit(_comObjectLock);
                    isLocked = false;
                }
            }
        }
Beispiel #23
0
		public Global(COMObject replacedObject) : base(replacedObject)
		{
			
		}
Beispiel #24
0
        /// <summary>
        /// creates a new COMObject from factoryInfo
        /// </summary>
        /// <param name="factoryInfo">Factory Info from Wrapper Assemblies</param>
        /// <param name="caller">parent there have created comProxy</param>
        /// <param name="comProxy">new created proxy</param>
        /// <param name="comProxyType">Type of comProxy</param>
        /// <param name="className">name of COMServer proxy class</param>
        /// <param name="fullClassName">full namespace and name of COMServer proxy class</param>
        /// <returns>corresponding Wrapper class Instance or plain COMObject</returns>
        public static COMObject CreateObjectFromComProxy(IFactoryInfo factoryInfo, COMObject caller, object comProxy, Type comProxyType, string className, string fullClassName)
        {
            bool isLocked = false;
            try
            {
                if (Settings.EnableThreadSafe)
                {
                    Monitor.Enter(_comObjectLock);
                    isLocked = true;
                }

                Type classType = null;
                if (true == _wrapperTypeCache.TryGetValue(fullClassName, out classType))
                {
                    // cached classType
                    object newClass = Activator.CreateInstance(classType, new object[] { caller, comProxy });
                    return newClass as COMObject;
                }
                else
                {
                    // create new classType
                    classType = factoryInfo.Assembly.GetType(fullClassName, false, true);
                    if (null == classType)
                        throw new ArgumentException("Class not exists: " + fullClassName);

                    _wrapperTypeCache.Add(fullClassName, classType);
                    COMObject newClass = Activator.CreateInstance(classType, new object[] { caller, comProxy, comProxyType }) as COMObject;
                    return newClass;
                }
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw throwedException;
            }
            finally
            {
                if (isLocked)
                {
                    Monitor.Exit(_comObjectLock);
                    isLocked = false;
                }
            }
        }
Beispiel #25
0
 /// <summary>
 /// creates instance
 /// </summary>
 /// <param name="eventClass"></param>
 public SinkHelper(COMObject eventClass)
 {
     _eventClass = eventClass;
 }
Beispiel #26
0
        /// <summary>
        /// creates a new COMObject based on wrapperClassType
        /// </summary>
        /// <param name="caller"></param>
        /// <param name="comProxy"></param>
        /// <param name="wrapperClassType"></param>
        /// <returns></returns>
        public static COMObject CreateKnownObjectFromComProxy(COMObject caller, object comProxy, Type wrapperClassType)
        {
            bool isLocked = false;
            try
            {
                if (null == comProxy)
                    return null;

                if (Settings.EnableThreadSafe)
                {
                    Monitor.Enter(_comObjectLock);
                    isLocked = true;
                }

                // create new proxyType
                Type comProxyType = null;
                if (false == _proxyTypeCache.TryGetValue(wrapperClassType.FullName, out comProxyType))
                {
                    comProxyType = comProxy.GetType();
                    _proxyTypeCache.Add(wrapperClassType.FullName, comProxyType);
                }

                COMObject newClass = Activator.CreateInstance(wrapperClassType, new object[] { caller, comProxy, comProxyType }) as COMObject;
                return newClass;
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                throw throwedException;
            }
            finally
            {
                if (isLocked)
                {
                    Monitor.Exit(_comObjectLock);
                    isLocked = false;
                }
            }
        }