Exemple #1
0
        /// <summary>
        /// Creates a new ICOMObject based on classType of comProxy
        /// </summary>
        /// <param name="caller">parent there have created comProxy</param>
        /// <param name="comProxy">new created proxy</param>
        /// <param name="allowDynamicObject">allow to create a COMDynamicObject instance if its failed to resolve the wrapper type</param>
        /// <returns>corresponding wrapper class instance or plain COMObject</returns>
        /// <exception cref="ArgumentNullException">comProxy arguments is null</exception>
        /// <exception cref="CreateInstanceException">throws when its failed to create new instance</exception>
        /// <exception cref="FactoryException">throws when its failed to find the corresponding factory. this indicates a missing netoffice api assembly</exception>
        /// <exception cref="NetOfficeInitializeException">unexpected initialization error. see inner exception(s) for details</exception>
        public virtual ICOMObject CreateObjectFromComProxy(ICOMObject caller, object comProxy, bool allowDynamicObject)
        {
            if (null == caller)
            {
                throw new ArgumentNullException("caller");
            }

            CheckInitialize();
            try
            {
                ICOMObject result      = null;
                Guid       typeId      = Guid.Empty;
                Guid       componentId = Guid.Empty;

                CoreTypeExtensions.GetComponentAndTypeId(this, comProxy, ref componentId, ref typeId);

                lock (_createComObjectLock)
                {
                    // get type factory first to handle possible duplicate type
                    ITypeFactory factoryInfo = CoreFactoryExtensions.GetTypeFactory(this, caller, comProxy, componentId, typeId, false);
                    if (null != factoryInfo)
                    {
                        TypeInformation typeInfo = CoreTypeExtensions.GetTypeInformationForUnknownObject(this, factoryInfo, typeId, comProxy);
                        if (null == typeInfo)
                        {
                            throw new FactoryException(String.Format("Unable to resolve proxy type:{0}", ComTypes.TypeDescriptor.GetFullComponentClassName(comProxy)));
                        }

                        result = CoreCreateExtensions.CreateInstance(this, typeInfo, caller, comProxy);
                        //result = InternalObjectActivator.TryReplaceInstance(caller, result);
                    }
                    else
                    {
                        result = CoreCreateExtensions.TryCreateObjectByResolveEvent(this, caller, null, comProxy);
                        if (null == result)
                        {
                            if (allowDynamicObject && Settings.EnableDynamicObjects)
                            {
                                result = InternalObjectActivator.RaiseCreateCOMDynamic(caller, comProxy);
                                if (null == result)
                                {
                                    result = new COMDynamicObject(caller, comProxy);
                                }
                            }
                            else
                            {
                                throw new FactoryException(String.Format("Unable to resolve proxy type:{0}", ComTypes.TypeDescriptor.GetFullComponentClassName(comProxy)));
                            }
                        }
                    }

                    return(result);
                }
            }
            catch (Exception throwedException)
            {
                Console.WriteException(throwedException);
                throw;
            }
        }
Exemple #2
0
        private ICOMObject InternalCreateKnownObjectFromComProxy(ICOMObject caller, object comProxy, Type contractWrapperType)
        {
            CheckInitialize();
            try
            {
                ICOMObject result = null;
                lock (_createComObjectLock)
                {
                    TypeInformation typeInfo = CoreTypeExtensions.GetTypeInformationForKnownObject(this, contractWrapperType, comProxy);
                    if (null != typeInfo)
                    {
                        result = CoreCreateExtensions.CreateInstance(this, typeInfo, caller, comProxy);
                    }
                    else
                    {
                        result = CoreCreateExtensions.TryCreateObjectByResolveEvent(this, caller, contractWrapperType, contractWrapperType);
                        if (null == result)
                        {
                            throw new FactoryException(String.Format("Unable to find implementation: {0}.", contractWrapperType.FullName));
                        }
                    }

                    //result = InternalObjectActivator.TryReplaceInstance(caller, result);
                    return(result);
                }
            }
            catch (Exception throwedException)
            {
                Console.WriteException(throwedException);
                throw;
            }
        }
 object Native.IRtdServer.ConnectData(int topicID, ref object strings, ref bool getNewValues)
 {
     try
     {
         lock (_thisLock)
         {
             object result = ConnectData(topicID, CoreTypeExtensions.WrapObject(Factory, strings, true), getNewValues);
             return(Invoker.ValidateParam(result));
         }
     }
     catch (Exception exception)
     {
         OnError(RTDMethods.ConnectData, exception);
         throw new COMRtdServerException(RTDMethods.Unknown, exception);
     }
 }
Exemple #4
0
        /// <summary>
        /// Creates an entity support list for a proxy
        /// </summary>
        /// <param name="factory">core to perform searching</param>
        /// <param name="comProxy">proxy to analyze</param>
        /// <returns>supported methods and properties as name/kind dictionary</returns>
        /// <exception cref="COMException">Throws generaly if any exception occurs. See inner exception(s) for details</exception>
        internal Dictionary <string, string> GetSupportedEntities(Core factory, object comProxy)
        {
            try
            {
                Guid parentLibraryGuid = CoreTypeExtensions.GetParentLibraryGuid(factory, comProxy);
                if (Guid.Empty == parentLibraryGuid)
                {
                    return(null);
                }

                string className = TypeDescriptor.GetClassName(comProxy);
                string key       = (parentLibraryGuid.ToString() + className).ToLower();

                Dictionary <string, string> supportList = null;
                if (factory.InternalCache.EntitiesListCache.TryGetValue(key, out supportList))
                {
                    return(supportList);
                }

                supportList = new Dictionary <string, string>();
                IDispatch dispatch = comProxy as IDispatch;
                if (null == dispatch)
                {
                    throw new COMException("Unable to cast underlying proxy to IDispatch.");
                }

                COMTypes.ITypeInfo typeInfo = dispatch.GetTypeInfo(0, 0);
                if (null == typeInfo)
                {
                    throw new COMException("GetTypeInfo returns null.");
                }

                IntPtr typeAttrPointer = IntPtr.Zero;
                typeInfo.GetTypeAttr(out typeAttrPointer);

                COMTypes.TYPEATTR typeAttr = (COMTypes.TYPEATTR)Marshal.PtrToStructure(typeAttrPointer, typeof(COMTypes.TYPEATTR));
                for (int i = 0; i < typeAttr.cFuncs; i++)
                {
                    string            strName, strDocString, strHelpFile;
                    int               dwHelpContext;
                    IntPtr            funcDescPointer = IntPtr.Zero;
                    COMTypes.FUNCDESC funcDesc;
                    typeInfo.GetFuncDesc(i, out funcDescPointer);
                    funcDesc = (COMTypes.FUNCDESC)Marshal.PtrToStructure(funcDescPointer, typeof(COMTypes.FUNCDESC));

                    switch (funcDesc.invkind)
                    {
                    case COMTypes.INVOKEKIND.INVOKE_PROPERTYGET:
                    case COMTypes.INVOKEKIND.INVOKE_PROPERTYPUT:
                    case COMTypes.INVOKEKIND.INVOKE_PROPERTYPUTREF:
                    {
                        typeInfo.GetDocumentation(funcDesc.memid, out strName, out strDocString, out dwHelpContext, out strHelpFile);
                        string outValue = "";
                        bool   exists   = supportList.TryGetValue("Property-" + strName, out outValue);
                        if (!exists)
                        {
                            supportList.Add("Property-" + strName, strDocString);
                        }
                        break;
                    }

                    case COMTypes.INVOKEKIND.INVOKE_FUNC:
                    {
                        typeInfo.GetDocumentation(funcDesc.memid, out strName, out strDocString, out dwHelpContext, out strHelpFile);
                        string outValue = "";
                        bool   exists   = supportList.TryGetValue("Method-" + strName, out outValue);
                        if (!exists)
                        {
                            supportList.Add("Method-" + strName, strDocString);
                        }
                        break;
                    }
                    }

                    typeInfo.ReleaseFuncDesc(funcDescPointer);
                }

                typeInfo.ReleaseTypeAttr(typeAttrPointer);
                Marshal.ReleaseComObject(typeInfo);

                factory.InternalCache.EntitiesListCache.Add(key, supportList);

                return(supportList);
            }
            catch (Exception exception)
            {
                throw new COMException("An unexpected error occurs.", exception);
            }
        }