Ejemplo n.º 1
0
        public async Task Handle(DeactivateTerminal message, CancellationToken token = default(CancellationToken))
        {
            AssertionConcern.AssertArgumentNotNull(message, nameof(message));

            var eventSource = this.eventSourceFactory.Create(
                this.settingsService.EventSourcingInBaseUrl + "/",
                this.settingsService.EventSourcingOutBaseUrl + "/",
                message.AuthorId
                );

            Terminal terminal = await eventSource.Session.Get <Terminal>(message.Id, nameof(terminal), message.ExpectedVersion, token);

            terminal.Deactivate();
            await eventSource.Session.Commit(token);
        }
        public async Task Handle(DeactivateTerminal message, CancellationToken token = default(CancellationToken))
        {
            AssertionConcern.AssertArgumentNotNull(message, nameof(message));

            var queryResult = await this.neuronGraphQueryClient.GetTerminalById(
                this.settingsService.CortexGraphOutBaseUrl + "/",
                message.Id.ToString(),
                new Graph.Common.NeuronQuery()
            {
                TerminalActiveValues = Graph.Common.ActiveValues.All
            },
                token
                );

            var terminal = queryResult.Neurons.FirstOrDefault()?.Terminal;

            AssertionConcern.AssertArgumentValid(t => t != null, terminal, "Specified terminal does not exist.", "Id");

            // validate
            var validationResult = await this.validationClient.UpdateNeuron(
                this.settingsService.IdentityAccessOutBaseUrl + "/",
                Guid.Parse(terminal.PresynapticNeuronId),
                message.UserId,
                token);

            if (!validationResult.HasErrors)
            {
                var txn = await Transaction.Begin(this.eventStore, this.inMemoryEventStore, message.Id, validationResult.UserNeuronId, message.ExpectedVersion);

                await txn.InvokeAdapter(
                    typeof(TerminalDeactivated).Assembly,
                    async (ev) => await this.terminalAdapter.DeactivateTerminal(
                        message.Id,
                        validationResult.UserNeuronId,
                        ev
                        ));

                await txn.Commit();
            }
        }