public void Initialize(IBus bus) { bus.Subscribe <StartMessage>("simpleSaga", startMessage => { Console.WriteLine("StartMessage: {0}", startMessage.Text); var firstProcessedMessage = startMessage.Text + " - initial process "; var request = new TestRequestMessage { Text = firstProcessedMessage }; using (var publishChannel = bus.OpenPublishChannel()) { publishChannel.Request <TestRequestMessage, TestResponseMessage>(request, response => { Console.WriteLine("TestResponseMessage: {0}", response.Text); var secondProcessedMessage = response.Text + " - final process "; var endMessage = new EndMessage { Text = secondProcessedMessage }; using (var publishChannel2 = bus.OpenPublishChannel()) { publishChannel2.Publish(endMessage); } }); } }); }
public void OnNetworkEndMessage(EndMessage m) { if (this.gameRunning) { this.victory = m.victory; } }
public void EndingANotStartedGame_ThrowsException_Test() { // Arrange var quest = QuestFactory.CreateStored(out var gameStore, out var gameId); var endMsg = EndMessage.Create(1); // Act & Assert Assert.Throws <InvalidActionException>(() => quest.AddMessage(gameId, endMsg)); }
public void AddTwoMessagesWithGapInSequence_ThrowsGameOutOfSyncException_Test() { // Arrange var startMsg = StartMessage.Create(1); var endMsg = EndMessage.Create(3); // Act & Assert _quest.AddMessage(_gameId, startMsg); Assert.Throws <GameOutOfSyncException>(() => _quest.AddMessage(_gameId, endMsg)); }
public void Can_call_publish_inside_a_subscribe_handler() { var bus = RabbitHutch.CreateBus("host=localhost"); // setup the Saga Console.WriteLine("Setting up the Saga"); bus.Subscribe <StartMessage>("simpleSaga", startMessage => { Console.WriteLine("Saga got StartMessage: {0}", startMessage.Text); var firstProcessedMessage = startMessage.Text + " - initial process "; var request = new TestRequestMessage { Text = firstProcessedMessage }; bus.Request <TestRequestMessage, TestResponseMessage>(request, response => { Console.WriteLine("Saga got Response: {0}", response.Text); var secondProcessedMessage = response.Text + " - final process "; var endMessage = new EndMessage { Text = secondProcessedMessage }; bus.Publish(endMessage); }); }); // setup the RPC endpoint Console.WriteLine("Setting up the RPC endpoint"); bus.Respond <TestRequestMessage, TestResponseMessage>(request => { Console.WriteLine("RPC got Request: {0}", request.Text); return(new TestResponseMessage { Text = request.Text + " Responded! " }); }); // setup the final subscription Console.WriteLine("Setting up the final subscription"); var autoResetEvent = new AutoResetEvent(false); bus.Subscribe <EndMessage>("inline_saga_spike", endMessage => { Console.WriteLine("Test got EndMessage: {0}", endMessage.Text); autoResetEvent.Set(); }); // now kick it off Console.WriteLine("Test is publishing StartMessage"); bus.Publish(new StartMessage { Text = "Hello Saga!! " }); // give the message time to run through the process autoResetEvent.WaitOne(1000); }
public void Can_call_publish_inside_a_subscribe_handler() { var bus = RabbitHutch.CreateBus("host=localhost"); // setup the Saga Console.WriteLine("Setting up the Saga"); bus.Subscribe<StartMessage>("simpleSaga", startMessage => { Console.WriteLine("Saga got StartMessage: {0}", startMessage.Text); var firstProcessedMessage = startMessage.Text + " - initial process "; var request = new TestRequestMessage { Text = firstProcessedMessage }; using (var publishChannel = bus.OpenPublishChannel()) { publishChannel.Request<TestRequestMessage, TestResponseMessage>(request, response => { Console.WriteLine("Saga got Response: {0}", response.Text); var secondProcessedMessage = response.Text + " - final process "; var endMessage = new EndMessage {Text = secondProcessedMessage}; using (var publishChannel2 = bus.OpenPublishChannel()) { publishChannel2.Publish(endMessage); } }); } }); // setup the RPC endpoint Console.WriteLine("Setting up the RPC endpoint"); bus.Respond<TestRequestMessage, TestResponseMessage>(request => { Console.WriteLine("RPC got Request: {0}", request.Text); return new TestResponseMessage {Text = request.Text + " Responded! "}; }); // setup the final subscription Console.WriteLine("Setting up the final subscription"); var autoResetEvent = new AutoResetEvent(false); bus.Subscribe<EndMessage>("inline_saga_spike", endMessage => { Console.WriteLine("Test got EndMessage: {0}", endMessage.Text); autoResetEvent.Set(); }); // now kick it off Console.WriteLine("Test is publishing StartMessage"); using (var publishChannel = bus.OpenPublishChannel()) { publishChannel.Publish(new StartMessage { Text = "Hello Saga!! " }); } // give the message time to run through the process autoResetEvent.WaitOne(1000); }
public void Initialize(IBus bus) { bus.Subscribe<StartMessage>("id", startMessage => { var request = new TestRequestMessage {Text = startMessage.Text}; bus.Request<TestRequestMessage, TestResponseMessage>(request, response => { var endMessage = new EndMessage {Text = response.Text}; bus.Publish(endMessage); }); }); }
public void GetSpecificTypeFromBaseClass_ResultsInSpecificClassName_Test() { // Arrange var gameMsg = new EndMessage() as GameMessage; var expectedType = typeof(EndMessage).Name; // Act var actualType = gameMsg.Type; // Assert Assert.Equal(expectedType, actualType); }
public void EndingGameTwice_ThrowsException_Test() { // Arrange var quest = QuestFactory.CreateStored(out var gameStore, out var gameId); var startMsg = StartMessage.Create(1); var endMsg = EndMessage.Create(2); var secondEndMsg = EndMessage.Create(3); // Act & Assert quest.AddMessage(gameId, startMsg); quest.AddMessage(gameId, endMsg); Assert.Throws <InvalidActionException>(() => quest.AddMessage(gameId, secondEndMsg)); }
public override AMove CreateNextMove(Game.Game game, Dictionary <string, string> dictVariables) { var result = Validate(game.World, dictVariables); var withoutFunctionFormula = CreateFormulaWithoutFunctions(game, dictVariables); if (game.Guess) { if (withoutFunctionFormula != null) { var endMessage = new EndMessage(game, this, "You win:\n" + withoutFunctionFormula.ReformatFormula(dictVariables) + "\n is true in this world", true); if (result.Value == EValidationResult.False) { endMessage = new EndMessage(game, this, "You lose:\n" + withoutFunctionFormula.ReformatFormula(dictVariables) + "\n is false, not true, in this world", false); } var infoFunctionFormula = new InfoMessage(game, withoutFunctionFormula, $"So you believe that \n{withoutFunctionFormula.ReformatFormula(dictVariables)}\n is true", endMessage); return(new InfoMessage(game, this, $"So you believe that \n{ReformatFormula(dictVariables)}\n is true", infoFunctionFormula)); } else { var endMessage = new EndMessage(game, this, "You win:\n" + ReformatFormula(dictVariables) + "\n is true in this world", true); if (result.Value == EValidationResult.False) { endMessage = new EndMessage(game, this, "You lose:\n" + ReformatFormula(dictVariables) + "\n is false, not true, in this world", false); } return(new InfoMessage(game, this, $"So you believe that \n{ReformatFormula(dictVariables)}\n is true", endMessage)); } } else { if (withoutFunctionFormula != null) { var endMessage = new EndMessage(game, this, "You win:\n" + withoutFunctionFormula.ReformatFormula(dictVariables) + "\n is false in this world", true); if (result.Value == EValidationResult.True) { endMessage = new EndMessage(game, this, "You lose:\n" + withoutFunctionFormula.ReformatFormula(dictVariables) + "\n is true, not false, in this world", false); } var infoFunctionFormula = new InfoMessage(game, withoutFunctionFormula, $"So you believe that \n{withoutFunctionFormula.ReformatFormula(dictVariables)}\n is false", endMessage); return(new InfoMessage(game, this, $"So you believe that \n{ReformatFormula(dictVariables)}\n is false", infoFunctionFormula)); } else { var endMessage = new EndMessage(game, this, "You win:\n" + ReformatFormula(dictVariables) + "\n is false in this world", true); if (result.Value == EValidationResult.True) { endMessage = new EndMessage(game, this, "You lose:\n" + ReformatFormula(dictVariables) + "\n is true, not false, in this world", false); } return(new InfoMessage(game, this, $"So you believe that \n{ReformatFormula(dictVariables)}\n is false", endMessage)); } } }
public void AddStartAndEndMessagesWithCorrectSequence_ResultsInEndedGame_Test() { // Arrange var startMsg = StartMessage.Create(1); var endMsg = EndMessage.Create(2); // Act _quest.AddMessage(_gameId, startMsg); var game = _quest.AddMessage(_gameId, endMsg); // Assert Assert.NotNull(game.Score.Begin); Assert.NotNull(game.Score.End); }
public void EndingGame_ThenUndoIt_RemovesTheEndTimestamp_Test() { // Arrange var quest = QuestFactory.CreateStored(out var gameStore, out var gameId); var startMsg = StartMessage.Create(1); var endMsg = EndMessage.Create(2); // Act quest.AddMessage(gameId, startMsg); quest.AddMessage(gameId, endMsg); var game = quest.Undo(gameId); // Assert Assert.Null(game.Score.End); }
public void EndingAStartedGame_EndsItByAddingTimestamp_Test() { // Arrange var quest = QuestFactory.CreateStored(out var gameStore, out var gameId); var startMsg = StartMessage.Create(1); var endMsg = EndMessage.Create(2); // Act quest.AddMessage(gameId, startMsg); var game = quest.AddMessage(gameId, endMsg); // Assert Assert.NotNull(game.Score.End); Assert.Equal(endMsg.Timestamp, game.Score.End); }
// Event handler for if the Enter Name button is clicked private void nameBox_Enter(object sender, EventArgs e) { // Retrieves and resets the name name = nameBox.Text; nameBox.Text = ""; nameBox.Visible = false; nameMessage.Visible = false; EndMessage.Visible = true; Scores.Visible = true; EndMessage.Focus(); if (name != "") { addToDatabase(); }// end if }
public void Initialize(IBus bus) { bus.Subscribe <StartMessage>("id", startMessage => { var request = new TestRequestMessage { Text = startMessage.Text }; bus.Request <TestRequestMessage, TestResponseMessage>(request, response => { var endMessage = new EndMessage { Text = response.Text }; bus.Publish(endMessage); }); }); }
public void Initialize(IBus bus) { bus.Subscribe<StartMessage>("simpleSaga", startMessage => { Console.WriteLine("StartMessage: {0}", startMessage.Text); var firstProcessedMessage = startMessage.Text + " - initial process "; var request = new TestRequestMessage { Text = firstProcessedMessage }; bus.Request<TestRequestMessage, TestResponseMessage>(request, response => { Console.WriteLine("TestResponseMessage: {0}", response.Text); var secondProcessedMessage = response.Text + " - final process "; var endMessage = new EndMessage { Text = secondProcessedMessage }; bus.Publish(endMessage); }); }); }
/// <summary> /// ゲーム終了か通知 /// Server2Client /// </summary> /// <param name="connectionId"></param> /// <param name="message"></param> /// <returns></returns> public Task SendEndMessageAsync(string connectionId, EndMessage message) { var task = new Task(() => { if (string.IsNullOrEmpty(connectionId)) { return; } SingleProcessMessageTransceiver client; if (_connectedClientTable.TryGetValue(connectionId, out client)) { client.ReceivedEndMessage?.Invoke(this, new ReceivedEndMessageArgs(message)); } }); task.RunSynchronously(); return(task); }
private void Attack() { if (pos.y > status.S1 && pos.y < status.E1) { Debug.Log("Attack!"); Enemy.tag = "Untagged"; Destroy(Enemy); Enemies = GameObject.FindGameObjectsWithTag("Enemy"); Hit.SetActive(true); } else { Debug.Log("Damage!"); Hp -= 1; if (Hp == 0) { EndMessage.SetActive(true); } } var Y = pos.y; }
public void SendEndMessageAsync(IServerMessageTransceiver server, IClientMessageTransceiver client) { string connectionId = null; server.ReceivedJoinRequest += (_, args) => { connectionId = args.ConnectionId; }; EndMessage msg = EndMessage.NotEnd; client.ReceivedEndMessage += (_, args) => { msg = args.EndMessage; }; client.SendJoinRequestAsync().Wait(); server.SendEndMessageAsync(connectionId, EndMessage.EndGame).Wait(); Assert.Equal(EndMessage.EndGame, msg); }
public void Initialize(IBus bus) { bus.Subscribe <StartMessage>("id", startMessage => { var request = new TestRequestMessage { Text = startMessage.Text }; using (var publishChannel = bus.OpenPublishChannel()) { publishChannel.Request <TestRequestMessage, TestResponseMessage>(request, response => { var endMessage = new EndMessage { Text = response.Text }; using (var publishChannel2 = bus.OpenPublishChannel()) { publishChannel2.Publish(endMessage); } }); } }); }
public static async Task <string> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { // Deserialize the body of the request string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); InputMessage message = JsonConvert.DeserializeObject <InputMessage>(requestBody); // Convert to the correct message var result = new EndMessage() { id = message.id, source = message.source, date = message.purchasedOn, customerId = message.userId, description = message.description, amount = message.amount }; // Return the result as a serialized string return(JsonConvert.SerializeObject(result)); }
public ReceivedEndMessageArgs(EndMessage message) { EndMessage = message; }
protected void ExecuteTool() { try { if ((((ushort)GetKeyState(0x91)) & 0xffff) != 0) { Debugger.Break(); } if (skip) { return; } if (StartMessage.Is()) { Messages.Enqueue(new BuildMessage(StartMessage)); } Guid iid = Guid.NewGuid(); string pipeName = @"\pipe\ptk_{0}_{1}".format(Process.GetCurrentProcess().Id, Index); Result = true; using (var server = new RpcServerApi(iid)) { string currentProjectName = string.Empty; //Allow up to 5 connections over named pipes server.AddProtocol(RpcProtseq.ncacn_np, pipeName, 5); //Authenticate via WinNT // server.AddAuthentication(RpcAuthentication.RPC_C_AUTHN_WINNT); //Start receiving calls server.StartListening(); //When a call comes, do the following: server.OnExecute += (client, arg) => { // deserialize the message object and replay thru this logger. var message = BuildMessage.DeserializeFromString(arg.ToUtf8String()); // var message = JsonSerializer.DeserializeFromString<BuildMessage>(arg.ToUtf8String()); if (!filters.Any(each => each.IsMatch(message.Message))) { Messages.Enqueue(message); } if (cancellationTokenSource.IsCancellationRequested) { return(new byte[1] { 0x01 }); } return(new byte[0]); }; foreach (var project in projectFiles) { if (cancellationTokenSource.IsCancellationRequested) { Result = false; return; } currentProjectName = project; if (ProjectStartMessage.Is()) { Messages.Enqueue(new BuildMessage(ProjectStartMessage)); } try { // no logo, thanks. var parameters = " /nologo"; // add properties lines. if (!Properties.IsNullOrEmpty()) { parameters = parameters + " /p:" + Properties.Select(each => each.ItemSpec).Aggregate((c, e) => c + ";" + e); } parameters = parameters + @" /noconsolelogger ""/logger:ClrPlus.Scripting.MsBuild.Building.Logger,{0};{1};{2}"" ""{3}""".format(Assembly.GetExecutingAssembly().Location, pipeName, iid, project); if ((((ushort)GetKeyState(0x91)) & 0xffff) != 0) { Debugger.Break(); } var proc = AsyncProcess.Start( new ProcessStartInfo(MSBuildUtility.MsbuildExe.Path, parameters) { WindowStyle = ProcessWindowStyle.Normal , }, _environment); while (!proc.WaitForExit(20)) { if (cancellationTokenSource.IsCancellationRequested) { proc.Kill(); } } // StdErr = proc.StandardError.Where(each => each.Is()).Select(each => (ITaskItem)new TaskItem(each)).ToArray(); // StdOut = proc.StandardOutput.Where(each => each.Is()).Select(each => (ITaskItem)new TaskItem(each)).ToArray(); if (proc.ExitCode != 0) { Result = false; return; } ; } catch (Exception e) { Messages.Enqueue(new BuildMessage("{0},{1},{2}".format(e.GetType().Name, e.Message, e.StackTrace)) { EventType = "BuildError", }); Result = false; return; } if (ProjectEndMessage.Is()) { Messages.Enqueue(new BuildMessage(ProjectEndMessage)); } } } if (EndMessage.Is()) { Messages.Enqueue(new BuildMessage(EndMessage)); } } catch (Exception e) { Messages.Enqueue(new BuildMessage("{0},{1},{2}".format(e.GetType().Name, e.Message, e.StackTrace)) { EventType = "BuildError", }); } finally { Completed.Set(); } }
private void HandleEndMessage(EndMessage msg) { Console.WriteLine("End of count"); Console.WriteLine(Environment.NewLine); _are.Set(); }
public void HandleEndMessage(EndMessage endMessage) { _dataManager.End(); }