Beispiel #1
0
        public async Task <TResult> ExecuteAsync <TResult>(
            Func <TResult> success,
            Func <TFailure, TResult> failed)
        {
            var results = await Tasks
                          .Select(async task =>
            {
                var rollbackResult = await task.Invoke(
                    (rollback) => RollbackResult.Success(rollback),
                    (failureResultReturned) => RollbackResult.Failure(failureResultReturned));
                return(rollbackResult);
            })
                          .WhenAllAsync();

            var resultGlobal = await results.FirstOrDefault(
                result => result.IsFailure,
                async (failedResult) =>
            {
                await results.Select(result => result.Rollback()).RunAllAsync();
                return(failed(failedResult.FailureResult));
            },
                async() =>
            {
                return(await success().ToTask());
            });

            return(resultGlobal);
        }
        public GlobalJsonResult <RollbackResult> RollbackComponentsForVersion([FromBody] RollbackRequest request)
        {
            installation.RollbackInstallationVersion(request.FailedInstallationComponentId, Version.Parse(request.FailedInstallationVersion));
            var version = installation.GetCurrentVersion();

            var result = new RollbackResult();

            result.PopulateFrom(version);

            return(GlobalJsonResult <RollbackResult> .Success(System.Net.HttpStatusCode.NoContent, result));
        }