/// <summary> /// Property changes from the monitor /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PropertyChangedMonitor(object sender, PropertyChangedEventArgs e) { try { ThreadContext.InvokeOnUiThread( delegate { switch (e.PropertyName) { case "CmdjSentEntry": ProcessValues1(MonitorQueue.CmdjSentEntry); break; case "Cmdj2SentEntry": ProcessValues2(MonitorQueue.Cmdj2SentEntry); break; } }, _ct); } catch (Exception ex) { var monitorItem = new MonitorEntry { Datetime = HiResDateTime.UtcNow, Device = MonitorDevice.Server, Category = MonitorCategory.Interface, Type = MonitorType.Error, Method = MethodBase.GetCurrentMethod().Name, Thread = Thread.CurrentThread.ManagedThreadId, Message = $" {ex.Message}" }; MonitorLog.LogToMonitor(monitorItem); OpenDialog(ex.Message); } }
/// <summary> /// Removes the window. /// </summary> /// <param name="windowId">The window identifier.</param> /// <param name="coordX">The coord x.</param> /// <param name="coordY">The coord y.</param> public void RemoveWindow(long windowId, int coordX, int coordY) { var args = new GameWindowEventArgs(windowId, coordX, coordY); Tracer.Debug(string.Format("MapEditViewModel :: Window removed callback retrieved ({0})", args)); ThreadContext.InvokeOnUiThread(() => this.WindowRemoved(this, args)); }
/// <summary> /// Keeps the game alive. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param> private async void KeepGameAlive(object sender, ElapsedEventArgs e) { if (!this.currentGameId.Equals(Guid.Empty)) { bool isGameRunning; try { isGameRunning = await this.gameConsoleServiceClient.IsGameRunningAsync(this.currentGameId); } catch (ServerUnavailableException ex) { ApplicationHelpers.HandleServerException(ex); return; } catch (Exception ex) { this.LogError(ex.Message, ex); ThreadContext.InvokeOnUiThread(() => this.RunningGameDisappeared(this, null)); this.keepAliveTimer.Stop(); return; } if (isGameRunning) { await Tracer.Debug(string.Format("Sent keepalive for the game with the id {0}. Game is still running.", this.currentGameId)); } else { await Tracer.Debug(string.Format("Sent keepalive for the game with the id {0}. Game is no longer running.", this.currentGameId)); ThreadContext.InvokeOnUiThread(() => this.RunningGameDisappeared(this, null)); this.keepAliveTimer.Stop(); } } }
/// <summary> /// Updates the name. /// </summary> /// <param name="name">The name.</param> public void UpdateName(string name) { var args = new UpdateNameEventArgs(name); Tracer.Debug(string.Format("MapEditViewModel :: Name updated callback retrieved (Name={0})", args.Name)); ThreadContext.InvokeOnUiThread(() => this.NameUpdated(this, args)); }
/// <summary> /// Updates the is playable. /// </summary> /// <param name="isPlayable">if set to <c>true</c> the map is playable.</param> public void UpdateIsPlayable(bool isPlayable) { var args = new UpdateIsPlayableEventArgs(isPlayable); Tracer.Debug(string.Format("MapEditViewModel :: Is playable callback retrieved (Flag={0})", args.IsPlayable)); ThreadContext.InvokeOnUiThread(() => this.IsPlayableUpdated(this, args)); }
/// <summary> /// Removes the hole. /// </summary> /// <param name="windowId">The window identifier.</param> /// <param name="windowX">The window x.</param> /// <param name="windowY">The window y.</param> /// <param name="holeId">The hole identifier.</param> public void RemoveHole(long windowId, int windowX, int windowY, long holeId) { var args = new GameHoleClickedEventArgs(windowId, windowX, windowY, holeId); Tracer.Debug(string.Format("MapEditViewModel :: Hole removed callback retrieved ({0})", args)); ThreadContext.InvokeOnUiThread(() => this.HoleRemoved(this, args)); }
/// <summary> /// Starts the round. /// </summary> /// <param name="directionX">The direction x where user clicked to start the ball.</param> /// <param name="directionY">The direction y where user clicked to start the ball.</param> public void StartRound(double directionX, double directionY) { var args = new RoundStartedEventArgs(new Vector(directionX, directionY)); ThreadContext.InvokeOnUiThread(() => this.OnRoundStarted(args)); }
/// <summary> /// Sets the start point. /// </summary> /// <param name="windowId">The windows identifier.</param> /// <param name="pointX">The point x.</param> /// <param name="pointY">The point y.</param> public void SetStartPoint(long windowId, double pointX, double pointY) { var args = new BallPlacedOnGameFieldEventArgs(windowId, new Point(pointX, pointY)); ThreadContext.InvokeOnUiThread(() => this.OnStartPointSet(args)); }
/// <summary> /// Cancels the game. /// </summary> public void CancelGame() { ThreadContext.InvokeOnUiThread(() => this.GameCancelled(this, null)); }
/// <summary> /// An error in the game ocurrs and the game has to be canceled by the client. /// </summary> public void GameError() { ThreadContext.InvokeOnUiThread(this.OnGameError); }
/// <summary> /// Starts the game with a specific id. /// </summary> /// <param name="gameId">The game identifier.</param> /// <param name="map">The map.</param> /// <param name="opponentName">Name of the opponent.</param> /// <param name="visibleWindows">The visible windows.</param> /// <param name="startGame">if set to <c>true</c> the player who receives this callback should start the game.</param> public void StartGame(Guid gameId, Map map, string opponentName, IEnumerable <long> visibleWindows, bool startGame) { var args = new GameStartedEventArgs(gameId, map.ToEntity(visibleWindows), opponentName, startGame); ThreadContext.InvokeOnUiThread(() => this.OnGameStarted(args)); }
/// <summary> /// Ends the round. /// </summary> /// <param name="score">The current score over all player rounds.</param> /// <param name="wasFinalRound">if set to <c>true</c> this was the final round and the game should be finished.</param> public void EndRound(int score, bool wasFinalRound) { var args = new RoundEndedEventArgs(score, wasFinalRound); ThreadContext.InvokeOnUiThread(() => this.OnRoundEnded(args)); }