public NpTests() { _tester = new NetTester(); _nphost = new NpHost(PipeName); _nphost.AddService <INetTester>(_tester); _nphost.Open(); }
public BuildLogViewModel(IViewModelServiceProvider serviceProvider) : base(serviceProvider) { PipeName = $"{BasePipeName}.{Guid.NewGuid()}"; host = new NpHost(PipeName, null, null, new StrideServiceWireSerializer()); host.AddService <IForwardSerializableLogRemote>(this); host.Open(); }
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(); }
public ExecServerRemoteClient(string remoteAddress, RedirectLogger logger) { _client = new NpClient <IExecServerRemote>(new NpEndPoint(remoteAddress)); //Create callback channel this.CallbackAddress = remoteAddress + "_callback"; _callbackChannel = new NpHost(this.CallbackAddress, null, null); _callbackChannel.AddService <IServerLogger>(logger); }
public PackageBuildMonitorRemote(IBuildMonitorCallback buildMonitorCallback, string logPipeUrl) { this.buildMonitorCallback = buildMonitorCallback; this.logPipeUrl = logPipeUrl; // Listen to pipe with this as listener var host = new NpHost(this.logPipeUrl, null, null, new StrideServiceWireSerializer()); host.AddService <IForwardSerializableLogRemote>(this); host.Open(); }
private void Initialize() { _contractType = _contractTypeDef.ToType(); _implementationType = _implementationTypeDef.ToType(); if (!_implementationType.GetInterfaces().Contains(_contractType)) { throw new TypeAccessException("Contract and implementation mismatch."); } _agentService = new AgentService(this, _endPoint); _agentServiceHost = new NpHost(string.Format("dpp-{0}", _sessionId)); _agentServiceHost.AddService <IAgentService>(_agentService); _agentServiceHost.Open(); }
public void Start(string workingDirectory, Process debuggerProcess, LoggerResult logger) { var gameHostAssembly = typeof(GameDebuggerTarget).Assembly.Location; using (var debugger = debuggerProcess != null ? VisualStudioDebugger.GetByProcess(debuggerProcess.Id) : null) { var address = "Stride/Debugger/" + Guid.NewGuid(); var arguments = $"--host=\"{address}\""; // Child process should wait for a debugger to be attached if (debugger != null) { arguments += " --wait-debugger-attach"; } var startInfo = new ProcessStartInfo { FileName = gameHostAssembly, Arguments = arguments, WorkingDirectory = workingDirectory, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; // Start ServiceWire pipe var gameDebuggerHost = new GameDebuggerHost(logger); ServiceHost = new NpHost(address, null, null); ServiceHost.AddService <IGameDebuggerHost>(gameDebuggerHost); ServiceHost.Open(); var process = new Process { StartInfo = startInfo }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); // Make sure proces will be killed if our process is finished unexpectedly attachedChildProcessJob = new AttachedChildProcessJob(process); // Attach debugger debugger?.AttachToProcess(process.Id); GameHost = gameDebuggerHost; } }
public void RunHost() { _tester = new Mock <INetTester>(); _tester .Setup(o => o.Min(It.IsAny <int>(), It.IsAny <int>())) .Returns((int a, int b) => Math.Min(a, b)); _tester .Setup(o => o.Range(It.IsAny <int>(), It.IsAny <int>())) .Returns((int a, int b) => Enumerable.Range(a, b).ToDictionary(key => key, el => el)); _nphost = new NpHost(PipeName); _nphost.AddService <INetTester>(_tester.Object); _nphost.Open(); }
public void ResponseWithOutParameterNewtonsoftSerializerTest() { using (var nphost = new NpHost(PipeName + "JsonResponseOut", serializer: new NewtonsoftSerializer())) { nphost.AddService <INetTester>(_tester); nphost.Open(); using (var clientProxy = new NpClient <INetTester>(new NpEndPoint(PipeName + "JsonResponseOut"), new NewtonsoftSerializer())) { int quantity = 0; var result = clientProxy.Proxy.Get(Guid.NewGuid(), "SomeLabel", 45.65, out quantity); Assert.Equal(44, quantity); Assert.NotEqual(default(TestResponse), result); Assert.Equal("MyLabel", result.Label); } } }
public void SimpleProtobufSerializerTest() { using (var nphost = new NpHost(PipeName + "Proto", serializer: new ProtobufSerializer())) { nphost.AddService <INetTester>(_tester); nphost.Open(); var rnd = new Random(); var a = rnd.Next(0, 100); var b = rnd.Next(0, 100); using (var clientProxy = new NpClient <INetTester>(new NpEndPoint(PipeName + "Proto"), new ProtobufSerializer())) { var result = clientProxy.Proxy.Min(a, b); Assert.Equal(Math.Min(a, b), result); } } }
public IPCNamedPipeServer(string _pipeName, IMessageService _service = null, Logger _logger = null, ServiceWire.Stats _stats = null) { if (string.IsNullOrEmpty(_pipeName)) { throw new ArgumentException("PipeName is null or empty."); } PipeName = _pipeName; Service = _service != null ? _service : new IPCService(); Service.OnMessageReceived += messageReceived_relay; Logger = _logger != null ? _logger : new Logger(logLevel: ServiceWire.LogLevel.Warn); Stats = _stats != null ? _stats : new ServiceWire.Stats(); NpHost = new NpHost(PipeName, Logger, Stats); NpHost.AddService(Service); NpHost.Open(); }
#pragma warning disable IDE0060 // Remove unused parameter static void Main(string[] args) #pragma warning restore IDE0060 // Remove unused parameter { var logger = new Logger(logLevel: LogLevel.Debug); var stats = new Stats(); string pipename = TransformationRunFactory.TransformationRunFactoryService; int timeout = 60; foreach (string arg in args) { if (arg.StartsWith(nameof(pipename), StringComparison.OrdinalIgnoreCase)) { pipename = arg.Split(':')[1]; } else if (arg.StartsWith(nameof(timeout), StringComparison.OrdinalIgnoreCase) && int.TryParse(arg.Split(':')[1], out int _timeout)) { timeout = _timeout; } } #pragma warning disable IDE0063 // Use simple 'using' statement using (TransformationRunFactoryService service = new TransformationRunFactoryService(new Uri($"ipc://{pipename}"), timeout)) #pragma warning restore IDE0063 // Use simple 'using' statement using (NpHost host = new NpHost(pipename, logger, stats)) { host.AddService <ITransformationRunFactoryService>(service); host.Open(); Console.Out.WriteLine($"Startup: {DateTime.Now}"); while (service.IsRunning) { Thread.Sleep(10); } Console.Out.WriteLine($"Shutdown: {DateTime.Now}"); } }
public static void Main(string[] args) { string pipeAddress = string.Empty; var p = new OptionSet { { "pipe=", "Pipe for communication", v => pipeAddress = v }, }; p.Parse(args); var host = new NpHost(pipeAddress + "/IStrideCommands"); host.AddService <IStrideCommands>(new StrideCommands()); host.Open(); // Forbid process to terminate (unless ctrl+c) while (true) { Console.Read(); Thread.Sleep(100); } }
public void MainLoop(IGameDebuggerHost gameDebuggerHost) { host = gameDebuggerHost; string callbackChannelEndpoint = "Stride/Debugger/GameDebuggerTarget/CallbackChannel"; using (var callbackHost = new NpHost(callbackChannelEndpoint, null, null)) { callbackHost.AddService <IGameDebuggerTarget>(this); host.RegisterTarget(callbackChannelEndpoint); Log.MessageLogged += Log_MessageLogged; // Log suppressed exceptions in scripts ScriptSystem.Log.MessageLogged += Log_MessageLogged; Scheduler.Log.MessageLogged += Log_MessageLogged; Log.Info("Starting debugging session"); while (!requestedExit) { Thread.Sleep(10); } } }
/// <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); }
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)); }
public void OneTimeSetUp() { HostServer = new NpHost(TransformationRunFactory.TransformationRunFactoryService, serializer: new BinarySerializationProvider()); HostServer.AddService <ITransformationRunFactoryService>(new TransformationRunFactoryService(new Uri($"ipc://{TransformationRunFactory.TransformationRunFactoryService}"))); HostServer.Open(); }