예제 #1
0
        public async Task <DomainResult <ObjectId> > Handle(CreateConnectionCommand command, CancellationToken cancellationToken)
        {
            var origin = await _pointRepository.FindAsync(command.OriginPointId);

            var destination = await _pointRepository.FindAsync(command.DestinationPointId);

            if (origin is null || destination is null)
            {
                return(DomainResult.Failure <ObjectId>("Origin or Destination not found"));
            }

            var connection = new Connection(origin, destination, command.Time, command.Cost);

            var alreadyExists = await _connectionRepository.AlreadyExistsAsync(x => connection.IsTheSame(x));

            if (alreadyExists)
            {
                return(DomainResult.Failure <ObjectId>("Connection already exists.", HttpStatusCode.Conflict));
            }

            await _connectionRepository.CreateAsync(connection);

            await _mediator.Publish(new ConnectionCreatedEvent(connection));

            return(DomainResult.Ok(connection.Id));
        }
        public async Task <IActionResult> Create([FromBody] CreateConnectionCommand command)
        {
            var result = await _bus.Send(command);

            return(result.Success
                ? Created(result.Value)
                : Error(result.ErrorMessage, result.Code));
        }
예제 #3
0
        public async Task Does_not_create_a_connection_if_ConnectionTypes_do_not_match_and_sets_Error_to_InvalidOperation()
        {
            var createConnectionCommand = new CreateConnectionCommand(componentWithWebRtcAudioOutput.Id, 1, componentWithUdpAudioInput.Id, 1);
            await createConnectionCommand.Process(virtualStudio);

            Assert.IsTrue(createConnectionCommand.Error.Type == ErrorType.InvalidOperation);
            Assert.IsTrue(virtualStudio.Connections.Count == 0);
        }
예제 #4
0
        public async Task Does_not_create_a_connection_between_two_inputs()
        {
            var createConnectionCommand = new CreateConnectionCommand(componentWithWebRtcAudioInput.Id, 1, componentWithWebRtcAudioInput.Id, 1);
            await createConnectionCommand.Process(virtualStudio);

            Assert.IsTrue(createConnectionCommand.Error.Type == ErrorType.NotFound);
            Assert.IsTrue(virtualStudio.Connections.Count == 0);
        }
예제 #5
0
        public async Task Does_not_create_a_connection_with_components_that_only_exist_in_the_ComponentRepository()
        {
            var createConnectionCommand = new CreateConnectionCommand(componentWithUdpAudioOutput.Id, 1, componentWithUdpAudioInputInRepository.Id, 1);
            var success = await createConnectionCommand.Process(virtualStudio);

            Assert.IsFalse(success);
            Assert.IsNotNull(createConnectionCommand.Error);
            Assert.AreEqual(ErrorType.NotFound, createConnectionCommand.Error.Type);
        }
예제 #6
0
        public async Task Does_not_create_a_connection_when_the_output_input_is_already_connected()
        {
            var createConnectionCommand = new CreateConnectionCommand(componentWithWebRtcAudioOutput.Id, 1, componentWithWebRtcAudioInput.Id, 1);
            await createConnectionCommand.Process(virtualStudio);

            createConnectionCommand = new CreateConnectionCommand(componentWithWebRtcAudioOutput.Id, 1, componentWithWebRtcAudioInput.Id, 1);
            await createConnectionCommand.Process(virtualStudio);

            Assert.IsTrue(createConnectionCommand.Error.Type == ErrorType.InvalidOperation);
            Assert.IsTrue(virtualStudio.Connections.Count == 1);
        }
예제 #7
0
        /// <summary>
        /// Handles the MouseUp event.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public bool MouseUp(MouseEventArgs e)
        {
            if (IsActive)
            {
                SelectionManager.UnselectAll();

                if (Canvas.IsMouseCaptured)
                {
                    CreateConnectionCommand cmd = new CreateConnectionCommand(initialPoint, e.GetPosition(Canvas), Canvas);
                    UndoManager.Execute(cmd);
                }
                DeactivateTool();
                GhostManager.Release();
                return(true);
            }
            return(false);
        }
예제 #8
0
        /// <summary>
        /// Handles the MouseUp event.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public bool MouseUp(MouseEventArgs e)
        {
            if (IsActive)
            {
                SelectionManager.UnselectAll();

                if (Canvas.IsMouseCaptured)
                {
                    CreateConnectionCommand cmd = new CreateConnectionCommand(initialPoint, e.GetPosition(Canvas), Canvas);
                    UndoManager.Execute(cmd);
                }
                DeactivateTool();
                GhostManager.Release();
                return true;
            }
            return false;
        }
        private async Task CreateConnection_OnDrop(DragEventArgs e, AddConnectionDialog.CreationMode creationMode,
                                                   CreateConnectionCommand createConnectionCommand)
        {
            EntityData draggedData = e.Data.GetData(typeof(EntityData)) as EntityData;
            EntityData currentData = GetCurrentItemData();

            if (draggedData != null && currentData != null)
            {
                // show the dialog to choose which method to add a call to
                AddConnectionDialog addConnectionDialog = new AddConnectionDialog(graphSource, creationMode);
                // select the dragged item
                addConnectionDialog.Preselect(draggedData);
                if (addConnectionDialog.ShowDialog() == true)
                {
                    await createConnectionCommand(addConnectionDialog.DataElement, addConnectionDialog.ConnectionName);
                }
            }
        }
예제 #10
0
        public async Task Create_connections_between_compatible_input_and_output()
        {
            var createConnectionCommand = new CreateConnectionCommand(componentWithUdpAudioOutput.Id, 1, componentWithUdpAudioInput.Id, 1);
            await createConnectionCommand.Process(virtualStudio);

            Assert.IsNull(createConnectionCommand.Error);

            createConnectionCommand = new CreateConnectionCommand(componentWithWebRtcAudioOutput.Id, 1, componentWithWebRtcAudioInput.Id, 1);
            await createConnectionCommand.Process(virtualStudio);

            Assert.IsNull(createConnectionCommand.Error);

            createConnectionCommand = new CreateConnectionCommand(componentWithWebRtcVideoOutput.Id, 1, componentWithWebRtcVideoInput.Id, 1);
            await createConnectionCommand.Process(virtualStudio);

            Assert.IsNull(createConnectionCommand.Error);

            Assert.IsTrue(virtualStudio.Connections.Count == 3);
        }