public TwoWayResult AcceptChallenge(Guid challengeId) { //get the challenge var match = factory.GetGame().AcceptChallenge(challengeId); //inform the challenger that the challenge was accepted string clientId = factory.GetPlayerPresence().GetClientId(match.Item2); if (!string.IsNullOrWhiteSpace(clientId)) { //Clients[clientId].challengeAccepted(match.Item1); //The client accepted the challenge dynamic call1 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId }; call1.game.challengeAccepted(match.Item1); RemoteExecution.ExecuteOnClient(call1); //Caller.goToGame(match.Item1); //Tell the caller to go to the match dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId }; call2.game.goToGame(match.Item1); return(new TwoWayResult(call2)); } else { //Caller.otherPlayerNotOnline(); dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId }; call.game.otherPlayerNotOnline(); return(call); } }
public void BroadcastExecuteOnClientTest() { ClientCall remoteCall = null; // TODO: Initialize to an appropriate value RemoteExecution.BroadcastExecuteOnClient(remoteCall); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public JsonResult PushVideoFragment() { //Get the audio stream and store it on a local collection MemoryStream ms = new MemoryStream(); Request.Files[0].InputStream.CopyTo(ms); ms.Position = 0; string id = Guid.NewGuid().ToString().Replace("-", ""); audios.Add(id, ms); //store the images locally var frames = new List <string>(); foreach (string k in Request.Form.Keys) { frames.Add(Request.Form[k]); } //send the audio to everyone but me var receivers = RemoteController.Users.Where(u => u != Request.Cookies["videoChatUser"].Value); foreach (var u in receivers) { dynamic call = new ClientCall { CallerId = Request.Cookies["videoChatUser"].Value, ClientId = u }; //since we cannot send the audio, we just send the ID of the audio that we just received call.updateVideoFragment(id, frames, Request.Cookies["videoChatUser"].Value); RemoteExecution.ExecuteOnClient(call, false); } return(Json(new { success = true })); }
/// <summary> /// The override does not send anything but makes a client call /// </summary> public override void ExecuteResult(ControllerContext context) { //make the client call if (string.IsNullOrEmpty(this.Call.ClientId)) { RemoteExecution.BroadcastExecuteOnClient(this.Call); } else { RemoteExecution.ExecuteOnClient(this.Call, false); //wait until the call has been made so the connection is not trunckated int len = (int)(string.Concat("data:", this.Call.ToString(), "\n").Length / 20); while (true) { if (SseHelper.ConnectionsMade.Contains(this.Call.ClientId)) { break; } //wait a few miliseconds Thread.Sleep(len); } //send just success var jsonp = new JavaScriptSerializer().Serialize(new { success = true }); context.HttpContext.Response.ContentType = "application/json"; context.HttpContext.Response.Write(jsonp); } }
public void ExecuteOnClientTest() { ClientCall remoteCall = null; // TODO: Initialize to an appropriate value bool raiseEventOnError = false; // TODO: Initialize to an appropriate value RemoteExecution.ExecuteOnClient(remoteCall, raiseEventOnError); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public static void ReloadUserList() { dynamic reload = new ClientCall { CallerId = string.Empty, ClientId = string.Empty }; reload.getUsers(); RemoteExecution.BroadcastExecuteOnClient(reload); }
public ProcessSharp(System.Diagnostics.Process native, MemoryType type, bool initializeRemoteProcedures = false, Dictionary <string, int> cachedAddresses = null, params object[] procedureConstructorParams) : base(native, type) { RemoteExecution = new RemoteExecution <TExecDesc>(this, initializeRemoteProcedures, cachedAddresses, procedureConstructorParams); }
static void Main(string[] args) { List <string> listIPAddres = new List <string>(); listIPAddres.Add(IPDesktop); //listIPAddres.Add(IPLaptop); foreach (var item in listIPAddres) { var abc = RemoteExecution.ExecuteRemoteCommands(item, " netstat.exe -ano"); } }
public void PlayerReady(Guid matchId, Guid playerId) { var m = factory.GetGame(matchId, true); m.PlayerReady(playerId); string clientId1 = factory.GetPlayerPresence().GetClientId(playerId); string clientId2 = factory.GetPlayerPresence().GetClientId(playerId == m.Player1 ? m.Player2 : m.Player1); //start the match if both are ready if (m.Player1Ready && m.Player2Ready) { dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId1 }; call.game.startMatch(); RemoteExecution.ExecuteOnClient(call); dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId2 }; call2.game.startMatch(); RemoteExecution.ExecuteOnClient(call2); //Clients[string.Format("match_", matchId)].startMatch(); } else { //inform the other player that the player is ready if (RemoteExecution.ClientIsOnLine(clientId2)) { dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId2 }; //Clients[clientId].otherPlayerIsReady(); call.game.otherPlayerIsReady(); RemoteExecution.ExecuteOnClient(call, false); } else //TODO:tell the client that the other player is not online { dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId1 }; call.game.otherPlayerNotOnline(); RemoteExecution.ExecuteOnClient(call); } } }
[InlineData(SIGTERM)] // AppDomain.CurrentDomain.ProcessExit public async Task CancelOnProcessTermination_cancels_on_process_termination(int signo) { const string ChildProcessWaiting = "Waiting for the command to be cancelled"; const int CancelledExitCode = 42; Func <string[], Task <int> > childProgram = (string[] args) => { var command = new Command("the-command"); command.SetHandler(async context => { var cancellationToken = context.GetCancellationToken(); try { context.Console.WriteLine(ChildProcessWaiting); await Task.Delay(int.MaxValue, cancellationToken); context.ExitCode = 1; } catch (OperationCanceledException) { // For Process.Exit handling the event must remain blocked as long as the // command is executed. // We are currently blocking that event because CancellationTokenSource.Cancel // is called from the event handler. // We'll do an async Yield now. This means the Cancel call will return // and we're no longer actively blocking the event. // The event handler is responsible to continue blocking until the command // has finished executing. If it doesn't we won't get the CancelledExitCode. await Task.Yield(); context.ExitCode = CancelledExitCode; } }); return(new CommandLineBuilder(new RootCommand { command }) .CancelOnProcessTermination() .Build() .InvokeAsync("the-command")); }; using RemoteExecution program = RemoteExecutor.Execute(childProgram, psi: new ProcessStartInfo { RedirectStandardOutput = true }); Process process = program.Process; // Wait for the child to be in the command handler. string childState = await process.StandardOutput.ReadLineAsync(); childState.Should().Be(ChildProcessWaiting); // Request termination kill(process.Id, signo).Should().Be(0); // Verify the process terminates timely bool processExited = process.WaitForExit(10000); if (!processExited) { process.Kill(); process.WaitForExit(); } processExited.Should().Be(true); // Verify the process exit code process.ExitCode.Should().Be(CancelledExitCode); }
public void PlayerAttack(Guid matchId, Guid playerId, int row, int col) { var m = factory.GetGame(matchId, true); string clientId = factory.GetPlayerPresence().GetClientId(m.Player1 == playerId ? m.Player2 : m.Player1); var result = m.PlayerAttack(new Position { Row = row, Column = col }, playerId); if (result.Command == Command.GameAction && result.Action == GameAction.ShotMade) { dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId }; call.game.sucessfulAttack(row, col); RemoteExecution.ExecuteOnClient(call); dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId }; call2.game.takeDamage(new Damage { UnitId = result.UnitId, HealthAfterAttack = result.HealthAfterAttack }); RemoteExecution.ExecuteOnClient(call2); //Caller.sucessfulAttack(row, col); //Clients[clientId].takeDamage(new Damage { UnitId = result.UnitId, HealthAfterAttack = result.HealthAfterAttack }); } else if (result.Command == Command.GameAction && result.Action == GameAction.ShotMissed) { dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId }; call.game.attackMissed(row, col); RemoteExecution.ExecuteOnClient(call); dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId }; call2.game.shotMissed(); RemoteExecution.ExecuteOnClient(call2); //Caller.attackMissed(row, col); //Clients[clientId].shotMissed(); } else if (result.Command == Command.EndGame) { dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId }; call.game.endMatch(result.Winner); RemoteExecution.ExecuteOnClient(call); dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId }; call2.game.endMatch(result.Winner); RemoteExecution.ExecuteOnClient(call2); //Clients[string.Format("match_", matchId)].endMatch(result.Winner); } }
public void RemoteExecutionConstructorTest() { RemoteExecution target = new RemoteExecution(); Assert.Inconclusive("TODO: Implement code to verify target"); }
public async Task CancelOnProcessTermination_provides_CancellationToken_that_signals_termination_when_null_timeout_is_specified(int signo) { const string ChildProcessWaiting = "Waiting for the command to be cancelled"; const int CancelledExitCode = 42; Func <string[], Task <int> > childProgram = (string[] args) => { var command = new Command("the-command"); command.SetHandler(async context => { var cancellationToken = context.GetCancellationToken(); try { context.Console.WriteLine(ChildProcessWaiting); await Task.Delay(int.MaxValue, cancellationToken); context.ExitCode = 1; } catch (OperationCanceledException) { // For Process.Exit handling the event must remain blocked as long as the // command is executed. // We are currently blocking that event because CancellationTokenSource.Cancel // is called from the event handler. // We'll do an async Yield now. This means the Cancel call will return // and we're no longer actively blocking the event. // The event handler is responsible to continue blocking until the command // has finished executing. If it doesn't we won't get the CancelledExitCode. await Task.Yield(); // Exit code gets set here - but then execution continues and is let run till code voluntarily returns // hence exit code gets overwritten below context.ExitCode = 123; } // This is an example of bad pattern and reason why we need a timeout on termination processing await Task.Delay(TimeSpan.FromMilliseconds(200)); context.ExitCode = CancelledExitCode; }); return(new CommandLineBuilder(new RootCommand { command }) // Unfortunately we cannot use test parameter here - RemoteExecutor currently doesn't capture the closure .CancelOnProcessTermination(null) .Build() .InvokeAsync("the-command")); }; using RemoteExecution program = RemoteExecutor.Execute(childProgram, psi: new ProcessStartInfo { RedirectStandardOutput = true }); Process process = program.Process; // Wait for the child to be in the command handler. string childState = await process.StandardOutput.ReadLineAsync(); childState.Should().Be(ChildProcessWaiting); // Request termination kill(process.Id, signo).Should().Be(0); // Verify the process terminates timely bool processExited = process.WaitForExit(10000); if (!processExited) { process.Kill(); process.WaitForExit(); } processExited.Should().Be(true); // Verify the process exit code process.ExitCode.Should().Be(CancelledExitCode); }