示例#1
0
        /// <summary>
        /// Creates a shape and adds it to the canvas.
        /// </summary>
        /// <param name="shapeId">The ID of the shape to add.</param>
        /// <returns>Async task.</returns>
        private async Task CreateShape(Guid shapeId)
        {
            // create a shape UI element
            Rectangle shape = null;
            await App.Current.Dispatcher.InvokeAsync(() =>
            {
                RotateTransform rotation = new RotateTransform()
                {
                    Angle = 0, CenterX = 50, CenterY = 50
                };
                shape = new Rectangle()
                {
                    Height          = 100,
                    Width           = 100,
                    Stroke          = new SolidColorBrush(Colors.Yellow),
                    StrokeThickness = 5,
                    RadiusX         = 20,
                    RadiusY         = 20,
                    RenderTransform = rotation
                };
            });

            // get the current shape position from the shape actor service
            ActorId     actorId      = new ActorId($"{ClientId:N}_{shapeId:N}");
            IShapeActor shapeActor   = ActorProxy.Create <IShapeActor>(actorId, "ShapeActor");
            var         currentShape = await shapeActor.GetCurrentPositionAsync();

            // subscribe this shape to all shape change events
            var shapesEventHandler = new ShapeEventsHandler(ShapesCanvas, shape);

            // save the shape state
            shapes.Add(shapeId, new ShapeState(shapeActor, shapesEventHandler));
            shapesEventHandler.ShapeChanged(currentShape);
        }
        /// <summary>
        /// Creates a new shape and adds it to the canvas.
        /// </summary>
        /// <param name="shapeId">The ID of the shape to add.</param>
        /// <returns>Async task.</returns>
        private async Task CreateNewShape(Guid shapeId)
        {
            // create a shape UI element
            RotateTransform rotation = new RotateTransform()
            {
                Angle = 0, CenterX = 50, CenterY = 50
            };
            Rectangle shape = new Rectangle()
            {
                Height          = 100,
                Width           = 100,
                Stroke          = new SolidColorBrush(Colors.Yellow),
                StrokeThickness = 5,
                RadiusX         = 20,
                RadiusY         = 20,
                RenderTransform = rotation
            };

            // create a new shape
            ActorId     actorId      = new ActorId(shapeId);
            IShapeActor shapeActor   = ActorProxy.Create <IShapeActor>(actorId, shapeActorServiceUri);
            var         currentShape = await shapeActor.GetCurrentPositionAsync();

            // subscribe to all shape change events
            var shapeEventHandler = new ShapeEventsHandler(ShapesCanvas, shape);
            await shapeActor.SubscribeAsync <IShapeEvents>(shapeEventHandler, new TimeSpan(0, 0, 5));

            // save the shape state
            shapes.Add(shapeId, new ShapeState(shapeActor, shapeEventHandler));
        }
示例#3
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="shapeEventHandler">The shape event handler.</param>
 public ShapeState(IShapeActor shape, ShapeEventsHandler shapeEventHandler)
 {
     this.Shape             = shape;
     this.ShapeEventHandler = shapeEventHandler;
 }