Beispiel #1
0
        public async Task <ILiveResult <TResult> > Execute <TQuery, TResult>(TQuery query, QueryOptions options = null)
            where TQuery : IQuery <TModel, TResult>
            where TResult : class
        {
            var schema           = _querySchemaRegister.GetByQueryType(typeof(TQuery));
            var projectionSchema = _projectionSchemaRegister.FindByModelType(typeof(TModel));

            var queryHandler    = _serviceProvider.GetRequiredService <IQueryHandler <TQuery, TModel, TResult> >();
            var queryParitioner = GetQueryPartitioner <TQuery, TResult>();

            var partitionId = queryParitioner?.CalculatePartition(query);

            LiveQuery <TQuery, TModel, TResult> liveQuery = new LiveQuery <TQuery, TModel, TResult>(query, partitionId, queryHandler, schema, OnQueryDispose, options);

            var streamInfo = _partitions.GetOrAdd(partitionId.HasValue ? partitionId.Value : _rootPartitionId, pid => new DataPartitionStream <TModel>(pid, this, _subscriptionController, projectionSchema, !partitionId.HasValue));

            await streamInfo.Catchup();

            streamInfo.AppendQuery(liveQuery);

            _liveQueries.TryAdd(liveQuery.Query, liveQuery);

            // HACK
            if (liveQuery.Options.ExpectNotNull)
            {
                while (liveQuery.Result == null)
                {
                    liveQuery.Load(GetModel());
                    await Task.Delay(100);
                }
            }

            return(liveQuery);
        }
 public EventAggregatorModelProjectionSubscriber(IEventAggregator eventAggregator,
                                                 IProjectionSchemaRegister projectionSchemaRegister)
 {
     _pubSubEvent = eventAggregator.GetEvent <PubSubEvent <ProjectionEvent <TProjection> > >();
     _schema      = projectionSchemaRegister.FindByModelType(typeof(TModel));
 }
Beispiel #3
0
 public ProjectionExecutor(IProjectionSchemaRegister projectionSchema, IServiceProvider serviceProvider, ILogger logger)
 {
     _serviceProvider = serviceProvider;
     _logger          = logger;
     _schema          = projectionSchema.FindByModelType(typeof(TModel));
 }