public IDisposable BindOpenCommand() { _model.OpenCommand = ReactiveCommand.Create( () => Unit.Default, null, RxApp.MainThreadScheduler); return(_model.OpenCommand .SubscribeWithLog(_ => { OpenTabIntent intent = null; if (_model.SelectedWorkspace is CommanderWorkspaceModel workspace) { // if server selected as a target pass it to new tab var server = workspace.CommandEditor?.SelectedServerInfo; if (server != null) { intent = new OpenTabIntent(server, ""); } // if database selected as a target pass it to new tab var database = workspace.CommandEditor?.SelectedDatabaseInfo; if (database != null) { intent = new OpenTabIntent(database, ""); } } _broadcastService.Broadcast(intent ?? new OpenTabIntent()); })); }
public void Handle(IGameCommand command) { var startGameCommand = command as StartGameCommand; var alreadyPlayingOnBoard = boardManager.FindByConnectionId(startGameCommand.ConnectionId); if (alreadyPlayingOnBoard != null) { broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} already playing on board {alreadyPlayingOnBoard.Name}"); return; } var board = boardManager.Find(startGameCommand.BoardName); if (board == null) { board = StartNewBoard(startGameCommand.BoardName); } if (board.IsAlreadyJoined(startGameCommand.ConnectionId)) { broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} already playing on board {board.Name}"); return; } board.Join(new Player(startGameCommand.PlayerName, startGameCommand.ConnectionId)); broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} joined board {board.Name}"); }
public void Handle(IGameCommand command) { var board = boardManager.FindByConnectionId(command.ConnectionId); if (board == null) { broadcastService.Broadcast(command.ConnectionId, "No active games!"); return; } var shootCommand = command as ShootCommand; var player = board.FindPlayer(command.ConnectionId); var hitObject = board.ObjectAt(shootCommand.X, shootCommand.Y); if (hitObject == null) { broadcastService.Broadcast(command.ConnectionId, $"BOOM {player.Name} {player.Score}"); return; } board.RemoveGameObject(hitObject); if (board.GameObjects.Count < 1) { broadcastService.Broadcast(board, $"Oh no, they are respawning. Now there will be 2 zombies!"); boardActions.ScheduleNewZombie(board); boardActions.ScheduleNewZombie(board, 1000.Random(5000)); } player.Score += 1; broadcastService.Broadcast(board, $"BOOM {player.Name} {player.Score} {hitObject.Name}"); }
public IDisposable BindExecuteCommand() { var targetObservable = _model.WhenAnyValue(m => m.IsServerTargetSelected) .Merge(_model.WhenAnyValue(m => m.IsDatabaseTargetSelected)); var commandObservable = _model.WhenAnyValue(m => m.CommandText) .Select(string.IsNullOrWhiteSpace); var executableObservable = targetObservable.Merge(commandObservable) .SelectSeq(_ => { if (_model.IsServerTargetSelected || _model.IsDatabaseTargetSelected) { return(_commandParser.Parse(_model.CommandText) .Select(batchInfo => batchInfo.CommandInfos.Length > 0 && batchInfo.IsValid)); } return(Observable.Return(false)); }) .ObserveOn(RxApp.MainThreadScheduler); _model.ExecuteCommand = ReactiveCommand.CreateFromObservable <string, RedisResultInfo[]>( Execute, executableObservable, RxApp.MainThreadScheduler); return(_model.ExecuteCommand .SubscribeWithLog(results => { _broadcastService.Broadcast(new ViewResultsIntent(results)); _broadcastService.Broadcast(new ViewStructIntent(null)); })); }
public void Broadcast(string label, TrustedBroadcastRequest broadcast) { if (broadcast == null) { throw new ArgumentNullException(nameof(broadcast)); } var address = broadcast.PreviousScriptPubKey.GetDestinationAddress(RPCClient.Network); if (address == null) { throw new NotSupportedException("ScriptPubKey to track not supported"); } if (TrackPreviousScriptPubKey) { RPCClient.ImportAddress(address, label + " (PreviousScriptPubKey)", false); } var height = RPCClient.GetBlockCount(); var record = new Record(); record.Label = label; //3 days expiration record.Expiration = height + (int)(TimeSpan.FromDays(3).Ticks / Network.Main.Consensus.PowTargetSpacing.Ticks); record.Request = broadcast; AddBroadcast(record); if (height < broadcast.BroadcastAt.Height) { return; } _Broadcaster.Broadcast(record.Label, broadcast.Transaction); }
public async Task Start() { await Send <ChatController>(p => p.Chat(null), new { ClientId = "Server", Text = "Willkommen.", YourId = ConnectionId }); await _broadcastService.Broadcast <ChatController>(p => p.Chat(null), new ChatResponse() { ClientId = ConnectionId, Text = "I joined" }); await Run(); }
public void Handle(IGameCommand command) { var board = boardManager.FindByConnectionId(command.ConnectionId); if (board == null) { broadcastService.Broadcast(command.ConnectionId, "No active game"); return; } board.RemovePlayer(command.ConnectionId); broadcastService.Broadcast(command.ConnectionId, $"You have left game: {board.Name}"); }
public void Handle(IGameCommand command) { var board = boardManager.FindByConnectionId(command.ConnectionId); if (board == null) { broadcastService.Broadcast(command.ConnectionId, "No active game"); return; } broadcastService.Broadcast(command.ConnectionId, "All player stats:"); foreach (var p in board.Players) { var isMe = p.ConnectionId == command.ConnectionId ? " << you" : ""; broadcastService.Broadcast(command.ConnectionId, $"Player ({p.ConnectionId}): {p.Name}, Score: {p.Score}{isMe}"); } }
public async Task Chat(ChatRequest request) { await _broadcastService.Broadcast <ChatController>(p => p.Chat(null), new ChatResponse() { ClientId = _connectionService.ConnectionId, Text = request.Text }); }
private void LikeCurrentTrack(Guid queuedTrackId, string user) { var foundTrack = musicPlayer.CurrentlyPlayingTrack; if (foundTrack == null || foundTrack.Id != queuedTrackId) { return; } if (foundTrack.Likes.Any(v => v.ByUser == user)) { return; } if (foundTrack.User == user) { return; //Cant like your own track. } foundTrack.Likes = foundTrack.Likes.ToList(); foundTrack.Likes.Add(new Like { ByUser = user }); queuedTrackDataService.Update(foundTrack); logger.Debug("{0} liked track {1}", user, foundTrack.ToLoggerFriendlyTrackName()); broadcastService.Broadcast(foundTrack); callbackClient.PlayingTrackChanged(foundTrack); }
private async Task <String> Broadcast(T tweet) { if (tweet.ShouldBroadcast()) { return(await broadcastService.Broadcast(tweet.ConvertToMessage())); } return("Should not broadcast"); }
public static Task Broadcast <T>(this IBroadcastService service, T args) { if (service == null) { throw new ArgumentNullException(nameof(service)); } return(service.Broadcast(typeof(T), args)); }
public void ScheduleNewZombieTask(IGameBoard board) { zombieNum++; var localZombie = zombieNum; broadcastService.Broadcast(board, $"Night walker ({localZombie}) will spawn in 10 seconds"); Thread.Sleep(5000); broadcastService.Broadcast(board, $"Night walker ({localZombie}) will spawn in 5 seconds"); Thread.Sleep(3000); broadcastService.Broadcast(board, $"Night walker ({localZombie}) will spawn in 3 seconds"); Thread.Sleep(1000); broadcastService.Broadcast(board, $"Night walker ({localZombie}) will spawn in 2 seconds"); Thread.Sleep(1000); broadcastService.Broadcast(board, $"Night walker ({localZombie}) will spawn in 1 seconds"); Thread.Sleep(1000); board.AddGameObject(new Zombie($"Night-walker ({localZombie})", 0.Random(10), 0)); }
public IObservable <RedisConnectionInfo> Restore() { return(_connectionStorage.GetAllAsync() .ToObservable() .SelectMany(list => list) .Select(connectionEntity => GetConnection( connectionEntity.Name, connectionEntity.ConnectionString, connectionEntity.Id)) .Do(connectionInfo => { _connectionRegistry.Add(connectionInfo); }) .Do(connectionInfo => { _broadcastService.Broadcast( new ConnectionBroadcast(connectionInfo.Id, ConnectionBroadcastKind.Restore)); })); }
public IDisposable BindSelection() { return(_model.WhenAnyValue(m => m.SelectedNode) .SubscribeWithLog(node => { switch (node) { case KeyResultNodeModel key: _broadcastService.Broadcast( new ViewStructIntent(key.ResultProjectionInfo)); break; default: _broadcastService.Broadcast( new ViewStructIntent(null)); break; } })); }
public async Task SendPosition(PlayerPosition position) { position.ClientId = _connectionService.ConnectionId; if (_catchme.SetPlayerPosition(position.ClientId, position)) { var catcher = _catchme.GetCatcher(); await _broadcastService.Broadcast <CatchmeController>(p => p.SendCatcher(), new { clientId = catcher }); } await _broadcastService.BroadcastToOthers <PlayerPositionController>(p => p.SendPosition(null), position, _connectionService); }
private void MoveGameObjects(object state) { var unitsToRemove = new List <IGameObject>(); foreach (var go in gameObjects) { if (go is Zombie zombie) { zombie.MoveRandom(); broadcastService.Broadcast(this, $"[{this.Name}] WALK {zombie.Name} {zombie.X} {zombie.Y}"); if (zombie.Y >= 20) { EndGameAndRespawn(); unitsToRemove.Add(go); } } } foreach (var go in unitsToRemove) { this.gameObjects.Remove(go); } }
private void Print(IGameCommand command, string msg) { broadcastService.Broadcast(command.ConnectionId, msg); }
public Transaction[] TryBroadcast(ref uint256[] knownBroadcasted) { var height = _Cache.BlockCount; DateTimeOffset startTime = DateTimeOffset.UtcNow; int totalEntries = 0; HashSet <uint256> knownBroadcastedSet = new HashSet <uint256>(knownBroadcasted ?? new uint256[0]); List <Transaction> broadcasted = new List <Transaction>(); foreach (var broadcast in GetRequests()) { totalEntries++; if (broadcast.Request.PreviousScriptPubKey == null) { var transaction = broadcast.Request.Transaction; var txHash = transaction.GetHash(); _Tracker.TransactionCreated(broadcast.Cycle, broadcast.TransactionType, txHash, broadcast.Correlation); RecordMaping(broadcast, transaction, txHash); if (!knownBroadcastedSet.Contains(txHash) && broadcast.Request.IsBroadcastableAt(height) && _Broadcaster.Broadcast(transaction)) { LogBroadcasted(broadcast); broadcasted.Add(transaction); } knownBroadcastedSet.Add(txHash); } else { foreach (var tx in GetReceivedTransactions(broadcast.Request.PreviousScriptPubKey)) { foreach (var coin in tx.Outputs.AsCoins()) { if (coin.ScriptPubKey == broadcast.Request.PreviousScriptPubKey) { var transaction = broadcast.Request.ReSign(coin); var txHash = transaction.GetHash(); _Tracker.TransactionCreated(broadcast.Cycle, broadcast.TransactionType, txHash, broadcast.Correlation); RecordMaping(broadcast, transaction, txHash); if (!knownBroadcastedSet.Contains(txHash) && broadcast.Request.IsBroadcastableAt(height) && _Broadcaster.Broadcast(transaction)) { LogBroadcasted(broadcast); broadcasted.Add(transaction); } knownBroadcastedSet.Add(txHash); } } } } var remove = height >= broadcast.Expiration; if (remove) { Repository.Delete <Record>("TrustedBroadcasts", broadcast.Request.Transaction.GetHash().ToString()); } } knownBroadcasted = knownBroadcastedSet.ToArray(); Logs.Broadcasters.LogInformation($"Trusted Broadcaster is monitoring {totalEntries} entries in {(long)(DateTimeOffset.UtcNow - startTime).TotalSeconds} seconds"); return(broadcasted.ToArray()); }
private void Activate() { _broadcastService.Broadcast( new ActivateTargetIntent(_model.ServerInfo)); }
public void Broadcast([ModelBinder(typeof(IdsArrayBinder))] IEnumerable <Int32> ids, string message) { broadcastService.Broadcast(ids, message); }