示例#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);
        }
        /// <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);
        }
示例#3
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);
        }