/// <summary> /// Логгирование авторизации /// </summary> private static void LogAuthorize(IResultValue <string> resultToken, IAuthorizeRestService service, IBoutiqueLogger boutiqueLogger) => resultToken. ResultValueVoidOkBad(_ => boutiqueLogger. Void(_ => boutiqueLogger.ShowMessage($"Токен сервиса [{service.GetType().Name}] получен")), errors => errors. Void(_ => boutiqueLogger.ShowMessage($"Ошибка авторизации в сервисе [{service.GetType().Name}]")). Void(_ => boutiqueLogger.ShowErrors(errors)));
/// <summary> /// Логгирование действия с базой /// </summary> public static void LogServiceAction <TId, TDomain>(IResultError result, IBoutiqueLogger boutiqueLogger, ServiceActionType serviceActionType) where TDomain : IDomainModel <TId> where TId : notnull => result. ResultErrorVoidOkBad(() => boutiqueLogger.ShowMessage($"{serviceActionType} [{typeof(TDomain).Name}] completed"), errors => errors. Void(_ => boutiqueLogger.ShowMessage($"Error {serviceActionType} [{typeof(TDomain).Name}]")). Void(_ => boutiqueLogger.ShowErrors(errors)));
/// <summary> /// Загрузить тип одежды в базу /// </summary> private static async Task <IResultError> ClothesDelete(IRestHttpClient restClient, IBoutiqueLogger boutiqueLogger) => await BoutiqueRestServiceFactory.GetClothesRestService(restClient). MapAsync(service => ServiceDeleteAction(service, boutiqueLogger));
/// <summary> /// Загрузить данные в базу /// </summary> public static async Task <IResultError> DeleteData(IRestHttpClient httpClient, IBoutiqueLogger boutiqueLogger) => await httpClient.ToResultValue(). Void(_ => boutiqueLogger.ShowMessage("Начало удаления данных")). ResultValueBindErrorsOkAsync(restClient => SizeGroupDelete(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => ClothesTypeDelete(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => GenderDelete(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => CategoryDelete(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => ColorDelete(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => SizeDelete(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => ClothesDelete(restClient, boutiqueLogger)). VoidTaskAsync(_ => boutiqueLogger.ShowMessage("Удаление данных завершено"));
/// <summary> /// Загрузить одежду в базу /// </summary> private static async Task <IResultError> ClothesUpload(IRestHttpClient restClient, IBoutiqueLogger boutiqueLogger) => await BoutiqueRestServiceFactory.GetClothesRestService(restClient). MapAsync(service => ClothesInitialize.ClothesMains.SelectChunk(POST_CHUNK). Select(clothesMains => ServicePostAction(service, clothesMains, boutiqueLogger)). ToResultErrorsTaskAsync());
/// <summary> /// Загрузить тип одежды в базу /// </summary> private static async Task <IResultError> SizeGroupUpload(IRestHttpClient restClient, IBoutiqueLogger boutiqueLogger) => await BoutiqueRestServiceFactory.GetSizeGroupRestService(restClient). MapAsync(service => ServicePostAction(service, SizeGroupInitialize.SizeGroupMains, boutiqueLogger));
/// <summary> /// Загрузить тип одежды в базу /// </summary> private static async Task <IResultError> ClothesTypeUpload(IRestHttpClient restClient, IBoutiqueLogger boutiqueLogger) => await BoutiqueRestServiceFactory.GetClothesTypeRestService(restClient). MapAsync(service => ServicePostAction(service, ClothesTypeInitialize.ClothesTypeMains, boutiqueLogger));
/// <summary> /// Функция авторизации /// </summary> private static IResultValue <Func <IRestHttpClient, IAuthorizeDomain, Task <IResultValue <string> > > > BoutiqueAuthorizeFunc(IBoutiqueLogger boutiqueLogger) => new ResultValue <Func <IRestHttpClient, IAuthorizeDomain, Task <IResultValue <string> > > >((restClient, authorizeDomain) => Authorize(restClient, authorizeDomain, boutiqueLogger));
/// <summary> /// Получить конфигурацию авторизации /// </summary> public static async Task <IResultValue <IAuthorizeDomain> > GetConfiguration(IBoutiqueLogger boutiqueLogger) => await AuthorizeConfigurationManager.GetConfigurationAsync(). ResultValueVoidBadTaskAsync(errors => boutiqueLogger. Void(_ => boutiqueLogger.ShowMessage("Ошибка файла авторизации")). Void(_ => boutiqueLogger.ShowErrors(errors)));
/// <summary> /// Загрузить данные в базу /// </summary> public static async Task <IResultError> PostData(IRestHttpClient restClientBoutique, IBoutiqueLogger boutiqueLogger) => await restClientBoutique.ToResultValue(). Void(_ => boutiqueLogger.ShowMessage("Начало загрузки данных")). ResultValueBindErrorsOkAsync(restClient => GenderUpload(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => CategoryUpload(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => ColorUpload(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => ClothesTypeUpload(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => SizeUpload(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => SizeGroupUpload(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => ClothesUpload(restClient, boutiqueLogger)). VoidTaskAsync(_ => boutiqueLogger.ShowMessage("Загрузка данных завершена"));
/// <summary> /// Логгирование загрузки /// </summary> private static async Task <IResultError> ServicePostAction <TId, TDomain>(IRestServiceBase <TId, TDomain> restService, IEnumerable <TDomain> domains, IBoutiqueLogger boutiqueLogger) where TDomain : IDomainModel <TId> where TId : notnull => await restService.PostCollectionAsync(domains). VoidTaskAsync(result => BoutiqueServiceLog.LogServiceAction <TId, TDomain>(result, boutiqueLogger, ServiceActionType.Post));
/// <summary> /// Получить конфигурацию /// </summary> public static async Task <IResultValue <ILoaderConfigurationDomain> > GetConfiguration(IBoutiqueLogger boutiqueLogger) => await LoaderConfigurationManager.GetConfigurationAsync(). ResultValueVoidBadTaskAsync(errors => boutiqueLogger. Void(_ => boutiqueLogger.ShowMessage("Ошибка конфигурационного файла")). Void(_ => boutiqueLogger.ShowErrors(errors)));
/// <summary> /// Авторизироваться с помощью токена /// </summary> private static async Task <IResultValue <string> > Authorize(IRestHttpClient restClient, IAuthorizeDomain authorizeDomain, IBoutiqueLogger boutiqueLogger) => await BoutiqueRestServiceFactory.GetAuthorizeRestService(restClient).ToResultValue(). ResultValueBindOkAsync(service => service.AuthorizeJwt(authorizeDomain). VoidTaskAsync(token => LogAuthorize(token, service, boutiqueLogger)));
/// <summary> /// Логгирование удаления /// </summary> private static async Task <IResultError> ServiceDeleteAction <TId, TDomain>(IRestServiceBase <TId, TDomain> restService, IBoutiqueLogger boutiqueLogger) where TDomain : IDomainModel <TId> where TId : notnull => await restService.DeleteAsync(). VoidTaskAsync(result => BoutiqueServiceLog.LogServiceAction <TId, TDomain>(result, boutiqueLogger, ServiceActionType.Delete));
/// <summary> /// Загрузить тип пола в базу /// </summary> private static async Task <IResultError> GenderUpload(IRestHttpClient restClient, IBoutiqueLogger boutiqueLogger) => await BoutiqueRestServiceFactory.GetGenderRestService(restClient). MapAsync(service => ServicePostAction(service, GenderInitialize.Genders, boutiqueLogger));
/// <summary> /// Клиент для подключения к сервису одежды /// </summary> public static async Task <IResultValue <IRestHttpClient> > GetBoutiqueRestClient(string jwtToken, IBoutiqueLogger boutiqueLogger) => await LoaderConfigurationFactory.GetConfiguration(boutiqueLogger). ResultValueOkTaskAsync(config => HttpClientFactory.GetRestClient(config.HostConfiguration, jwtToken));
/// <summary> /// Загрузить категории одежды в базу /// </summary> private static async Task <IResultError> CategoryUpload(IRestHttpClient restClient, IBoutiqueLogger boutiqueLogger) => await BoutiqueRestServiceFactory.GetCategoryRestService(restClient). MapAsync(service => ServicePostAction(service, CategoryInitialize.Categories, boutiqueLogger));
/// <summary> /// Авторизироваться и загрузить данные в базу с предварительной очисткой /// </summary> public static async Task <IResultError> UploadAuthorizeData(IBoutiqueLogger boutiqueLogger) => await BoutiqueAuthorizeService.AuthorizeJwt(boutiqueLogger). ResultValueBindOkBindAsync(token => BoutiqueRestServiceFactory.GetBoutiqueRestClient(token, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => BoutiqueDelete.DeleteData(restClient, boutiqueLogger)). ResultValueBindErrorsOkBindAsync(restClient => BoutiquePost.PostData(restClient, boutiqueLogger));
/// <summary> /// Получить логин и токен /// </summary> public static async Task <IResultValue <string> > AuthorizeJwt(IBoutiqueLogger boutiqueLogger) => await BoutiqueAuthorizeFunc(boutiqueLogger). ResultValueCurryOkAsync(BoutiqueRestServiceFactory.GetBoutiqueRestClient(boutiqueLogger)). ResultValueCurryOkBindAsync(AuthorizeConfigurationFactory.GetConfiguration(boutiqueLogger)). ResultValueBindOkBindAsync(func => func());