Пример #1
0
 public T DeserializeQueueData(byte[] queueData)
 {
     try
     {
         DataBlock dataBlock = DataBlock.CreateByQueueData(queueData);
         return((T)dataConverter.Deserialize(dataBlock.UserData));
     }
     catch (DataBlock.DataBlockParseException e)
     {
         fileManager.WriteErrorQueueData(e.QueueData, true);
         throw e;
     }
 }
Пример #2
0
        public T Get <T>(string key)
        {
            var data = _RedisDb.HashGet(key, _dataConverter.Serialize(key));

            if (data.IsNull)
            {
                return(default(T));
            }
            else
            {
                return(_dataConverter.Deserialize <T>(data.ToString()));
            }
        }
Пример #3
0
        public async Task <IEnumerable <Movie> > GetMovies(IDataConverter <List <Movie> > dataConverter)
        {
            var movies = new List <Movie>();

            try
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                using HttpClientHandler handler = new HttpClientHandler()
                      {
                          AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                      };
                using HttpClient client = new HttpClient(handler);

                var response = await client.GetAsync($"{_requestLocation}");

                if (!response.IsSuccessStatusCode) //try once more
                {
                    response = await client.GetAsync($"{_requestLocation}");
                }

                if (!response.IsSuccessStatusCode)
                {
                    // TODO: Do something here to handle failed downloads
                    return(movies);
                }
                else
                {
                    var responseData = await response.Content.ReadAsByteArrayAsync();

                    var encoder         = CodePagesEncodingProvider.Instance.GetEncoding(_encodingCodePage);
                    var responseEncoded = encoder.GetString(responseData);
                    movies = dataConverter.Deserialize(responseEncoded).ToList();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while getting data from http. URL: {_requestLocation}. Error: {ex.Message}, InnerException {ex.InnerException?.Message}, Stack {ex.StackTrace}");
            }
            return(movies);
        }