Exemplo n.º 1
0
        public virtual TResponse Run <TResponse>
        (
            ITasq <TResponse> tasq
        )
        {
            TResponse retVal;

            OnLog?.Invoke(this, TasqProcess.Start, new LogEventHandlerEventArgs(tasq));

            var resolvedHandler = GetHandlerDetail(tasq);

            OnLog?.Invoke(this, TasqProcess.Start, new LogEventHandlerEventArgs(resolvedHandler.Handler));

            if (resolvedHandler.Handler is TasqHandlerAsync)
            {
                retVal = RunAsync(tasq).Result;
            }
            else
            {
                TasqHandler tasqHandlerInstance = (TasqHandler)resolvedHandler.Handler;


                tasqHandlerInstance.Initialize(tasq);
                tasqHandlerInstance.BeforeRun(tasq);
                retVal = (TResponse)tasqHandlerInstance.XRun(null, tasq);
                tasqHandlerInstance.AfterRun(tasq);
            }

            return(retVal);
        }
Exemplo n.º 2
0
        public virtual IEnumerable <TResponse> Run <TKey, TResponse>
        (
            ITasq <TKey, TResponse> tasq
        )
        {
            OnLog?.Invoke(this, TasqProcess.Start, new LogEventHandlerEventArgs(tasq));

            var resolvedHandler = GetHandlerDetail(tasq);

            OnLog?.Invoke(this, TasqProcess.Start, new LogEventHandlerEventArgs(resolvedHandler.Handler));

            if (resolvedHandler.Handler is TasqHandlerAsync)
            {
                return(RunAsync(tasq).Result);
            }

            TasqHandler tasqHandlerInstance = (TasqHandler)resolvedHandler.Handler;

            List <TResponse> retVal = new List <TResponse>();

            tasqHandlerInstance.Initialize(tasq);
            tasqHandlerInstance.BeforeRun(tasq);

            var selectionCriteria = tasqHandlerInstance.SelectionCriteria(tasq);

            if (selectionCriteria != null)
            {
                foreach (var eachSelection in selectionCriteria)
                {
                    var result = (TResponse)tasqHandlerInstance.XRun(eachSelection, tasq);

                    retVal.Add(result);
                }
            }

            tasqHandlerInstance.AfterRun(tasq);


            return(retVal);
        }