/// <summary>
 /// Raise event.
 /// </summary>
 /// <param name="pipelineService">Pipeline service.</param>
 /// <param name="event">Event to process.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 public static async Task RaiseEventAsync(this IMessagePipelineService pipelineService, object @event,
                                          CancellationToken cancellationToken = default(CancellationToken))
 {
     var eventPipeline  = pipelineService.GetPipelineOfType <IEventPipeline>();
     var messageContext = eventPipeline.CreateMessageContext(pipelineService, @event);
     await eventPipeline.InvokeAsync(messageContext, cancellationToken);
 }
        /// <summary>
        /// Raise event.
        /// </summary>
        /// <param name="pipelineService">Pipeline service.</param>
        /// <param name="event">Event to process.</param>
        public static void RaiseEvent(this IMessagePipelineService pipelineService, object @event)
        {
            var eventPipeline  = pipelineService.GetPipelineOfType <IEventPipeline>();
            var messageContext = eventPipeline.CreateMessageContext(pipelineService, @event);

            eventPipeline.Invoke(messageContext);
        }
 public AccountController(
     IMessagePipelineService pipelineService,
     ILoggerFactory loggerFactory,
     SignInManager <User, string> signInManager) : base(pipelineService, loggerFactory)
 {
     this.signInManager = signInManager;
 }
示例#4
0
        /// <inheritdoc />
        public IMessageContext CreateMessageContext(IMessagePipelineService pipelineService, object @event)
        {
            var messageContext = new MessageContext(pipelineService, @event);

            messageContext.Pipeline = this;
            return(messageContext);
        }
示例#5
0
 public ApiTestController(
     IMessagePipelineService pipelineService,
     ILoggerFactory loggerFactory,
     IAppUnitOfWorkFactory appUnitOfWorkFactory) : base(pipelineService, loggerFactory)
 {
     this.appUnitOfWorkFactory = appUnitOfWorkFactory;
 }
示例#6
0
 /// <summary>
 /// .ctor
 /// </summary>
 /// <param name="pipelineService">Pipeline service.</param>
 /// <param name="loggerFactory">Logger factory.</param>
 public BaseController(
     IMessagePipelineService pipelineService,
     ILoggerFactory loggerFactory)
 {
     PipelineService = pipelineService;
     logger          = loggerFactory.CreateLogger <BaseController>();
 }
        /// <summary>
        /// Query.
        /// </summary>
        /// <typeparam name="TQuery">Query type.</typeparam>
        /// <param name="pipelineService">Pipelines service.</param>
        /// <param name="obj">Query object to execute by.</param>
        /// <returns>Query caller.</returns>
        public static IQueryCaller <TQuery> Query <TQuery>(this IMessagePipelineService pipelineService,
                                                           TQuery obj) where TQuery : class
        {
            var pipeline = pipelineService.GetPipelineOfType <IQueryPipeline>();

            return(pipeline.Query <TQuery>(pipelineService, obj));
        }
        /// <inheritdoc />
        public IMessageContext CreateMessageContext(IMessagePipelineService pipelineService, MessageRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }
            if (record.ContentType.IndexOf(".", StringComparison.Ordinal) < 0)
            {
                throw new ArgumentException(Properties.Strings.NoMethodNameFromContentType);
            }

            // Format object type name.
            var typesplit      = record.ContentType.Split(','); // type.method, assembly
            var objectTypeName = typesplit[0].Substring(0, typesplit[0].LastIndexOf(".", StringComparison.Ordinal))
                                 + "," + typesplit[1];
            var objectType = Type.GetType(objectTypeName);

            if (objectType == null)
            {
                throw new InvalidOperationException(string.Format(Properties.Strings.CannotLoadType, objectTypeName));
            }
            var obj = Activator.CreateInstance(objectType, nonPublic: true);

            var methodName = typesplit[0].Substring(typesplit[0].LastIndexOf(".", StringComparison.Ordinal) + 1);
            var method     = objectType.GetTypeInfo().GetMethod(methodName);

            if (method == null)
            {
                throw new InvalidOperationException(string.Format(Properties.Strings.CannotFindMethod, methodName));
            }
            var delegateType = Expression.GetDelegateType(
                method.GetParameters().Select(p => p.ParameterType).Concat(new[] { method.ReturnType }).ToArray());
            var @delegate = obj.GetType().GetTypeInfo().GetMethod(methodName).CreateDelegate(delegateType, obj);

            if (@delegate == null)
            {
                throw new InvalidOperationException(Properties.Strings.CannotCreateDelegate);
            }

            var messageContext = new MessageContext(pipelineService);

            messageContext.Pipeline = this;
            var dictContent = record.Content as IDictionary <string, object>;

            if (dictContent == null)
            {
                throw new ArgumentException(string.Format(Properties.Strings.ContentShouldBeType,
                                                          nameof(IDictionary <string, object>)));
            }
            var messageContent = dictContent.Values;
            var methodTypes    = method.GetParameters().Select(p => p.ParameterType);
            var values         = methodTypes.Zip(messageContent, (mt, mc) => TypeHelpers.ConvertType(mc, mt));

            var queryParameters = CreateMessage(@delegate, values.ToArray());

            messageContext.Items[QueryParametersKey] = queryParameters;
            messageContext.Content = dictContent;
            return(messageContext);
        }
        /// <inheritdoc />
        public virtual IQueryCaller <TQuery> Query <TQuery>(IMessagePipelineService pipelineService, TQuery obj) where TQuery : class
        {
            var messageContext = new MessageContext(pipelineService, obj);

            messageContext.ContentId = TypeHelpers.GetPartiallyAssemblyQualifiedName(typeof(TQuery));
            messageContext.Pipeline  = this;
            return(new QueryCaller <TQuery>(this, messageContext, obj));
        }
        /// <summary>
        /// Handle command within message context.
        /// </summary>
        /// <param name="pipelineService">Pipelines service.</param>
        /// <param name="command">Command to execute.</param>
        /// <returns>Message context used in execution.</returns>
        public static IMessageContext HandleCommand(this IMessagePipelineService pipelineService, object command)
        {
            var pipeline       = pipelineService.GetPipelineOfType <ICommandPipeline>();
            var messageContext = pipeline.CreateMessageContext(pipelineService, command);

            pipeline.Invoke(messageContext);
            return(messageContext);
        }
 public CompaniesController(IMessagePipelineService pipelineService, CompanyQueries companyQueries)
 {
     if (pipelineService == null)
     {
         throw new ArgumentNullException(nameof(pipelineService));
     }
     this.pipelineService = pipelineService;
     this.companyQueries  = companyQueries;
 }
        /// <summary>
        /// Remove pipeline of specified type or throw exception.
        /// </summary>
        /// <typeparam name="T">Pipeline type.</typeparam>
        /// <param name="pipelinesService">Pipelines service.</param>
        public static void RemovePipelineOfType <T>(this IMessagePipelineService pipelinesService)
            where T : class, IMessagePipeline
        {
            var pipeline = GetPipelineOfType <T>(pipelinesService);
            var list     = pipelinesService.PipelineContainer.Pipelines.ToList();

            list.Remove(pipeline);
            pipelinesService.PipelineContainer.Pipelines = list.ToArray();
        }
示例#13
0
 public ManageController(
     IMessagePipelineService pipelineService,
     ILoggerFactory loggerFactory,
     SignInManager <User, string> signInManager,
     Domain.UserContext.Queries.UsersQueries userQueries) :
     base(pipelineService, loggerFactory)
 {
     this.signInManager = signInManager;
     this.userQueries   = userQueries;
 }
        /// <summary>
        /// Handle command within message context.
        /// </summary>
        /// <param name="pipelineService">Pipelines service.</param>
        /// <param name="command">Command to execute.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>Message context used in execution.</returns>
        public static async Task <IMessageContext> HandleCommandAsync(this IMessagePipelineService pipelineService,
                                                                      object command,
                                                                      CancellationToken cancellationToken = default(CancellationToken))
        {
            var commandPipeline = pipelineService.GetPipelineOfType <ICommandPipeline>();
            var messageContext  = commandPipeline.CreateMessageContext(pipelineService, command);
            await commandPipeline.InvokeAsync(messageContext, cancellationToken);

            return(messageContext);
        }
        /// <inheritdoc />
        public IMessageContext CreateMessageContext(IMessagePipelineService pipelineService, MessageRecord record)
        {
            var context = new MessageContext(pipelineService)
            {
                ContentId = record.ContentType,
                Content   = record.Content,
                Pipeline  = this
            };

            return(context);
        }
示例#16
0
        public void OneTimeSetUp()
        {
            var builder = CommonDIConfig.CreateBuilder();

            Container = builder.Build();

            pipelineService = Container.Resolve <IMessagePipelineService>();
            using (var uow = Container.Resolve <IAppUnitOfWork>())
            {
                CreateAdmin(uow);
            }
        }
        public AdminController(IMessagePipelineService pipelineService, UserQueries userQueries)
        {
            if (pipelineService == null)
            {
                throw new ArgumentNullException(nameof(pipelineService));
            }
            if (userQueries == null)
            {
                throw new ArgumentNullException(nameof(userQueries));
            }

            this.commandPipeline = pipelineService;
            this.userQueries     = userQueries;
        }
        public ProductsController(IMessagePipelineService pipelineService, ProductQueries productQueries, CompanyQueries companyQueries)
        {
            if (pipelineService == null)
            {
                throw new ArgumentNullException(nameof(pipelineService));
            }
            if (productQueries == null)
            {
                throw new ArgumentNullException(nameof(productQueries));
            }

            this.productQueries  = productQueries;
            this.pipelineService = pipelineService;
            this.companyQueries  = companyQueries;
        }
        /// <summary>
        /// Get pipeline of specified type or throw exception.
        /// </summary>
        /// <typeparam name="T">Type of pipeline.</typeparam>
        /// <param name="pipelineService">Pipelines service.</param>
        /// <returns>Pipeline.</returns>
        public static T GetPipelineOfType <T>(this IMessagePipelineService pipelineService)
            where T : class, IMessagePipeline
        {
            var container = pipelineService.PipelineContainer;

            for (int i = 0; i < container.Pipelines.Length; i++)
            {
                var pipeline = container.Pipelines[i] as T;
                if (pipeline != null)
                {
                    return(pipeline);
                }
            }
            throw new InvalidOperationException($"Cannot find {typeof(T)} pipeline. Make sure you called correct " +
                                                " Add{X}Pipeline extension method.");
        }
        /// <inheritdoc />
        public IMessageContext CreateMessageContext(IMessagePipelineService pipelineService, object command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var mc = new MessageContext(pipelineService)
            {
                Content   = command,
                ContentId = TypeHelpers.GetPartiallyAssemblyQualifiedName(command.GetType()),
                Pipeline  = this
            };

            return(mc);
        }
示例#21
0
        /// <summary>
        /// Handle user registration.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="pipelineService">Pipeline service.</param>
        public async Task HandleRegisterUser(
            RegisterUserCommand command,
            IMessagePipelineService pipelineService)
        {
            using (var uow = uowFactory.Create())
            {
                var email = command.Email.ToLowerInvariant().Trim();
                if (uow.UserRepository.Any(x => x.Email == email))
                {
                    throw new DomainException("The user with the same email already exists.");
                }

                var user = new User
                {
                    FirstName = command.FirstName,
                    LastName  = command.LastName,
                    City      = command.City,
                    BirthDay  = command.BirthDay,
                    Country   = command.Country,
                    Email     = command.Email,
                    UserName  = email,
                };
                if (command.UserId != Guid.Empty)
                {
                    user.Id = command.UserId.ToString();
                }
                user.Clean();
                command.Result = await userManager.CreateAsync(user, command.Password);

                if (!command.Result.Succeeded)
                {
                    throw new IdentityException(command.Result);
                }

                await pipelineService.RaiseEventAsync(new UserCreatedEvent
                {
                    User = user,
                });

                command.User = user;
                logger.LogInformation($"User {user.FirstName} {user.LastName} with id {user.Id} has been registered.");
            }
        }
 /// <inheritdoc />
 public IQueryCaller <TQuery> CreateMessageContext <TQuery>(IMessagePipelineService pipelineService,
                                                            IMessageContext messageContext) where TQuery : class
 {
     return(new QueryCaller <TQuery>(this, messageContext).NoExecution());
 }
示例#23
0
 public UserController(IMessagePipelineService pipelineService, UserQueries userQueries)
 {
     this.pipelineService = pipelineService;
     this.userQueries     = userQueries;
 }
示例#24
0
 public ProjectController(
     IMessagePipelineService pipelinesService,
     ILoggerFactory loggerFactory) :
     base(pipelinesService, loggerFactory)
 {
 }
示例#25
0
 /// <summary>
 /// Constuctor of the <seealso cref="UsersController"/> class.
 /// </summary>
 /// <param name="pipelineService">Pipeline service.</param>
 /// <param name="userManager">User manager.</param>
 public UsersController(IMessagePipelineService pipelineService, UserManager <User> userManager)
 {
     this.pipelineService = pipelineService ?? throw new ArgumentNullException(nameof(pipelineService));
     this.userManager     = userManager ?? throw new ArgumentNullException(nameof(userManager));
 }
示例#26
0
 /// <summary>
 /// Constructor of the <seealso cref="AccountController"/> class.
 /// </summary>
 /// <param name="pipelineService">Pipeline service.</param>
 /// <param name="tokenGenerator">Token generator.</param>
 /// <param name="userManager">User manager.</param>
 public AccountController(IMessagePipelineService pipelineService, ITokenGenerator tokenGenerator, UserManager <User> userManager)
 {
     this.pipelineService = pipelineService ?? throw new ArgumentNullException(nameof(pipelineService));
     this.tokenGenerator  = tokenGenerator ?? throw new ArgumentNullException(nameof(tokenGenerator));
     this.userManager     = userManager ?? throw new ArgumentNullException(nameof(userManager));
 }
示例#27
0
 public void SetUp()
 {
     container       = GlobalConfig.Container;
     pipelineService = container.Resolve <IMessagePipelineService>();
 }
示例#28
0
 /// <summary>
 /// Consructor of the <seealso cref="MoviesController"/>.
 /// </summary>
 public MoviesController(IMessagePipelineService pipelineService)
 {
     this.pipelineService = pipelineService ?? throw new ArgumentNullException(nameof(pipelineService));
 }
 public ApiTaskController(
     IMessagePipelineService pipelineService,
     ILoggerFactory loggerFactory) : base(pipelineService, loggerFactory)
 {
 }