예제 #1
0
 public void SetParent([In, MarshalAs(UnmanagedType.IUnknown)] IShimUpdateHost shim)
 {
     if (null == shim)
     {
         throw new ArgumentNullException("shim");
     }
     Parent = shim;
 }
예제 #2
0
        /// <summary>
        /// Try set an outer host to an inner managed addin and suspend errors
        /// </summary>
        /// <param name="innerObject">inner aggregator</param>
        /// <param name="shimHost">outer host</param>
        private void TrySetShimHost(object innerObject, IShimUpdateHost shimHost)
        {
            IManagedInnerUpdateHandler innerAggreator = innerObject as IManagedInnerUpdateHandler;

            try
            {
                if (null != innerAggreator && null != shimHost)
                {
                    innerAggreator.SetParent(shimHost);
                }
            }
            catch
            {
                ;
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a new instance of fullQualifiedTypeName and call outerObject to publish the instance
        /// to the outer caller.
        /// </summary>
        /// <param name="assemblyName">name or strong name where the target type is located</param>
        /// <param name="fullQualifiedTypeName">type to create</param>
        /// <param name="outerAggregator">caller as outer aggregator</param>
        /// <param name="shimHost">outer shim host</param>
        /// <exception cref="ArgumentNullException">argument is null or empty</exception>
        /// <exception cref="MissingMethodException">no matching public constructor was found</exception>/param>
        /// <exception cref="TypeLoadException">typename was not found in assemblyName</exception>/param>
        /// <exception cref="FileNotFoundException">assemblyName was not found</exception>/param>
        /// <exception cref="MethodAccessException">the caller does not have permission to call this constructor</exception>/param>
        /// <exception cref="AppDomainUnloadedException">the operation is attempted on an unloaded application domain.</exception>/param>
        /// <exception cref="BadImageFormatException">assemblyName is not a valid assembly</exception>
        /// <exception cref="FileLoadException">an assembly or module was loaded twice with two different evidences</exception>
        /// <exception cref="InvalidOperationException">unexpected error</exception>
        public void CreateAggregatedInstance(string assemblyName, string fullQualifiedTypeName, IOuterUpdateAggregator outerAggregator, IShimUpdateHost shimHost)
        {
            if (String.IsNullOrWhiteSpace(assemblyName))
            {
                throw new ArgumentNullException("assemblyName");
            }
            if (String.IsNullOrWhiteSpace(fullQualifiedTypeName))
            {
                throw new ArgumentNullException("fullQualifiedTypeName");
            }
            if (null == outerAggregator)
            {
                throw new ArgumentNullException("outerAggregator");
            }

            IntPtr pOuter = IntPtr.Zero;
            IntPtr pInner = IntPtr.Zero;

            try
            {
                pOuter = Marshal.GetIUnknownForObject(outerAggregator);
                if (IntPtr.Zero != pOuter)
                {
                    object innerObject = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(assemblyName, fullQualifiedTypeName);
                    TrySetShimHost(innerObject, shimHost);
                    pInner = Marshal.CreateAggregatedObject(pOuter, innerObject);
                    if (IntPtr.Zero != pInner)
                    {
                        outerAggregator.SetInnerHandler(pInner);
                    }
                }

                if (IntPtr.Zero == pOuter || IntPtr.Zero == pInner)
                {
                    throw new InvalidOperationException("Unexpected result while getting IUnkown Pointer.");
                }
            }
            catch (Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                throw;
            }
            finally
            {
                if (IntPtr.Zero != pOuter)
                {
                    Marshal.Release(pOuter);
                }
                if (IntPtr.Zero != pInner)
                {
                    Marshal.Release(pInner);
                }
                Marshal.ReleaseComObject(outerAggregator);
            }
        }