/// <summary> /// Отлов ошибок и вызов метода асинхронно /// </summary> public static async Task <IResultValue <T> > ExecuteAndHandleErrorAsync <T>(Func <Task <T> > asyncFunc, Action beforeMethod = null, Action catchMethod = null, Action finallyMethod = null, IErrorCommon errorMessage = null) { if (asyncFunc == null) { throw new ArgumentNullException(nameof(asyncFunc)); } IResultValue <T> result; try { beforeMethod?.Invoke(); result = new ResultValue <T>(await asyncFunc.Invoke()); } catch (Exception exception) { catchMethod?.Invoke(); result = new ErrorCommon(GetTypeException(exception), String.Empty, exception). ToResultValue <T>(). ConcatErrors(errorMessage); } finally { finallyMethod?.Invoke(); } return(result); }
public void ChangeAllFilesStatusAndSetError(IErrorCommon errorStatus) { FilesQueueInfo = new FilesQueueInfo(); var fileData = _filesData.Select(file => new FileStatus(file.FilePath, StatusProcessing.End, errorStatus)); var filesStatus = new PackageStatus(fileData, StatusProcessingProject.End); ChangeFilesStatus(filesStatus); }
/// <summary> /// Отобразить сообщение /// </summary> public void ShowError(IErrorCommon errorConverting) => errorConverting?. Map(error => new List <string>() { "Ошибка | " + ConverterErrorType.ErrorTypeToString(error.ErrorConvertingType), errorConverting.Description, errorConverting.Exception?.Message }). Map(messages => String.Join("\n", messages.Where(message => !String.IsNullOrWhiteSpace(message)))). Map(messageText => { Console.WriteLine(messageText); return(Unit.Value); }). Void(_ => _accessService.SetLastTimeOperationByNow());
public ResultValue(TValue value, IEnumerable <IErrorCommon> errors, IErrorCommon errorNull = null) : this(errors) { Errors = value switch { null when errorNull != null => Errors.Concat(errorNull).ToList(), null => throw new ArgumentNullException(nameof(value)), _ => Errors }; Value = value; }
/// <summary> /// Сбросить индикаторы конвертации /// </summary> public async Task AbortPropertiesConverting(bool abortConnection, IErrorCommon errorStatus) { IsIntermediateResponseInProgress = false; if (abortConnection) { await AbortConverting(); } if (_statusProcessingInformation?.IsConverting == true) { _packageData?.ChangeAllFilesStatusAndSetError(errorStatus); } ClearSubscriptions(); }
/// <summary> /// Сообщения уровня ошибки /// </summary> public void ErrorLog(IErrorCommon fileError) { if (fileError == null) { return; } if (fileError.Exception != null) { _logger.Error(fileError.Exception, fileError.ErrorConvertingType.ToString); } else { _logger.Error($"{fileError.ErrorConvertingType}: {fileError.Description}"); } }
/// <summary> /// Преобразовать ошибку в трансферную модель /// </summary> private static ErrorCommonResponse ToErrorCommon(IErrorCommon error) => new ErrorCommonResponse(error.ErrorConvertingType, error.Description);
/// <summary> /// Выполнение положительного условия результирующего ответа или возвращение предыдущей ошибки в результирующем ответе с обработкой ошибок /// </summary> public static IResultValue <TValueOut> ResultValueOkTry <TValueIn, TValueOut>(this IResultValue <TValueIn> @this, Func <TValueIn, IResultValue <TValueOut> > okFunc, IErrorCommon errorMessage = null) { if (okFunc == null) { throw new ArgumentNullException(nameof(okFunc)); } if (@this == null) { throw new ArgumentNullException(nameof(@this)); } return(@this.HasErrors ? new ResultValue <TValueOut>(@this.Errors) : ExecuteBindResultValue(() => okFunc(@this.Value), errorMessage)); }
/// <summary> /// Сообщение об ошибке /// </summary> public async Task ShowError(IErrorCommon fileError) => await $"Тип ошибки: {ConverterErrorType.ErrorTypeToString(fileError.ErrorConvertingType)}.\nОписание: {fileError.Description}". VoidBindAsync(DialogFactory.GetErrorDialog);
/// <summary> /// Отлов ошибок и суммирование ошибок для модуля конвертации /// </summary> public static IResultValue <T> ExecuteBindResultValue <T>(Func <IResultValue <T> > method, IErrorCommon errorMessage = null) { IResultValue <T> result; try { result = method.Invoke(); } catch (Exception ex) { result = new ErrorCommon(GetTypeException(ex), String.Empty, ex). ToResultValue <T>(). ConcatErrors(errorMessage); } return(result); }
public ResultValue(IErrorCommon error) : this(error.AsEnumerable()) { }
public ResultValue(TValue value, IErrorCommon errorNull = null) : this(value, Enumerable.Empty <IErrorCommon>(), errorNull) { }
/// <summary> /// Преобразовать коллекцию ответов в ответ с коллекцией /// </summary> public static IResultCollection <T> ToResultCollection <T>(this IEnumerable <IResultCollection <T> > @this, IErrorCommon errorNull = null) => @this != null ? @this.Aggregate((IResultCollection <T>) new ResultCollection <T>(), (resultCollectionMain, resultCollection) => resultCollectionMain.ConcatResult(resultCollection)). WhereBad(result => result.Value.Count > 0, badFunc: result => errorNull != null ? new ResultCollection <T>(errorNull) : result) : throw new ArgumentNullException(nameof(@this));
/// <summary> /// Присвоить статус ошибки обработки для всех файлов /// </summary> public IPackageServer SetErrorToAllFiles(IErrorCommon filesError) => FilesDataServer.Select(fileData => new FileDataServer(fileData, StatusProcessing.ConvertingComplete, filesError)). Map(filesData => new PackageServer(Id, AttemptingConvertCount, StatusProcessingProject, ConvertingPackageSettings, filesData));
public ResultCollection(IErrorCommon error) : this(Enumerable.Empty <T>(), error.AsEnumerable()) { }
/// <summary> /// Отлов ошибок и вызов метода /// </summary> public static IResultError ExecuteAndHandleError(Action method, Action beforeMethod = null, Action catchMethod = null, Action finallyMethod = null, IErrorCommon errorMessage = null) => ExecuteAndHandleError(() => { method.Invoke(); return(Unit.Value); }, beforeMethod, catchMethod, finallyMethod, errorMessage). ToResult();
public FileDataServer(IFileDataServer fileDataServer, StatusProcessing statusProcessing, IErrorCommon fileErrors) : this(fileDataServer, statusProcessing, new List <IErrorCommon> { fileErrors }) { }
public FileStatus(string filePath, StatusProcessing statusProcessing, IErrorCommon error) : this(filePath, statusProcessing, new List <IErrorCommon>() { error }) { }
public ResultCollection(IEnumerable <T> collection, IEnumerable <IErrorCommon> errors, IErrorCommon errorNull = null) : base(errors) { var collectionList = collection?.ToList(); Errors = collectionList switch { null when errorNull != null => Errors.Concat(errorNull).ToList(), null => throw new ArgumentNullException(nameof(collection)), _ => Errors }; Value = collectionList ?? new List <T>(); }
/// <summary> /// Отлов ошибок и вызов метода асинхронно /// </summary> public static async Task <IResultError> ExecuteAndHandleErrorAsync(Func <Task> asyncMethod, Action beforeMethod = null, Action catchMethod = null, Action finallyMethod = null, IErrorCommon errorMessage = null) => await ExecuteAndHandleErrorAsync(async() => { await asyncMethod.Invoke(); return(Task.FromResult(Unit.Value)); }, beforeMethod, catchMethod, finallyMethod, errorMessage). MapAsync(result => result.ToResult());
public ResultError(IErrorCommon errorConverting) : this(errorConverting.AsEnumerable()) { }
/// <summary> /// Преобразовать внутренний класс ошибок библиотеки из основного /// </summary> public static IErrorApplication ToErrorApplication(this IErrorCommon errorCommon) => ErrorApplicationConverter.ToErrorApplication(errorCommon);
/// <summary> /// Отобразить и записать в лог ошибку /// </summary> public void ShowAndLogError(IErrorCommon errorConverting) => errorConverting. Void(ShowError). Void(error => _loggerService.ErrorLog(error));
/// <summary> /// Преобразовать коллекцию ответов в ответ с коллекцией /// </summary> public static IResultCollection <T> ToResultCollection <T>(this IResultValue <IEnumerable <T> > @this, IErrorCommon errorNull = null) => @this != null ? new ResultCollection <T>(@this.OkStatus ? @this.Value : @this.Value ?? Enumerable.Empty <T>(), @this.Errors, errorNull) : throw new ArgumentNullException(nameof(@this));
/// <summary> /// Преобразовать внутренний класс ошибок библиотеки из основного типа /// </summary> public static IErrorApplication ToErrorApplication(IErrorCommon errorApplication) => (errorApplication != null) ? new ErrorApplication(ToErrorApplicationType(errorApplication.ErrorConvertingType), errorApplication.Description) : throw new ArgumentNullException(nameof(errorApplication));