示例#1
0
        public IActionResult AddDevice(AddDeviceCommand command)
        {
            try
            {
                using var repository = _repositoryFactory.Create();
                repository.Add(new Device
                {
                    DeviceName       = command.DeviceName,
                    UserId           = command.UserId,
                    IeeeAddress      = command.IeeeAddress,
                    FriendlyName     = command.FriendlyName,
                    Type             = command.Type,
                    NetworkAddress   = command.NetworkAddress,
                    ManufacturerId   = command.ManufacturerId,
                    ManufacturerName = command.ManufacturerName,
                    PowerSource      = command.PowerSource,
                    ModelId          = command.ModelId,
                    Status           = command.Status
                });
                repository.Commit();

                return(Ok(null));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
示例#2
0
 private void RefreshCommands()
 {
     AddDeviceCommand.RaiseCanExecuteChanged();
     MoveUpCommand.RaiseCanExecuteChanged();
     MoveDownCommand.RaiseCanExecuteChanged();
     DeleteDeviceCommand.RaiseCanExecuteChanged();
 }
示例#3
0
        private bool Execute(AddDeviceCommand command)
        {
            var aggregateEvent = new DeviceAddedEvent(command.SerialNumber, command.IpAddress);

            Emit(aggregateEvent);

            return(true);
        }
        public async Task <IActionResult> RegisterDevice([FromServices] IMediatorHandler bus, [FromBody] AddDeviceModel addDeviceModel)
        {
            var command = new AddDeviceCommand(addDeviceModel.Name, addDeviceModel.Observation,
                                               addDeviceModel.MacAddress, addDeviceModel.UserId);
            await bus.SendCommand(command);

            return(ResponseCreated($"api/device/{command.Id}", new DeviceDetailsModel
            {
                Id = command.Id.ToString(),
                Name = command.Name,
                MacAddress = command.MacAddress,
                Observation = command.Observation
            }));
        }
示例#5
0
        public void InitialState_AfterAddDevice_DeviceAddedEventEmitted_UsingAsk()
        {
            var probe = CreateTestActor("probeActor");

            Sys.EventStream.Subscribe(probe, typeof(DomainEvent <Device, DeviceId, DeviceAddedEvent>));
            var aggregateManager = Sys.ActorOf(Props.Create(() => new DeviceManager()), "test-devicemanager");

            var aggregateId = TestAggregateId;
            var command     = new AddDeviceCommand(aggregateId, "12345", "127.0.0.1");

            aggregateManager.Ask(command);

            ExpectMsg <DomainEvent <Device, DeviceId, DeviceAddedEvent> >(
                x => x.AggregateIdentity.Equals(aggregateId), TimeSpan.FromSeconds(10));
        }
        public DeviceViewModel()
        {
            _deviceService = ServiceFactory.CreateDeviceService;
            _deviceService.DevicesChange   += UpdateDevices;
            _deviceService.OnDeviceChanged += UpdateDevice;
            _devices    = new ObservableCollection <DeviceDTO>();
            _editDevice = false;

            NavigationViewModel.ConnectionEstablishedEvent += RequestDevices;
            NavigationViewModel.ConnectionLostEvent        += CleanDevices;

            NewDeviceCommand    = new NewDeviceCommand(this);
            ToggleDeviceCommand = new ToggleDeviceCommand(this);
            SaveDeviceCommand   = new AddDeviceCommand(this);
            EditDeviceCommand   = new EditDeviceCommand(this);
            DeleteDeviceCommand = new MessageBoxCommand(new DeleteDeviceCommand(this), null, "Do you really want to delete this device?");
        }
示例#7
0
        public void InitialState_AfterSetLocationCommand_LocationSetEventEmitted_UsingTell()
        {
            var probe = CreateTestActor("probeActor");

            Sys.EventStream.Subscribe(probe, typeof(DomainEvent <Device, DeviceId, LocationSetEvent>));
            var aggregateManager = Sys.ActorOf(Props.Create(() => new DeviceManager()), "test-devicemanager");

            var aggregateId = TestAggregateId;

            var command     = new AddDeviceCommand(aggregateId, "16777215", "127.0.0.1");
            var nextCommand = new SetLocationCommand(aggregateId, "Default");

            aggregateManager.Tell(command);
            aggregateManager.Tell(nextCommand);

            ExpectMsg <DomainEvent <Device, DeviceId, LocationSetEvent> >(
                x => x.AggregateIdentity.Equals(aggregateId) &&
                x.AggregateEvent.Location == "Default");
        }
 public IActionResult Post([FromBody] AddDeviceCommand command)
 {
     commandBus.Execute(command);
     return(Ok());
 }
示例#9
0
 public async Task <IActionResult> Post(AddDeviceCommand request)
 {
     return(Ok(await Mediator.Send(request)));
 }