Пример #1
0
        public Task <TResult> ProcessQuery <TQuery, TResult>(TQuery query) where TQuery : IAsyncQuery <object>
        {
            IScheduler scheduler;

            if (Schedulers.TryGetValue(typeof(TQuery), out scheduler))
            {
                return(scheduler.Run(() => _queryBus.ProcessQuery <TQuery, TResult>(query)));
            }
            if (DefaultScheduler != null)
            {
                return(DefaultScheduler.Run(() => _queryBus.ProcessQuery <TQuery, TResult>(query)));
            }
            return(_queryBus.ProcessQuery <TQuery, TResult>(query));
        }
Пример #2
0
 public async Task <TResult> ProcessQuery <TQuery, TResult>(TQuery query) where TQuery : IAsyncQuery <object>
 {
     if (query.IsAssignableTo <ICacheInfos>())
     {
         var cacheInfo = (ICacheInfos)query;
         return(await _cacheService.ExecuteWithCache(
                    query.CancellationToken,
                    cacheInfo.Key,
                    () => _asyncQueryBus.ProcessQuery <TQuery, TResult>(query),
                    _defaultAge,
                    cacheInfo.Attributes));
     }
     return(await _asyncQueryBus.ProcessQuery <TQuery, TResult>(query));
 }
Пример #3
0
 private async Task Request(string s, CancellationToken ct, IAsyncQueryBus bus)
 {
     await Services.Schedulers.ThreadPool.Run(async() =>
     {
         var query = new BingQuery(ct)
         {
             Query = s
         };
         var result = await bus.ProcessQuery <BingQuery, string>(query);
         Debug.WriteLine(result);
     });
 }
Пример #4
0
        public async Task <TResult> ProcessQuery <TQuery, TResult>(TQuery query) where TQuery : IAsyncQuery <object>
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                return(await _innerQueryBus.ProcessQuery <TQuery, TResult>(query));
            }
            finally
            {
                stopwatch.Stop();
                Debug.WriteLine("Query {1} time : {0}", stopwatch.Elapsed, typeof(TQuery));
            }
        }
Пример #5
0
 public Task <TResult> ProcessQuery <TQuery, TResult>(TQuery query) where TQuery : IAsyncQuery <object>
 {
     try
     {
         _queryStarted.OnNext(query);
         var result = _queryBus.ProcessQuery <TQuery, TResult>(query);
         _queryEnded.OnNext(new Tuple <IAsyncQuery <object>, object>(query, result));
         return(result);
     }
     catch (Exception ex)
     {
         _queryError.OnNext(new Tuple <IAsyncQuery <object>, Exception>(query, ex));
         throw;
     }
 }
Пример #6
0
 private ICommand GetTestQueryCommandWithCache()
 {
     return(this.CommandBuilder("TestQueryCommandWithCache")
            .Execute <string>(async(query, ct) =>
     {
         var queries = Enumerable.Range(0, 10)
                       .Select(_ => Task.Run(() => _busWithCache.ProcessQuery <BingQuery, string>(new BingQuery(ct, query))));
         var results = await Task.WhenAll(queries);
         foreach (var result in results)
         {
             result.DebugWriteline();
         }
     })
            .Error((token, exception) => Task.FromResult(true))
            .ToCommand());
 }
Пример #7
0
        public async Task <TResult> ProcessQuery <TQuery, TResult>(TQuery query) where TQuery : IAsyncQuery <object>
        {
            Debug.WriteLine("[QUERY]   [START] {0}", query);
            try
            {
                var result = await _innerQueryBus.ProcessQuery <TQuery, TResult>(query);

                Debug.WriteLine("[QUERY]   [END]   {0}", query);
                return(result);
            }
            catch (Exception ex)
            {
                //prevent writing an exception multiple times
                Exception existing;
                if (!_catchedExceptions.TryGetValue(ex, out existing))
                {
                    _catchedExceptions.Add(ex, ex);
                    Debug.WriteLine("[QUERY]   [ERROR] {0}\n{1}", query, ex);
                }
                throw;
            }
        }