コード例 #1
0
 async Task <PipeResult <R> > IAsyncExecutor <M, R> .ExecuteAsync(
     M model,
     IPipeCache pipeCache)
 {
     Cache = pipeCache;
     return(await RunAsync(model));
 }
コード例 #2
0
        public static T GetSafely <T>(this IPipeCache cache, object key)
        {
            if (cache != null && key != null)
            {
                return(cache.Get <T>(key));
            }

            return(default);
コード例 #3
0
 public async Task <PipeResult <int> > ExecuteAsync(
     IntModel model,
     IPipeCache pipeCache = null)
 {
     model.Integer += 100;
     return(await Task.FromResult(PipeResult <int>
                                  .DefaultSuccessful
                                  .SetValue(model.Integer)));
 }
コード例 #4
0
        public async Task <PipeResult <R> > RunAsync(M model, IPipeCache cache)
        {
            if (_executorInstance == null)
            {
                _executorInstance = _executor();
            }

            return(await _executorInstance.ExecuteAsync(model, cache));
        }
コード例 #5
0
        public async Task <PipeResult <double> > ExecuteAsync(
            IntModel model,
            IPipeCache pipeCache = null)
        {
            await Task.Delay(50);

            return(PipeResult <double>
                   .DefaultSuccessful
                   .SetValue(50));
        }
コード例 #6
0
        public async Task <PipeResult <TimeSpan> > ExecuteAsync(
            IntModel model,
            IPipeCache pipeCache = null)
        {
            await Task.Delay(100);

            return(PipeResult <TimeSpan>
                   .DefaultSuccessful
                   .SetValue(TimeSpan.FromMilliseconds(100)));
        }
コード例 #7
0
        public async Task <PipeResult <R> > RunAsync(M model, IPipeCache cache)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var result = await _container.RunAsync(model, cache);

            stopWatch.Stop();
            result.SetElapsed(stopWatch.Elapsed);
            return(result);
        }
コード例 #8
0
        public async Task <PipeResult <R> > RunAsync(M model, IPipeCache cache)
        {
            var result = await _container.RunAsync(model, cache);

            if (result.Success == ExecutionResult.Failed &&
                _count > 0)
            {
                return(await ReTryAsync(model, cache));
            }
            return(result);
        }
コード例 #9
0
        public async Task <PipeResult <int> > ExecuteAsync(
            IntModel model,
            IPipeCache pipeCache = null)
        {
            _restrictionTester.IncrementCounter();
            await Task.Delay(100);

            model.Integer += 3;
            pipeCache.SetSafely <int>("3", model.Integer);
            _restrictionTester.DecrementCounter();
            return(PipeResult <int>
                   .DefaultSuccessful
                   .SetValue(model.Integer));
        }
コード例 #10
0
        public async Task <PipeResult <int> > ExecuteAsync(
            IntModel model,
            IPipeCache pipeCache = null)
        {
            var x1 = pipeCache.GetSafely <int>("1");
            var x2 = pipeCache.GetSafely <int>("2");
            var x3 = pipeCache.GetSafely <int>("3");
            var x4 = pipeCache.GetSafely <int>("4");

            model.Integer += x1 + x2 + x3 + x4;
            return(await Task.FromResult(PipeResult <int>
                                         .DefaultSuccessful
                                         .SetValue(model.Integer)));
        }
コード例 #11
0
        private async Task <PipeResult <R> > ReTryAsync(M model, IPipeCache cache)
        {
            for (int i = 0; i < _count - 1; i++)
            {
                var result = await _container.RunAsync(model, cache);

                if (result.Success == ExecutionResult.Successful)
                {
                    return(result);
                }

                await Task.Delay(_timeOutMilliseconds);
            }
            return(await _container.RunAsync(model, cache));
        }
コード例 #12
0
        public async Task <PipeResult <R> > RunAsync(M model, IPipeCache cache)
        {
            var result = PipeResult <R> .Default;

            if (_semaphore == null)
            {
                return(await _container.RunAsync(model, cache));
            }

            await _semaphore.WaitAsync();

            try
            {
                result = await _container.RunAsync(model, cache);
            }
            finally
            {
                _semaphore.Release();
            }
            return(result);
        }
コード例 #13
0
        public async Task <PipeResult <R> > RunAsync(M model, IPipeCache cache)
        {
            var result = (await _executor(model, cache));

            return(result);//.SetLabel(_label);
        }