/// <summary>
        /// Creates a new WrapperProcessStarter instance.
        /// </summary>
        /// <param name="wrapperExecutableNameProvider">Provides the name for the wrapper executable to start.</param>
        /// <param name="pipeToken">PipeToken instance for creating pipe connections.</param>
        /// <param name="processFactory">IProcessFactory instance for creating a new wrapper process</param>
        public WrapperProcessStarter(IWrapperExecutableNameProvider wrapperExecutableNameProvider, PipeToken pipeToken, IProcessFactory processFactory, IWrapperConfig configuration)
        {
            Raise.ArgumentNullException.IfIsNull(wrapperExecutableNameProvider, nameof(wrapperExecutableNameProvider));
            Raise.ArgumentNullException.IfIsNull(pipeToken, nameof(pipeToken));
            Raise.ArgumentNullException.IfIsNull(processFactory);

            _wrapperExecutableNameProvider = wrapperExecutableNameProvider;
            _pipeToken            = pipeToken;
            _processFactory       = processFactory;
            _wrapperConfiguration = configuration;
        }
Ejemplo n.º 2
0
        public void TestMethodContainsNoAttribute()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            using (var client = WrapperProxyFactory <ITestDllWithAttribute> .GetInstance(configuration))
            {
                client.MethodWithoutAttribute();
            }
        }
Ejemplo n.º 3
0
        public void TestLoadNonExistingFunction()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            using (var client = WrapperProxyFactory <ITestDll> .GetInstance(configuration))
            {
                client.TestNonExistingFunction();
            }
        }
Ejemplo n.º 4
0
        public void TestTypeIsNotAnInterface()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            // Test a random class that's derived from IDisposable but not an interface
            using (WrapperProxyFactory <HttpListener> .GetInstance(configuration))
            {
                // Do nothing
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new instance of TFunctions.
        /// All calls will be proxied over a named pipe to the wrapper executable.
        /// </summary>
        /// <param name="configuration">WrapperConfiguration object holding configuration info.</param>
        /// <exception cref="ArgumentException">An ArgumentException is thrown if the supplied generic type parameter is not an interface.</exception>
        /// <returns>Returns a new instance of TFunctions.</returns>
        public static TFunctions GetInstance(IWrapperConfig configuration)
        {
            Raise.ArgumentException.IfNot(typeof(TFunctions).IsInterface, nameof(TFunctions), "Generic parameter type <TFunctions> must be an interface.");
            Raise.ArgumentException.IfNot(typeof(TFunctions).IsPublic, nameof(TFunctions), "The provided interface type <TFunctions> must be public.");

            CreateToken();

            InjectionKernel.Rebind <IWrapperConfig>().ToConstant(configuration);
            InjectionKernel.Rebind <Type>().ToConstant(typeof(TFunctions));

            return(CreateProxy());
        }
Ejemplo n.º 6
0
        public void TestCallMethodWithoutException()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            // Create new Wrapper client providing the proxy interface
            // Remember to ensure a call to the Dispose()-Method!
            using (var client = WrapperProxyFactory <IUser32Dll> .GetInstance(configuration))
            {
                // Make calls - it's that simple!
                int x = client.GetSystemMetrics(0);
                int y = client.GetSystemMetrics(1);
            }
        }
Ejemplo n.º 7
0
        public void TestMustThrowObjectDisposedException()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            ITestDll client;

            using (client = WrapperProxyFactory <ITestDll> .GetInstance(configuration))
            {
                // Do nothing
            }

            client.TestStdCall(0);
        }
Ejemplo n.º 8
0
        public void TestRefParameterHandling()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            int parameter = 1337;

            using (var client = WrapperProxyFactory <ITestDll> .GetInstance(configuration))
            {
                client.TestVarParamHandling(ref parameter);
            }

            // Ref param should be incremented by 1
            Assert.AreEqual(1338, parameter);
        }
Ejemplo n.º 9
0
        public void TestPWideCharHandling()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            string input = "Hello World";

            string result;

            using (var client = WrapperProxyFactory <ITestDll> .GetInstance(configuration))
            {
                result = client.TestPWideCharHandling(input);
            }

            Assert.AreEqual(input, result);
        }
Ejemplo n.º 10
0
        public void TestNormalFunc()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create()
                                           .TargetArchitecture(ArchitectureToLoad)
                                           .Build();

            int input = 5;

            int result;

            using (var client = WrapperProxyFactory <ITestDll> .GetInstance(configuration))
            {
                result = client.TestNormalFunc(input);
            }

            Assert.AreEqual(input, result);
        }
Ejemplo n.º 11
0
        public DefaultWrapperExecutableNameProvider(IWrapperConfig configuration)
        {
            Raise.ArgumentNullException.IfIsNull(configuration);

            _configuration = configuration;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a new WrapperClient instance.
        /// </summary>
        /// <param name="formatter">Formatter instance for data serialization to the pipe.</param>
        /// <param name="wrapperProcessStarter">WrapperProcessStarter instance for invoking the appropriate wrapper executable.</param>
        /// <param name="pipeStreamFactory">A factory instance to create a new NamedPipeClientStream.</param>
        /// <param name="pipeToken">PipeToken instance for creating pipe connections.</param>
        /// <param name="wrapperConfig">the wrapperconfig</param>
        public PipeConnector(IFormatter formatter, IWrapperProcessStarter wrapperProcessStarter, PipeStreamFactory pipeStreamFactory, PipeToken pipeToken, IWrapperConfig wrapperConfig)
        {
            Raise.ArgumentNullException.IfIsNull(formatter, nameof(formatter));
            Raise.ArgumentNullException.IfIsNull(wrapperProcessStarter, nameof(wrapperProcessStarter));
            Raise.ArgumentNullException.IfIsNull(pipeStreamFactory, nameof(pipeStreamFactory));
            Raise.ArgumentNullException.IfIsNull(pipeToken, nameof(pipeToken));

            _formatter             = formatter;
            _wrapperProcessStarter = wrapperProcessStarter;
            _pipeStreamFactory     = pipeStreamFactory;
            _pipeToken             = pipeToken;

            _wrapperProcessStarter.StartWrapperProcess();
            OpenPipe(wrapperConfig.Timeout);
        }