Exemplo n.º 1
0
        public async Task <ExecutionResult> Execute(ExecuteContext <TCommand> context)
        {
            try
            {
                IAggregateRoot aggregateRoot = await _handler.ExecuteAsync(context.Arguments);

                _eventFactory.Make(aggregateRoot.Events);

                await aggregateRoot.CommitAsync(_aggregateStore);

                foreach (var composite in aggregateRoot.Events)
                {
                    await context.Publish(composite.Event, composite.Event.GetType());
                }

                return(context.Completed());
            }
            catch (ValidationException ex)
            {
                return(context.Faulted(ex));
            }
            catch (TelegramClientException ex)
            {
                return(context.Faulted(ex));
            }
            catch (Exception ex)
            {
                return(context.Faulted(ex));
            }
        }
        public async Task <ExecutionResult> Execute(ExecuteContext <ConsentArguments> context)
        {
            var sourceAddress = context.Arguments.Address;

            _logger.InfoFormat("Consent Content: {0}", sourceAddress);

            try
            {
                var routingSlip    = GetRoutingSlip(context);
                var compensateLogs = routingSlip.Message.CompensateLogs;

                var a = compensateLogs[0].Data["localFilePath"];

                throw new Exception("There is a fault in Consent Activity!");

                return(context.Completed <ConsentLog>(new Log("ConsentParam")));
            }
            catch (Exception exception)
            {
                var preMessage = exception.GetType() == typeof(HttpRequestException) ? "Exception from HttpClient: " : "Exception: ";

                _logger.Error(preMessage, exception.InnerException ?? exception);

                return(context.Faulted(exception));
            }
        }
Exemplo n.º 3
0
        public async Task <ExecutionResult> Execute(ExecuteContext <IRentCarActivityArguments> context)
        {
            this._logger.LogInformation($"Executing {nameof(RentCarActivity)} activity" +
                                        $"\r\nPayload: {JsonConvert.SerializeObject(context.Arguments)}");

            var(accepted, rejected) = await this._rentCarClient.GetResponse <ICarRentalAccepted, ICarRentalRejected>(new
            {
                context.Arguments.CarId,
                context.Arguments.RentFrom,
                context.Arguments.RentTo
            });

            var test = accepted.IsCompletedSuccessfully();

            if (accepted.IsCompletedSuccessfully())
            {
                var result = await accepted;

                return(context.Completed <IRentCarActivityLog>(new
                {
                    result.Message.CarRentalId
                }));
            }
            else
            {
                var result = await rejected;

                return(context.Faulted());
            }
        }
Exemplo n.º 4
0
        public async Task <ExecutionResult> Execute(ExecuteContext <FaultyArguments> context)
        {
            Console.WriteLine("FaultyActivity: Execute");
            Console.WriteLine("FaultyActivity: About to blow this up!");

            return(context.Faulted(new IntentionalTestException("Things that make you go boom!")));
        }
        public async Task <ExecutionResult> Execute(ExecuteContext <TParams> context)
        {
            var inconsistenciesIds = await FindAsync(context.Arguments);

            var anotherRunRequired = false;

            if (inconsistenciesIds != null)
            {
                foreach (var inconsistentId in inconsistenciesIds)
                {
                    anotherRunRequired = true;

                    try
                    {
                        await RemedyAsync(context.Arguments, inconsistentId);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, $"Could not remedy inconsistency with ID {inconsistentId}");
                        return(context.Faulted(e));
                    }
                }
            }

            var addition = anotherRunRequired ? 1 : 0;

            return(context.CompletedWithVariables(new ConsistencyRemediationVariables
            {
                RerunRequiredTimes = context.Arguments.RerunRequiredTimes + addition
            }
                                                  ));
        }
Exemplo n.º 6
0
        public async Task <ExecutionResult> Execute(ExecuteContext <IBookHotelActivityArguments> context)
        {
            this._logger.LogInformation($"Executing {nameof(BookHotelActivity)} activity" +
                                        $"\r\nPayload: {JsonConvert.SerializeObject(context.Arguments)}");

            var(accepted, rejected) = await this._hotelBookingClient.GetResponse <IHotelBookingAccepted, IHotelBookingRejected>(new
            {
                context.Arguments.HotelId,
                context.Arguments.RoomId,
                context.Arguments.CheckIn,
                context.Arguments.CheckOut,
            });

            if (accepted.IsCompletedSuccessfully())
            {
                var result = await accepted;

                return(context.Completed <IBookHotelActivityLog>(new
                {
                    result.Message.BookingId
                }));
            }
            else
            {
                var result = await rejected;

                this._logger.LogWarning($"Execution of  {nameof(BookHotelActivity)} activity failded. " +
                                        $"\r\nPayload: {JsonConvert.SerializeObject(context.Message)}" +
                                        $"\r\nReason: {result.Message.Reason}");

                return(context.Faulted());
            }
        }
Exemplo n.º 7
0
        public async Task <ExecutionResult> Execute(ExecuteContext <IBookFlightActivityArguments> context)
        {
            this._logger.LogInformation($"Executing {nameof(BookFlightActivity)} activity" +
                                        $"\r\nPayload: {JsonConvert.SerializeObject(context.Arguments)}");

            var(accepted, rejected) = await this._flightBookingClient
                                      .GetResponse <IBookFlightAccepted, IBookFlightRejected>(new
            {
                context.Arguments.AirportId,
                context.Arguments.DepartureDate,
                context.Arguments.DestinationId,
                context.Arguments.ReturnDate,
                context.Arguments.ReturnId
            });

            var test = accepted.IsCompletedSuccessfully();

            if (accepted.IsCompletedSuccessfully())
            {
                var result = await accepted;

                return(context.Completed <IBookFlightActivityLog>(new
                {
                    result.Message.DepartureFlightId,
                    result.Message.ReturnFLightId
                }));
            }
            else
            {
                var result = await rejected;

                return(context.Faulted());
            }
        }
        public async Task <ExecutionResult> Execute(ExecuteContext <OwnershipAssignmentParameters> context)
        {
            var result = await _busPublisher.SendRequest <CreateAccountingGroupOwnership, IParentChildIdentifierResult>(
                new CreateAccountingGroupOwnership(context.Arguments.AccountingGroupId, context.Arguments.OwnerUserId)
                );

            return(result.Successful ? context.Completed() : context.Faulted(new Exception(result.ErrorCode)));
        }
        public async Task <ExecutionResult> Execute(ExecuteContext <OwnershipAssignmentParameters> context)
        {
            var result = await _busPublisher.SendRequest <ICreatePointOfSaleUserAuthorization, IParentChildIdentifierResult>(
                new CreatePointOfSaleOwnership(context.Arguments.PointOfSaleId, context.Arguments.OwnerUserId)
                );

            return(result.Successful ? context.Completed() : context.Faulted(result.ToException()));
        }
Exemplo n.º 10
0
        public async Task <ExecutionResult> Execute(ExecuteContext <FullfilOrderArgs> context)
        {
            if (context.Arguments.Id.StartsWith("error"))
            {
                return(context.Faulted(new ArgumentException("Faulted because of... reasons!")));
            }

            return(context.Completed());
        }
Exemplo n.º 11
0
        public Task <ExecutionResult> Execute(ExecuteContext <ApplyCouponArguments> context)
        {
            if (context.Arguments.Quantity < 5)
            {
                return(Task.FromResult(context.Faulted()));
            }

            this.logger.LogInformation($"Applied discount of $10");
            return(Task.FromResult(context.CompletedWithVariables(new { Discount = 10 })));
        }
Exemplo n.º 12
0
        public async Task <ExecutionResult> Execute(ExecuteContext <IdentifyProductsArguments> context)
        {
            var number = context.Arguments.NumberOfTasks;
            int tenant = 1;

            if (!int.TryParse(context.Arguments.Tenant, out tenant))
            {
                return(context.Faulted(new System.Exception("Faulted!?!?")));
            }

            return(context.Completed());
        }
Exemplo n.º 13
0
        public Task <ExecutionResult> Execute(ExecuteContext <ConfirmActivityArguments> context)
        {
            if (context.Arguments.GuestsCount == 7)
            {
                Log.Error("Error in reservation!");
                return(Task.FromResult(context.Faulted()));
            }

            Log.Information("Finishing reservation");

            return(Task.FromResult(context.Completed()));
        }
Exemplo n.º 14
0
        public async Task <ExecutionResult> Execute(ExecuteContext <CreationActivityParameters> context)
        {
            var result = await _busPublisher.SendRequest <CreateAccountingGroup, IIdentifierResult>(
                new CreateAccountingGroup(context.Arguments.Id, context.Arguments.DisplayName, context.Arguments.SaleStrategyId)
                );

            if (!result.Successful)
            {
                return(context.Faulted(result.ToException()));
            }

            return(context.Completed(new IdentifierLogEntry(result.Id.Value)));
        }
Exemplo n.º 15
0
        public async Task <ExecutionResult> Execute(ExecuteContext <TEvent> context)
        {
            try
            {
                await _handler.HandleAsync(context.Arguments);

                return(context.Completed());
            }
            catch (Exception ex)
            {
                _exceptionHandler.Handle(ex, context.Arguments);
                return(context.Faulted());
            }
        }
Exemplo n.º 16
0
        public async Task <ExecutionResult> Execute(ExecuteContext <PreProcessArguments> context)
        {
            var sourceAddress = context.Arguments.Address;

            _logger.InfoFormat("PreProcess Content: {0}", sourceAddress);

            try
            {
                return(context.Completed <PreProcessLog>(new Log("PreProcessParam")));
            }
            catch (Exception exception)
            {
                var preMessage = exception.GetType() == typeof(HttpRequestException) ? "Exception from HttpClient: " : "Exception: ";

                _logger.Error(preMessage, exception.InnerException ?? exception);

                return(context.Faulted(exception));
            }
        }
Exemplo n.º 17
0
 ExecutionResult ExecuteContext.Faulted()
 {
     return(_context.Faulted());
 }
        public async Task <ExecutionResult> Execute(ExecuteContext <RetrieveArguments> context)
        {
            var sourceAddress = context.Arguments.Address;

            _logger.InfoFormat("Retrieve Content: {0}", sourceAddress);

            try
            {
                //throw new HttpRequestException();

                using (var client = new HttpClient())
                {
                    var response = await client.GetAsync(sourceAddress);

                    if (response.IsSuccessStatusCode)
                    {
                        var localFileName = GetLocalFileName(response, sourceAddress);

                        _logger.InfoFormat("Success, copying to local file: {0}", GetRelativePath(Environment.CurrentDirectory, localFileName));

                        using (var stream = File.Create(localFileName, 4096, FileOptions.Asynchronous))
                        {
                            await response.Content.CopyToAsync(stream).ConfigureAwait(false);
                        }

                        var fileInfo     = new FileInfo(localFileName);
                        var localAddress = new Uri(fileInfo.FullName);

                        _logger.InfoFormat("Completed, length = {0}", fileInfo.Length);

                        await context.Publish <ContentRetrieved>(new
                        {
                            Timestamp    = DateTime.UtcNow,
                            Address      = sourceAddress,
                            LocalPath    = fileInfo.FullName,
                            LocalAddress = localAddress,
                            fileInfo.Length,
                            ContentType = response.Content.Headers.ContentType.ToString(),
                        }).ConfigureAwait(false);

                        return(context.Completed <RetrieveLog>(new Log(fileInfo.FullName)));
                    }

                    string message = string.Format("Server returned a response status code: {0} ({1})",
                                                   (int)response.StatusCode, response.StatusCode);

                    _logger.ErrorFormat("Failed to retrieve image: {0}", message);

                    await context.Publish <ContentNotFound>(new
                    {
                        Timestamp = DateTime.UtcNow,
                        Address   = sourceAddress,
                        Reason    = message,
                    }).ConfigureAwait(false);

                    return(context.Completed());
                }
            }
            catch (Exception exception)
            {
                var preMessage = exception.GetType() == typeof(HttpRequestException) ? "Exception from HttpClient: " : "Exception: ";

                _logger.Error(preMessage, exception.InnerException ?? exception);

                return(context.Faulted(exception));
            }
        }