public void AggregatorMachine_Resolve_from_Inactive_Error() { var machine = new AggregatorMachine(); IEvent resolveEvent = new ResolveEvent { Data = "Hello world?" }; Assert.Throws <Exception>(() => machine.MoveNext(resolveEvent)); }
public async Task <IOperationToken> ResolveAsync(string instanceName, string serviceType, string domain, uint interfaceIndex = 0, object context = null) { await CheckConnectionAsync(); var op = new ResolveOperation(instanceName, serviceType, domain, interfaceIndex, context); op.ResolveEvent += (s, e) => ResolveEvent?.Invoke(s, e); await _connection.AddAndExecuteSubordinate(op); return(op.Token); }
internal override void ProcessReply(CallbackMessage message, bool moreComing) { if (message is ResolveCallbackMessage rcm) { IEnumerable <DnssdTxtRecord> records = null; if (rcm.Payload.TxtRecord != null) { var trb = new TxtRecordBuilder(); trb.Parse(rcm.Payload.TxtRecord, 0); records = trb.TxtRecords; } ResolveEvent?.Invoke(Token, new ResolveEventArgs(rcm.Payload.FullName, rcm.Payload.HostName, rcm.Payload.Port, rcm.Payload.InterfaceIndex, records, moreComing)); } }
public void AggregatorMachine_Resolve_Moves_From_Resolved_Error() { var machine = new AggregatorMachine(); IEvent onHandEvent = new OnHandEvent { Data = "Hello " }; IEvent shipmentEvent = new ShipmentEvent { Data = "world!" }; IEvent resolveEvent = new ResolveEvent { Data = "Hello world?" }; machine.MoveNext(onHandEvent); machine.MoveNext(shipmentEvent); Assert.Throws <Exception>(() => machine.MoveNext(resolveEvent)); }
protected virtual void PlayEvent(GameEvent[] events, int index) { if (index == events.Length) { SetupNextTurn(); return; } UnityAction Next = () => PlayEvent(events, index + 1); GameEvent e = events[index]; if (history[currentHistoryIndex].IsAfter(e.priority)) { history.Add(SerializeState(turnNumber, e.priority)); currentHistoryIndex++; } boardController.DiffBattery(e.primaryBatteryCost, e.secondaryBatteryCost); if (e is ResolveEvent) { ResolveEvent re = (ResolveEvent)e; uiController.HighlightCommands(re.priority); Counter animationsToPlay = new Counter(re.GetNumResolutions()); UnityAction callback = () => { animationsToPlay.Decrement(); if (animationsToPlay.Get() <= 0) { Next(); } }; re.robotIdToSpawn.ForEach(p => { RobotController primaryRobot = robotControllers[p.Item1]; (primaryRobot.isOpponent ? boardController.opponentDock : boardController.myDock).RemoveFromBelt(primaryRobot.transform.localPosition); primaryRobot.transform.parent = boardController.transform; boardController.PlaceRobot(primaryRobot, p.Item2.Item1, p.Item2.Item2); primaryRobot.displaySpawn(callback); }); re.robotIdToMove.ForEach(p => { RobotController primaryRobot = robotControllers[p.Item1]; primaryRobot.displayMove(ToVector(p.Item2), boardController, callback); }); re.robotIdToHealth.ForEach(t => { RobotController primaryRobot = robotControllers[t.Item1]; primaryRobot.displayDamage(t.Item2, callback); }); if (re.myBatteryHit) { boardController.GetMyBattery().DisplayDamage(callback); } if (re.opponentBatteryHit) { boardController.GetOpponentBattery().DisplayDamage(callback); } re.missedAttacks.ConvertAll(ToVector).ForEach(v => boardController.DisplayMiss(v, callback)); re.robotIdsBlocked.ForEach(r => robotControllers[r].DisplayBlocked(callback)); } else if (e is SpawnEvent) { robotControllers[((SpawnEvent)e).robotId].displaySpawnRequest(Next); } else if (e is MoveEvent) { robotControllers[((MoveEvent)e).robotId].displayMoveRequest(ToVector(((MoveEvent)e).destinationPos), Next); } else if (e is AttackEvent) { ((AttackEvent)e).locs.ConvertAll(ToVector).ForEach(v => robotControllers[((AttackEvent)e).robotId].displayAttack(v, Next)); } else if (e is DeathEvent) { robotControllers[((DeathEvent)e).robotId].displayDeath(((DeathEvent)e).returnHealth, (RobotController primaryRobot) => { boardController.UnplaceRobot(primaryRobot); DockController dock = !primaryRobot.isOpponent ? boardController.myDock : boardController.opponentDock; primaryRobot.transform.parent = dock.transform; primaryRobot.transform.localPosition = dock.PlaceInBelt(); Next(); }); } else if (e is EndEvent) { EndEvent evt = (EndEvent)e; Counter animationsToPlay = new Counter((evt.primaryLost ? 1 : 0) + (evt.secondaryLost ? 1 : 0)); UnityAction callback = () => { animationsToPlay.Decrement(); if (animationsToPlay.Get() <= 0) { uiController.robotButtonContainer.SetButtons(false); uiController.statsInterface.Initialize(evt); gameClient.SendEndGameRequest(); } }; if (evt.primaryLost) { boardController.GetMyBattery().DisplayEnd(callback); } if (evt.secondaryLost) { boardController.GetOpponentBattery().DisplayEnd(callback); } } else { PlayEvent(events, index + 1); } }