示例#1
0
        /// <summary>
        /// Create an instance of the managed adapter.
        /// </summary>
        /// <typeparam name="T">The type of the adapter.</typeparam>
        /// <param name="adapterType">The type of the implementation.</param>
        /// <param name="typeToProxy">The type of the adapter.</param>
        /// <returns>The managed adapter</returns>
        public static T Wrap <T>(Type adapterType, Type typeToProxy) where T : IAdapter
        {
            object proxy             = Create <T, ManagedAdapterProxy>();
            ManagedAdapterProxy self = (ManagedAdapterProxy)proxy;

            AdapterProxyBase.SetParameters((ManagedAdapterProxy)proxy, typeToProxy);
            self.trueType = adapterType;

            try
            {
                self.instance = TestToolHelpers.CreateInstanceFromTypeName(adapterType.FullName) as ManagedAdapterBase;
            }
            catch (InvalidOperationException)
            {
            }

            if (self.instance == null)
            {
                throw new InvalidOperationException(
                          String.Format("Adapter {0} instance creation failed",
                                        typeToProxy.FullName));
            }
            else if (!typeToProxy.IsAssignableFrom(self.instance.GetType()))
            {
                throw new InvalidOperationException(
                          String.Format("Adapter {0} does not implement {1}",
                                        adapterType.Name, typeToProxy.FullName));
            }

            return((T)proxy);
        }
示例#2
0
        /// <summary>
        /// Create an instance of the powershell adapter.
        /// </summary>
        /// <typeparam name="T">The type of the adapter.</typeparam>
        /// <param name="scriptDirectory">The folder containing the script files.</param>
        /// <param name="typeToProxy">The type of the adapter.</param>
        /// <returns>The powershell adapter</returns>
        public static T Wrap <T>(Type typeToProxy) where T : IAdapter
        {
            object proxy = Create <T, InteractiveAdapterProxy>();
            InteractiveAdapterProxy self = (InteractiveAdapterProxy)proxy;

            AdapterProxyBase.SetParameters(self, typeToProxy);
            //self.scriptDirectory = scriptDirectory.Replace("\\", "/");

            return((T)proxy);
        }
        /// <summary>
        /// Create an instance of the powershell adapter.
        /// </summary>
        /// <typeparam name="T">The type of the adapter.</typeparam>
        /// <param name="scriptDirectory">The folder containing the script files.</param>
        /// <param name="typeToProxy">The type of the adapter.</param>
        /// <returns>The powershell adapter</returns>
        public static T Wrap <T>(string scriptDirectory, Type typeToProxy) where T : IAdapter
        {
            object proxy = Create <T, PowerShellAdapterProxy>();
            PowerShellAdapterProxy self = (PowerShellAdapterProxy)proxy;

            AdapterProxyBase.SetParameters(self, typeToProxy);
            self.scriptDirectory = scriptDirectory.Replace("\\", "/");

            return((T)proxy);
        }
示例#4
0
        /// <summary>
        /// For derived class to set the proxyType variable.
        /// </summary>
        /// <param name="proxy">The proxy instance.</param>
        /// <param name="typeToProxy">The adapter type.</param>
        protected static void SetParameters(AdapterProxyBase proxy, Type typeToProxy)
        {
            proxy.proxyType = typeToProxy;
            proxy.adapterInitializeMethod = typeof(IAdapter).GetMethod("Initialize");
            proxy.adapterGetSiteMethod    = typeof(IAdapter).GetMethod("get_Site");
            proxy.adapterResetMethod      = typeof(IAdapter).GetMethod("Reset");
            proxy.disposableDisposeMethod = typeof(IDisposable).GetMethod("Dispose");
            proxy.objectGetHashCodeMethod = typeof(object).GetMethod("GetHashCode");

            if (!typeof(IAdapter).IsAssignableFrom(typeToProxy))
            {
                throw new InvalidOperationException(String.Format("Type '{0}' is not a valid adapter type.", typeToProxy));
            }
        }