Beispiel #1
0
        public PactCoreHost(T config)
        {
            _config = config;

            var currentDir  = Directory.GetCurrentDirectory();
            var pactCoreDir = $"{currentDir}\\pact";

            var startInfo = new ProcessStartInfo
            {
                WindowStyle            = ProcessWindowStyle.Hidden,
                FileName               = $"{pactCoreDir}\\lib\\ruby\\bin.real\\ruby.exe",
                Arguments              = $"-rbundler/setup -I\"{pactCoreDir}\\lib\\app\\lib\" \"{pactCoreDir}\\lib\\app\\{_config.Script}\" {_config.Arguments}",
                UseShellExecute        = false,
                RedirectStandardInput  = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true
            };

            startInfo.EnvironmentVariables["ROOT_PATH"]      = pactCoreDir;
            startInfo.EnvironmentVariables["RUNNING_PATH"]   = $"{pactCoreDir}\\bin\\";
            startInfo.EnvironmentVariables["BUNDLE_GEMFILE"] = $"{pactCoreDir}\\lib\\vendor\\Gemfile";
            startInfo.EnvironmentVariables["RUBYLIB"]        = $"{pactCoreDir}\\lib\\ruby\\lib\\ruby\\site_ruby\\{RubyVersion};{pactCoreDir}\\lib\\ruby\\lib\\ruby\\site_ruby\\{RubyVersion}\\{RubyArch};{pactCoreDir}\\lib\\ruby\\lib\\ruby\\site_ruby;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\vendor_ruby\\{RubyVersion};{pactCoreDir}\\lib\\ruby\\lib\\ruby\\vendor_ruby\\{RubyVersion}\\{RubyArch};{pactCoreDir}\\lib\\ruby\\lib\\ruby\\vendor_ruby;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\{RubyVersion};{pactCoreDir}\\lib\\ruby\\lib\\ruby\\{RubyVersion}\\{RubyArch}";
            startInfo.EnvironmentVariables["SSL_CERT_FILE"]  = $"{pactCoreDir}\\lib\\ruby\\lib\\ca-bundle.crt";

            _process = new Process
            {
                StartInfo = startInfo
            };

            AppDomain.CurrentDomain.DomainUnload += CurrentDomainUnload;
        }
Beispiel #2
0
        public PactCoreHost(T config)
        {
            _config = config;

            _process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    WindowStyle            = ProcessWindowStyle.Minimized,
                    FileName               = _config.Path,
                    Arguments              = _config.Arguments,
                    UseShellExecute        = false, //Important so that the correct process is killed
                    RedirectStandardInput  = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                                             //NOTE: Do Not set CreateNoWindow = true, as it will spawn the ruby process as a child and we then can't kill it without using System.Management
                }
            };

            AppDomain.CurrentDomain.DomainUnload += CurrentDomainUnload;
        }
        public PactCoreHost(T config)
        {
            _config = config;

            var expectedPackage = String.Empty;

#if USE_NET4X
            var pactCoreDir = $"{Constants.BuildDirectory}{Path.DirectorySeparatorChar}"; //OS specific version will be appended
            pactCoreDir    += "pact-win32";
            expectedPackage = "PactNet.Windows";
#else
            var pactCoreDir = $"{Constants.BuildDirectory}{Path.DirectorySeparatorChar}"; //OS specific version will be appended

            if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
            {
                pactCoreDir    += "pact-win32";
                expectedPackage = "PactNet.Windows";
            }
            else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
            {
                pactCoreDir    += "pact-osx";
                expectedPackage = "PactNet.OSX";
            }
            else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) &&
                     System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X86)
            {
                pactCoreDir    += "pact-linux-x86";
                expectedPackage = "PactNet.Linux.x86";
            }
            else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) &&
                     System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)
            {
                pactCoreDir    += "pact-linux-x86_64";
                expectedPackage = "PactNet.Linux.x64";
            }
            else
            {
                throw new PactFailureException("Sorry your current OS platform or architecture is not supported");
            }
#endif

            if (!Directory.Exists(pactCoreDir))
            {
                throw new PactFailureException($"Please install the relevant platform and architecture specific PactNet dependency from Nuget. Based on your current setup you should install '{expectedPackage}'.");

                //TODO: Fall back to using the locally installed ruby and packaged assets
            }

            var configPath     = $"{pactCoreDir}{Path.DirectorySeparatorChar}config.json";
            var platformConfig = JsonConvert.DeserializeObject <PlatformCoreConfig>(File.ReadAllText(configPath));

            var startInfo = new ProcessStartInfo
            {
#if USE_NET4X
                WindowStyle = ProcessWindowStyle.Hidden,
#endif
                FileName               = ReplaceConfigParams(platformConfig.FileName, pactCoreDir, _config.Script),
                Arguments              = $"{ReplaceConfigParams(platformConfig.Arguments, pactCoreDir, _config.Script)} {_config.Arguments}",
                UseShellExecute        = false,
                RedirectStandardInput  = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true
            };

            if (platformConfig.Environment != null)
            {
                foreach (var envVar in platformConfig.Environment)
                {
                    var value = ReplaceConfigParams(envVar.Value, pactCoreDir, _config.Script);
#if USE_NET4X
                    startInfo.EnvironmentVariables[envVar.Key] = value;
#else
                    startInfo.Environment[envVar.Key] = value;
#endif
                }
            }

            _process = new Process
            {
                StartInfo = startInfo
            };

#if USE_NET4X
            AppDomain.CurrentDomain.DomainUnload += (o, e) => Stop();
#else
            System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += context => Stop();
#endif
        }