Esempio n. 1
0
 public void TfSetUp()
 {
     _deserializerMock    = Substitute.For <IDeserializer>();
     _downloadServiceMock = Substitute.For <IDownloadService>();
     _downloadServiceMock.DownloadData(Arg.Any <string>()).Returns("file content");
     _sut = new MultiKinoUrlProviderService(_downloadServiceMock, _deserializerMock);
 }
        private async Task <MultiKinoCity> GetObject()
        {
            var stringCityData = await _downloadService.DownloadData("https://multikino.pl/data/locations/");

            var deserializerObject = _deserializer.Deserialize <MultiKinoCity>(stringCityData);

            return(deserializerObject);
        }
Esempio n. 3
0
        public async Task <List <T> > GetCurrentData <T>(Cities city)
        {
            List <T> deserializedObjestsList = new List <T>();
            var      urlList = await GetUrlsList(city);

            foreach (var url in urlList)
            {
                var stringData = await _downloadService.DownloadData(url);

                var deserializedData = _deserializer.Deserialize <T>(stringData);
                deserializedObjestsList.Add(deserializedData);
            }
            return(deserializedObjestsList);
        }
Esempio n. 4
0
        private async Task DownloadIconAsync(string url, string sourceName, string packageName)
        {
            try
            {
                IDownloadService downloadService = downloadFactory.GetDefaultDownloadService();
                byte[]           iconBytes       = null;
                iconBytes = await downloadService.DownloadData(url).ConfigureAwait(false);

                if (IsValidIcon(iconBytes))
                {
                    await File.WriteAllBytesAsync(GetIconFileNameWithCacheFolder(sourceName, packageName), iconBytes).ConfigureAwait(false);
                }
                else
                {
                    var defaultIconBytes = File.ReadAllBytes("wwwroot/assets/package.png"); //TODO: assets folder should be in appsettings
                    await File.WriteAllBytesAsync(GetIconFileNameWithCacheFolder(sourceName, packageName), defaultIconBytes).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "DownloadIconAsync - count not download icon");
            }
        }