public async void SendRequest(BaseYandexAPIRequest request)
        {
            try
            {
                string requestStr  = request.CreateRequestString();
                String responceStr = await _httpClientController.GetContentAsync(requestStr);

                BaseYandexAPIResponce responceObject = _responceDeserializer.DeserializeByRequestType(request, responceStr);
                if (responceObject != null)
                {
                    Notify(responceObject);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Пример #2
0
        public BaseYandexAPIResponce DeserializeByRequestType(BaseYandexAPIRequest request, string responceString)
        {
            BaseYandexAPIResponce responseObject = null;

            switch (request)
            {
            case TranslationRequest _:
                responseObject = JsonSerializer.Deserialize <TranslationResponce>(responceString, new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true,
                });
                break;

            case GetLanguagesRequest _:
                responseObject = JsonSerializer.Deserialize <LanguagesResponce>(responceString, new JsonSerializerOptions
                {
                    PropertyNameCaseInsensitive = true,
                });
                break;
            }
            return(responseObject);
        }