public void KillSession()
 {
     //clean up
     if (null != _agentServiceHost)
     {
         _agentServiceHost.Close();
     }
     _exitWaitHandle.Set(); //allows WaitUntilExit to return
 }
Example #2
0
            private bool disposedValue = false; // To detect redundant calls

            protected virtual void Dispose(bool disposing)
            {
                if (!disposedValue)
                {
                    if (disposing)
                    {
                        _client.Dispose();
                        _callbackChannel.Close();
                        _callbackChannel.Dispose();
                    }
                    disposedValue = true;
                }
            }
Example #3
0
        static void Main(string[] args)
        {
            var logger = new Logger(logLevel: LogLevel.Debug);
            var stats  = new Stats();

            var ip         = ConfigurationManager.AppSettings["ip"];
            var port       = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
            var ipEndpoint = new IPEndPoint(IPAddress.Any, port);

            var useCompression       = false;
            var compressionThreshold = 131072; //128KB
            var pipeName             = "ServiceWireTestHost";

            var nphost = new NpHost(pipeName, logger, stats);
            var tester = new NetTester();

            nphost.AddService <INetTester>(tester);
            var mytester = new MyTester();

            nphost.UseCompression       = useCompression;
            nphost.CompressionThreshold = compressionThreshold;
            nphost.AddService <IMyTester>(mytester);
            nphost.Open();

            var tcphost = new TcpHost(ipEndpoint, logger, stats);

            tcphost.UseCompression       = useCompression;
            tcphost.CompressionThreshold = compressionThreshold;
            tcphost.AddService <INetTester>(tester);
            tcphost.AddService <IMyTester>(mytester);

            var valTypes = new ValTypes();

            tcphost.AddService <IValTypes>(valTypes);

            tcphost.Open();

            Console.WriteLine("Press Enter to stop the dual host test.");
            Console.ReadLine();

            nphost.Close();
            tcphost.Close();

            Console.WriteLine("Press Enter to quit.");
            Console.ReadLine();
        }
Example #4
0
        /// <summary>
        /// Runs ExecServer in server mode (waiting for connection from ExecServer clients)
        /// </summary>
        /// <param name="entryAssemblyPath">Path to the client assembly in case we need to start another instance of same process.</param>
        /// <param name="executablePath">Path of the executable to run from this ExecServer instance</param>
        private int RunServer(string entryAssemblyPath, string executablePath, int serverInstanceIndex)
        {
            var address = GetEndpointAddress(executablePath, serverInstanceIndex);

            // TODO: The setting of disabling caching should be done per EXE (via config file) instead of global settings for ExecServer
            var useAppDomainCaching = Environment.GetEnvironmentVariable(DisableExecServerAppDomainCaching) != "true";

            // Start WCF pipe for communication with process
            var execServerApp = new ExecServerRemote(entryAssemblyPath, executablePath, true, useAppDomainCaching, serverInstanceIndex == 0);
            var host          = new NpHost(address, null, null);

            host.AddService <IExecServerRemote>(execServerApp);

            try
            {
                host.Open();
            }
            catch (Exception e)
            {
                // Uncomment the following line to see which process got a ExitCodeServerAlreadyInUse
                // File.WriteAllText(Path.Combine(Environment.CurrentDirectory, $"test_ExecServer{Process.GetCurrentProcess().Id}.log"), $"Exit code: {ExitCodeServerAlreadyInUse}\r\n");

                // Silently exit if the server is already running
                return(ExitCodeServerAlreadyInUse);
            }

            Console.WriteLine("Server [{0}] is running", executablePath);

            // Register for shutdown
            execServerApp.ShuttingDown += (sender, args) => host.Close();

            // Wait for the server to shutdown
            execServerApp.Wait();

            return(0);
        }
Example #5
0
        public async Task <ResultStatus> TryExecuteRemote(Command command, BuilderContext builderContext, IExecuteContext executeContext, LocalCommandContext commandContext)
        {
            while (!CanSpawnParallelProcess())
            {
                await Task.Delay(1, command.CancellationToken);
            }

            var address   = "Stride/CompilerApp/PackageBuilderApp/" + Guid.NewGuid();
            var arguments = $"--slave=\"{address}\" --build-path=\"{builderOptions.BuildDirectory}\"";

            using (var debugger = VisualStudioDebugger.GetAttached())
            {
                if (debugger != null)
                {
                    arguments += $" --reattach-debugger={debugger.ProcessId}";
                }
            }

            // Start ServiceWire pipe for communication with process
            var processBuilderRemote = new ProcessBuilderRemote(assemblyContainer, commandContext, command);
            var host = new NpHost(address, null, null, new StrideServiceWireSerializer());

            host.AddService <IProcessBuilderRemote>(processBuilderRemote);

            var startInfo = new ProcessStartInfo
            {
                // Note: try to get exec server if it exists, otherwise use CompilerApp.exe
                FileName               = Path.ChangeExtension(typeof(PackageBuilder).Assembly.Location, ".exe"),
                Arguments              = arguments,
                WorkingDirectory       = Environment.CurrentDirectory,
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            host.Open();

            var output = new List <string>();

            var process = new Process {
                StartInfo = startInfo
            };

            process.Start();
            process.OutputDataReceived += (_, args) => LockProcessAndAddDataToList(process, output, args);
            process.ErrorDataReceived  += (_, args) => LockProcessAndAddDataToList(process, output, args);
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            // Note: we don't want the thread to schedule another job since the CPU core will be in use by the process, so we do a blocking WaitForExit.
            process.WaitForExit();

            host.Close();

            NotifyParallelProcessEnded();

            if (process.ExitCode != 0)
            {
                executeContext.Logger.Error($"Remote command crashed with output:{Environment.NewLine}{string.Join(Environment.NewLine, output)}");
            }

            if (processBuilderRemote.Result != null)
            {
                // Register results back locally
                foreach (var outputObject in processBuilderRemote.Result.OutputObjects)
                {
                    commandContext.RegisterOutput(outputObject.Key, outputObject.Value);
                }

                // Register log messages
                foreach (var logMessage in processBuilderRemote.Result.LogMessages)
                {
                    commandContext.Logger.Log(logMessage);
                }

                // Register tags
                foreach (var tag in processBuilderRemote.Result.TagSymbols)
                {
                    commandContext.AddTag(tag.Key, tag.Value);
                }
            }

            return(command.CancellationToken.IsCancellationRequested ? ResultStatus.Cancelled : (process.ExitCode == 0 ? ResultStatus.Successful : ResultStatus.Failed));
        }
 /// <inheritdoc/>
 public override void Destroy()
 {
     host.Close();
     base.Destroy();
 }
Example #7
0
 public void Dispose()
 {
     _nphost.Close();
     _nphost.Dispose();
     _nphost = null;
 }
Example #8
0
 public void Dispose()
 {
     _nphost.Close();
 }
Example #9
0
 public void Close()
 {
     NpHost?.Close();
 }
Example #10
0
 public void Dispose()
 {
     NpHost?.Close();
 }