Exemple #1
0
        public UseCaseHandler <TOutput> Execute(UseCaseHandler <TOutput> handler)
        {
            ExecutingTask = Task.Run(async() =>
            {
                handler.OnStart?.Invoke();

                try
                {
                    var result = await GetUseCaseTask();

                    //TODO: remove this.
                    await Task.Delay(3000);

                    handler.Result = result;
                    handler.OnComplete?.Invoke(result);
                }
                catch (Exception e)
                {
                    handler.OnError?.Invoke(e);
                }
            });

            handler.ExecutingTask = ExecutingTask;

            return(handler);
        }
Exemple #2
0
        public UseCaseHandler <M> FromResult <M>(NextAction <M> action, UseCaseHandler <M> callbackHandler)
        {
            M   result      = default;
            var nextHandler = new UseCaseHandler <M>();

            nextHandler.ExecutingTask = ExecutingTask?.ContinueWith(t =>
            {
                callbackHandler.OnStart?.Invoke();

                try
                {
                    result = action.Invoke(Result);

                    callbackHandler.OnComplete?.Invoke(result);
                }
                catch (Exception e)
                {
                    callbackHandler.OnError?.Invoke(e);
                }

                nextHandler.Result = result;
            });

            return(nextHandler);
        }
Exemple #3
0
        public UseCaseHandler <TOutput> Execute(UseCaseHandler <TOutput> .OnCompleteCallback <TOutput> onComplete = null,
                                                UseCaseHandler <TOutput> .OnErrorCallback onError = null,
                                                UseCaseHandler <TOutput> .OnStartCallback onStart = null)
        {
            var handler = new UseCaseHandler <TOutput>()
            {
                OnComplete = onComplete,
                OnError    = onError,
                OnStart    = onStart
            };

            return(Execute(handler));
        }