Beispiel #1
0
        private void RespondWithInvalidItemDescription(IRespondWithSuccessOrError <CreateTodoOutput, ErrorOutputMessage> presenter)
        {
            var errors = new ErrorOutputMessage();

            errors.AddError("ItemDescription cannot be empty or null");
            presenter.Respond(errors);
        }
Beispiel #2
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var sagaWithCompenstate = new SagaBuilder <TestContext>()
                                      .With_Context_State(context)
                                      .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Add_Numbers(ctx);
                ctx.AddError("error adding two numbers");
            }))
                                      .With_Error_Behavior(Domain.Saga.ErrorBehavior.Terminate) // could be Terminate so saga halts at this step
                                      .Using_Step(new Func <TestContext, Task>(async(ctx) =>
            {
                await Add_Numbers(ctx);
            }))
                                      .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                           (err) =>
            {
                presenter.Respond(err);
            });

            sagaWithCompenstate.Run();
        }
        public void RespondWithErrorMessage(string message, IRespondWithSuccessOrError <CreateCommentOutput, ErrorOutputMessage> presenter)
        {
            var errorOutputMessage = new ErrorOutputMessage();

            errorOutputMessage.AddError(message);
            presenter.Respond(errorOutputMessage);
        }
        public void Execute(string input, IRespondWithSuccessOrError <string, ErrorOutputTo> presenter)
        {
            var processStartInfo = _processPipeLineTask.CommandToExecute();

            using (var process = _processFactory.CreateProcess(processStartInfo))
            {
                process.Start();

                var outputTask = process.ReadStdOutToEndAsync();
                var errorTask  = process.ReadStdErrToEndAsync();

                process.WriteToStdInput(input);

                process.WaitForExit();

                var error = errorTask.Result;
                if (!string.IsNullOrWhiteSpace(error))
                {
                    var errorOutputTo = new ErrorOutputTo();
                    errorOutputTo.AddError(error);
                    presenter.Respond(errorOutputTo);
                    return;
                }
                presenter.Respond(outputTask.Result);
            }
        }
Beispiel #5
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var workflowResult = new SagaBuilder <TestContext>()
                                 .With_Context_State(context)
                                 .Using_Step(_addTask)
                                 .Using_Step(_plusTenTask)
                                 .Using_Step((ctx) =>
            {
                var input = new TestInput
                {
                    a = ctx.Value1,
                    b = ctx.Result
                };
                var propertyPresenter = new PropertyPresenter <TestResult, ErrorOutput>();
                _useCase.Execute(input, propertyPresenter);
                if (propertyPresenter.IsErrorResponse())
                {
                    throw new Exception();
                }
                ctx.Result = propertyPresenter.SuccessContent.Result;
            })
                                 .With_Finish_Actions(Respond_With_Success(presenter), Respond_With_Error(presenter))
                                 .Run();
        }
Beispiel #6
0
 private static Action <TestContext> Respond_With_Success(IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter) => (TestContext ctx) =>
 {
     presenter.Respond(new TestResult
     {
         Result = ctx.Result
     });
 };
Beispiel #7
0
        private static void RepsondWithNullFilter(IRespondWithSuccessOrError <List <TodoTo>, ErrorOutputMessage> presenter)
        {
            var errors = new ErrorOutputMessage();

            errors.AddError("Null filter object");
            presenter.Respond(errors);
        }
Beispiel #8
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var workflowResult = new SagaBuilder <TestContext>()
                                 .With_Context_State(context)
                                 .Using_Step(_addTask)
                                 .Using_Step(_addWithDiTask)
                                 .With_Roll_Back_Action_On_Error((ctx) =>
            {
                presenter.Respond(new ErrorOutput("Error on step 2"));
            })
                                 .With_Finish_Action((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            })
                                 .Run();
        }
Beispiel #9
0
        public void Execute(RangedStatsInput inputTo, IRespondWithSuccessOrError <CodeAnalysis, ErrorOutputMessage> presenter)
        {
            using (var repo = _builder
                              .WithPath(inputTo.Path)
                              .WithRange(inputTo.RangeState, inputTo.RangeEnd)
                              .WithIgnorePatterns(inputTo.IgnorePatterns)
                              .WithBranch(inputTo.Branch)
                              .WithWorkingDaysPerWeek(inputTo.DaysPerWeek)
                              .WithWorkingWeekHours(inputTo.HoursPerWeek)
                              .WithIgnoreComments(inputTo.IgnoreComments)
                              .WithAliasMapping(inputTo.AliasFile)
                              .WithWeekends(inputTo.WeekendDays)
                              .Build())
            {
                //var authors = repo.List_Authors();
                //var stats = repo.Build_Individual_Developer_Stats(authors);
                //var dailyDeveloperStats = repo.Build_Daily_Individual_Developer_Stats(authors);

                //var teamStats = repo.Build_Team_Stats();

                //var result = new StatsOutput
                //{
                //    Authors = authors,
                //    DeveloperStats = stats,
                //    DailyDeveloperStats = dailyDeveloperStats,
                //    TeamStats = teamStats,
                //    ReportingRange = repo.ReportingRange
                //};

                var codeAnalysis = repo.Run_Analysis();

                presenter.Respond(codeAnalysis);
            }
        }
        private void Respond_With_File(RenderWordInput inputTo,
                                       IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter,
                                       RenderedDocumentOutput result)
        {
            var reportMessage = new WordFileOutput(inputTo.ReportName, result.FetchDocumentAsByteArray());

            presenter.Respond(reportMessage);
        }
        private void Respond_With_Errors(IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter,
                                         RenderedDocumentOutput output)
        {
            var errorOutput = new ErrorOutput();

            errorOutput.AddErrors(output.ErrorMessages);
            presenter.Respond(errorOutput);
        }
Beispiel #12
0
        public async Task Execute(Cities inputTo, IRespondWithSuccessOrError <int, ErrorOutput> presenter)
        {
            //Todo: Is this correct?
            //Todo: Is there a different way of doing this?
            var cityCode = await _country.Fetch_City_Code(inputTo.City, inputTo.State, inputTo.Country);

            presenter.Respond(cityCode);
        }
Beispiel #13
0
        private void RespondWithSuccess(IRespondWithSuccessOrError <CreateTodoOutput, ErrorOutputMessage> presenter, CreateTodoOutput output)
        {
            var outputMessage = new CreateTodoOutput {
                Id = output.Id
            };

            presenter.Respond(outputMessage);
        }
        private void RenderReport(ReportGenerationArguments arguments,
                                  Func <string, ReportGenerationArguments, NodePipeLineTask> taskFactory,
                                  IRespondWithSuccessOrError <string, ErrorOutput> presenter)
        {
            var nodeAppPath = Fetch_NodeApp_Path(_options.NodeApp);

            var task = taskFactory.Invoke(nodeAppPath, arguments);

            var executor = new SynchronousAction(task, new ProcessFactory());

            executor.Execute(presenter);
        }
Beispiel #15
0
        public void Execute(TodoFilterInput inputTo, IRespondWithSuccessOrError <List <TodoTo>, ErrorOutputMessage> presenter)
        {
            if (inputTo == null)
            {
                RepsondWithNullFilter(presenter);
                return;
            }

            var filteredCollection = FetchFilteredCollection(inputTo);

            presenter.Respond(filteredCollection);
        }
        public void Render(Func <TSuccessInner, TSuccessOuter> conversionFunc, IRespondWithSuccessOrError <TSuccessOuter, TError> presenter)
        {
            if (_errors != null)
            {
                presenter.Respond(_errors);
                return;
            }

            var conversionResult = conversionFunc.Invoke(_output);

            presenter.Respond(conversionResult);
        }
        public void Execute(RenderWordInput inputTo,
                            IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter)
        {
            var result = _wordGateway.CreateWordReport(inputTo);

            if (result.HasErrors())
            {
                Respond_With_Errors(presenter, result);
                return;
            }

            Respond_With_File(inputTo, presenter, result);
        }
        public void Execute(RenderPdfInput inputTo,
                            IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter)
        {
            var output = _pdfGateway.ConvertToPdf(inputTo);

            if (Render_Errors(output))
            {
                Respond_With_Errors(presenter, output);
                return;
            }

            Respond_With_Pdf(inputTo, presenter, output);
        }
        public void Execute(RenderExcelInput inputInput,
                            IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter)
        {
            var result = _reportGateway.CreateExcelReport(inputInput);

            if (result.HasErrors())
            {
                Respond_With_Errors(presenter, result);
                return;
            }

            Respond_With_File(inputInput, presenter, result);
        }
Beispiel #20
0
        public async Task Execute(Cities inputTo, IRespondWithSuccessOrError <Cities, ErrorOutput> presenter)
        {
            try
            {
                var city = await _country.Fetch_City_Code(inputTo.City, inputTo.State, inputTo.Country);

                presenter.Respond(city);
            }
            catch (Exception ex)
            {
                presenter.Respond(new ErrorOutput(ex.Message));
            }
        }
Beispiel #21
0
        public void Execute(CreateTodoInput inputTo, IRespondWithSuccessOrError <CreateTodoOutput, ErrorOutputMessage> presenter)
        {
            var domainEntity = MapInputToDomainEntity(inputTo);

            if (InvalidItemDescription(domainEntity))
            {
                RespondWithInvalidItemDescription(presenter);
                return;
            }

            var output = Persist(inputTo);

            RespondWithSuccess(presenter, output);
        }
Beispiel #22
0
        public async Task Execute(Cities inputTo, IRespondWithSuccessOrError <CurrentWeather, ErrorOutput> presenter)
        {
            try
            {
                var city = await _country.Fetch_City_Code(inputTo.City, inputTo.State, inputTo.Country);

                var currentWeather = await _weather.Fetch_Weather_For_Today(city.CityId);

                presenter.Respond(currentWeather);
            }
            catch (Exception ex)
            {
                presenter.Respond(new ErrorOutput(ex.Message));
            }
        }
Beispiel #23
0
        public void Execute(TestInput inputTo, IRespondWithSuccessOrError <TestResult, ErrorOutput> presenter)
        {
            var context = new TestContext
            {
                Value1 = inputTo.a,
                Value2 = inputTo.b
            };

            var sagaWithoutCompenstate = new SagaBuilder <TestContext>()
                                         .With_Context_State(context)
                                         .Using_Step(_addTask)
                                         .Using_Step(_errorTask)
                                         .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                              (err) =>
            {
                presenter.Respond(err);
            });

            var sagaWithCompenstate = new SagaBuilder <TestContext>()
                                      .With_Context_State(context)
                                      .Using_Step(_addTask)
                                      .With_Error_Behavior(Domain.Saga.ErrorBehavior.Continue) // could be Terminate so saga halts at this step
                                      .Using_Step(_errorTask)
                                      .With_Roll_Back_Action_On_Error((ctx) =>
            {
                ctx.Result -= 10;
            })
                                      .With_Finish_Actions((ctx) =>
            {
                presenter.Respond(new TestResult
                {
                    Result = ctx.Result
                });
            },
                                                           (err) =>
            {
                presenter.Respond(err);
            });

            sagaWithCompenstate.Run();
            //sagaWithoutCompenstate.Run();
        }
Beispiel #24
0
        public void Execute(RenderWordInput inputTo, IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter)
        {
            var wordPresenter = new PropertyPresenter <IFileOutput, ErrorOutput>();

            _wordUsecase.Execute(inputTo, wordPresenter);

            if (wordPresenter.IsErrorResponse())
            {
                presenter.Respond(wordPresenter.ErrorContent);
                return;
            }

            var pdfInput = Create_Pdf_Input(wordPresenter);

            _pdfUsecase.Execute(pdfInput, presenter);
        }
        public void Execute(RandomPersonInput inputTo, IRespondWithSuccessOrError <InnerTestObject, ErrorOutput> presenter)
        {
            if (inputTo.ForceError)
            {
                var errors = new ErrorOutput();
                errors.AddError("Forced error happened");
                presenter.Respond(errors);
                return;
            }

            var random = new Random(11223);

            presenter.Respond(new InnerTestObject
            {
                Age       = random.Next(inputTo.MinAge, inputTo.MaxAge),
                FirstName = "Test",
                LastName  = "User"
            });
        }
Beispiel #26
0
        public void Execute(string input, IRespondWithSuccessOrError <string, ErrorOutput> presenter)
        {
            var processStartInfo = _processPipeLineTask.CommandToExecute();

            try
            {
                using (var process = _processFactory.CreateProcess(processStartInfo))
                {
                    process.Start();

                    var readerTask = process.ReadStdOutToEndAsync();
                    var errorTask  = process.ReadStdErrToEndAsync();

                    process.WriteToStdInput(input);

                    process.WaitForExit(_processPipeLineTask.ProcessTimeout());

                    if (process.TimeoutOccured)
                    {
                        var errorOutput = new ErrorOutput();
                        errorOutput.AddError($"The process timed out after waiting [{_processPipeLineTask.ProcessTimeout()}] seconds.");
                        return;
                    }

                    var error = errorTask.Result;
                    if (HasError(error))
                    {
                        var errorOutput     = new ErrorOutput();
                        var trimedArugments = processStartInfo.Arguments.Substring(3);
                        errorOutput.AddError($"Failed to execute {trimedArugments}");
                        errorOutput.AddError(error);
                        presenter.Respond(errorOutput);
                        return;
                    }

                    presenter.Respond(readerTask.Result);
                }
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to execute [{processStartInfo.FileName}] with [{processStartInfo.Arguments}]", e);
            }
        }
        public void Execute(CreateCommentInput inputTo, IRespondWithSuccessOrError <CreateCommentOutput, ErrorOutputMessage> presenter)
        {
            var domainEntity = CreateDomainModelFromInput(inputTo);

            if (InvalidTodoItemId(domainEntity))
            {
                RespondWithErrorMessage("Invalid item Id", presenter);
                return;
            }

            if (InvalidComment(domainEntity))
            {
                RespondWithErrorMessage("Missing comment", presenter);
                return;
            }

            var output = Persist(inputTo);

            RespondWithSuccess(output, presenter);
        }
 private void Respond_With_Pdf(RenderPdfInput inputTo,
                               IRespondWithSuccessOrError <IFileOutput, ErrorOutput> presenter,
                               RenderedDocumentOutput output)
 {
     presenter.Respond(new PdfFileOutput(inputTo.FileName, output.FetchDocumentAsByteArray()));
 }
        public async Task Execute(string inputTo, IRespondWithSuccessOrError <List <Domain.Classes.Weather>, ErrorOutput> presenter)
        {
            var res = await _forecasts.FetchForecast(inputTo);

            presenter.Respond(res);
        }
Beispiel #30
0
 public void Execute(CountryCodeRequest inputTo, IRespondWithSuccessOrError <string, ErrorOutput> presenter)
 {
     presenter.Respond(_countryCodes.FetchCountryCode(inputTo));
 }