public ActiveBoardOperationsHandler(Coordinate canvasSize)
 {
     _isLastDrawPending = false;
     _lastDrawn         = null;
     _stateManager      = ClientBoardStateManager.Instance;
     _canvasSize        = canvasSize;
 }
        /// <summary>
        ///     Provides Update to the Manager, after shape completion.
        ///     Also yield provides the list of operations for the UX to perform.
        /// </summary>
        /// <param name="oldBoardShape">Original BoardShape.</param>
        /// <param name="newBoardShape">BoardShape after modification.</param>
        /// <param name="operationType">The type of operation being performed.</param>
        /// <returns>The List of operations on Shapes for UX to render.</returns>
        private List <UXShape> UpdateManager(BoardShape oldBoardShape, BoardShape newBoardShape, Operation operationType)
        {
            // Whenever Update goes to the Manager, the last operation saved locally is discarded.
            // Set prev drawings to null in case any exists.
            _lastDrawn         = null;
            _isLastDrawPending = false;

            // List of UXShapes to be sent to the server.
            var operations = new List <UXShape>();

            // Shape Id of the shape is kept same, After modification.
            var oldShapeId = oldBoardShape.ShapeOwnerId;

            // Creation of UXShapes for old boardshape.
            var oldShape = new UXShape(UXOperation.DELETE, oldBoardShape.MainShapeDefiner, oldShapeId);

            // Creation of UXShape for new boardshape.
            var uxNewShape = new UXShape(UXOperation.CREATE, newBoardShape.MainShapeDefiner, oldShapeId);

            // Appending them to list of operations to be performed by the UX.
            operations.Add(oldShape);
            operations.Add(uxNewShape);

            // Setting flags in NewBoardShape before sending to Manager.
            newBoardShape.RecentOperation  = operationType;
            newBoardShape.LastModifiedTime = DateTime.Now;

            // saving the state across clients.
            _stateManager.SaveOperation(newBoardShape);

            return(operations);
        }
Exemple #3
0
        /// <summary>
        ///     Pushes the elements (BoardShape before and after the operation) on the top of the stack.
        /// </summary>
        /// <param name="boardShapePrevious">BoardShape before operation.</param>
        /// <param name="boardShapeNew">BoardShape after operation.</param>
        public void Push(BoardShape boardShapePrevious, BoardShape boardShapeNew)
        {
            if (GetSize() == s_capacity)
            {
                Trace.Indent();
                Trace.WriteLine(
                    "Whiteboard.BoardStack.Push: Stack is at full capacity. Removing first inserted element.");
                Trace.Unindent();
                RemoveFirstInserted();
            }

            _stack.Add(Tuple.Create(boardShapePrevious, boardShapeNew));
        }
 /// <summary>
 ///     Saves the update on a shape in the state and sends it to server for broadcast.
 /// </summary>
 /// <param name="boardShape">The object describing shape.</param>
 /// <returns>Boolean to indicate success status of update.</returns>
 public bool SaveOperation(BoardShape boardShape)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        ///     Creates shape based on mouse drag.
        /// </summary>
        /// <param name="shapeType">Denotes which shape to create.</param>
        /// <param name="start">Start of mouse drag.</param>
        /// <param name="end">End of mouse drag.</param>
        /// <param name="strokeWidth">Width of the outline stroke.</param>
        /// <param name="strokeColor">Color of the outline stroke.</param>
        /// <param name="shapeId">Id of the shape.</param>
        /// <param name="shapeComp">Denotes whether the shape is complete, or if it is for real-time rendering.</param>
        /// <returns>The List of operations on Shapes for UX to render.</returns>
        public override List <UXShape> CreateShape(ShapeType shapeType, Coordinate start, Coordinate end,
                                                   float strokeWidth, BoardColor strokeColor, string shapeId = null,
                                                   bool shapeComp = false)
        {
            // shapeId null signifies a new shape creation.
            if (shapeId == null)
            {
                _lastDrawn         = null;
                _isLastDrawPending = false;
            }

            // List of Operations to be send to UX
            var operations = new List <UXShape>();

            // required to clear the previous shape in internal storage for real time rendering, before forming the new shape
            if (_lastDrawn != null && shapeType != _lastDrawn.MainShapeDefiner.ShapeIdentifier)
            {
                // Delete the Object that was already created in the canvas
                var oldShapeId = _lastDrawn.Uid;
                var oldShape   = new UXShape(UXOperation.DELETE, _lastDrawn.MainShapeDefiner, oldShapeId);
                operations.Add(oldShape);

                // In this case previous shape won't be used for creating new shape
                _lastDrawn = null;
            }

            //creation of a completely new shape
            string newShapeId = null;

            if (_lastDrawn == null)
            {
                var newMainShape = ShapeFactory.MainShapeCreatorFactory(shapeType, start, end, null);

                // setting params for new shape
                newMainShape.StrokeColor = strokeColor.Clone();
                newMainShape.StrokeWidth = strokeWidth;

                var newUxShape = new UXShape(UXOperation.CREATE, newMainShape, null);
                newShapeId = newUxShape.WindowsShape.Uid;
                operations.Add(newUxShape);

                var userLevel = 0; // to be changed
                var userId    = _stateManager.GetUser();

                // creating the new BoardShape to send to server
                _lastDrawn = new BoardShape(newMainShape, userLevel, DateTime.Now, DateTime.Now, newShapeId, userId,
                                            Operation.CREATE);
            }
            else
            {
                var modifiedPrevShape =
                    ShapeFactory.MainShapeCreatorFactory(shapeType, start, end, _lastDrawn.MainShapeDefiner);
                var newUxShape = new UXShape(UXOperation.CREATE, modifiedPrevShape, null);
                newShapeId = newUxShape.WindowsShape.Uid;
                operations.Add(newUxShape);

                _lastDrawn.MainShapeDefiner = modifiedPrevShape;
                _lastDrawn.LastModifiedTime = DateTime.Now;
                _lastDrawn.RecentOperation  = Operation.CREATE;
            }

            // sending the Updates to the Client Side Server
            _isLastDrawPending = true;
            if (shapeComp)
            {
                // send updates to server .. clone of _lastDrawn
                var newBoardShape = _lastDrawn.Clone();
                newBoardShape.RecentOperation  = Operation.CREATE;
                newBoardShape.Uid              = newShapeId;
                newBoardShape.LastModifiedTime = DateTime.Now;
                newBoardShape.CreationTime     = DateTime.Now;
                _stateManager.SaveOperation(newBoardShape);

                //reset the variables
                _lastDrawn         = null;
                _isLastDrawPending = false;
            }

            return(operations);
        }