/// <summary> /// Subscribes to notifications from ClientBoardStateManager to get updates. /// </summary> /// <param name="listener">The subscriber. </param> /// <param name="identifier">The identifier of the subscriber. </param> public void Subscribe(IClientBoardStateListener listener, string identifier) { // Cleaning current state since new state will be called _mapIdToBoardShape = null; _mapIdToQueueElement = null; _priorityQueue = null; _redoStack = null; _undoStack = null; GC.Collect(); // Re-initializing state and adding subscriber InitializeDataStructures(); _clients.Add(identifier, listener); try { // Creating BoardServerShape object and requesting communicator Trace.WriteLine("ClientBoardStateManager.Subscribe: Sending fetch state request to communicator."); BoardServerShape boardServerShape = new(null, Operation.FETCH_STATE, _currentUserId); _clientBoardCommunicator.Send(boardServerShape); Trace.WriteLine("ClientBoardStateManager.Subscribe: Fetch state request sent to communicator."); } catch (Exception e) { Trace.WriteLine("ClientBoardStateManager.Subscribe: Exception occurred."); Trace.WriteLine(e.Message); } }
/// <summary> /// Initializes the data structures which are maintaining the state. /// </summary> /// <param name="initializeUndoRedo">Initialize undo-redo stacks or not. By default it is true.</param> private void InitializeDataStructures(bool initializeUndoRedo = true) { _mapIdToBoardShape = new Dictionary <string, BoardShape>(); _mapIdToQueueElement = new Dictionary <string, QueueElement>(); _priorityQueue = new BoardPriorityQueue(); if (initializeUndoRedo) { _redoStack = new BoardStack(_undoRedoCapacity); _undoStack = new BoardStack(_undoRedoCapacity); } }