public ActionResultFaultlessExecutionService(FaultlessExecution.Abstractions.IFaultlessExecutionService faultlessExecutionService,
                                              Microsoft.Extensions.Logging.ILogger <ActionResultFaultlessExecutionService> logger)
 {
     _faultlessExecutionService           = faultlessExecutionService;
     _faultlessExecutionService.LogErrors = false;//bypass the built in error log, we'll log the errors ourself
     _logger = logger;
 }
예제 #2
0
        public void Load()
        {
            this.PeopleList = new ObservableCollection <DemoServices.Person>();
            this.CityList   = new ObservableCollection <DemoServices.City>();
            this.AnswerList = new ObservableCollection <DemoServices.Answer>();
            this.ErrorList  = new ObservableCollection <string>();

            if (UseGenericExceptionHandler)
            {
                _faultlessExecutionService = new ShowMessageBoxFaultlesExecutionService(); //this demonstrates how you might write a generic handler so that you don't need to worry about writing .onexeption handlers for all your calls
            }
            else
            {
                _faultlessExecutionService = new FaultlessExecution.FaultlessExecutionService();
            }

            //simple example of testing that something did not error
            var peopleResult = _faultlessExecutionService.TryExecute(() => _database.GetAllThePeopleInTheWorld());

            if (peopleResult.WasSuccessful)
            {
                LoadPersonList(peopleResult.ReturnValue);
            }
            else
            {
                HandleException(peopleResult.Exception);
            }

            //example of using OnException and/or OnSuccess to perform actions based on whether the call was successful or not
            _faultlessExecutionService.TryExecute(() => _webApi.GetSomeCities())
            .OnException((r) => this.HandleException(r.Exception))
            .OnSuccess((r) => this.LoadCityList(r.ReturnValue));

            //example of using the retry logic to rerun the action if it failed
            var cloudResult = _faultlessExecutionService.TryExecute(() => _cloud.GetAllTheAnswers())
                              .Retry(numberOfRetries: 3)
                              .OnException((r) => this.HandleException(r.Exception));

            if (cloudResult.WasSuccessful)
            {
                this.LoadAnswerList(cloudResult.ReturnValue);
            }

            //example of using the retryIf logic to rerun the action if some condition is met
            _faultlessExecutionService.TryExecute(() => _fileSystem.CheckAllOfYourFiles())
            .RetryOnceIf((result) => result.Exception is TimeoutException)
            .OnException((r) => this.HandleException(r.Exception));
        }