Beispiel #1
0
        public async Task <IEnumerable <SnapshotMiniature> > GetSnapshotMiniaturesAsync(IEnumerable <LocationSnapshot> snapshots)
        {
            var results = new List <SnapshotMiniature>();

            if (!snapshots.Any())
            {
                return(results);
            }

            var miniatures = _miniaturesCache.GetSnapshotMiniatures(snapshots);

            if (miniatures.Count() == snapshots.Count())
            {
                return(miniatures);
            }

            var pictureFiles = await GetPictureFiles();

            foreach (var snapshot in snapshots)
            {
                var pictureFile = pictureFiles.FirstOrDefault(_ => _.Name == snapshot.PictureFileName);
                var miniature   = (pictureFile != null) ? await GetSnapshotMiniatureAsync(snapshot, pictureFile) : new SnapshotMiniature
                {
                    Snapshot = snapshot
                };
                results.Add(miniature);
                if (miniature.Data == null)
                {
                    continue;
                }
                _miniaturesCache.AddSnapshotMiniature(miniature);
            }

            return(results);
        }
Beispiel #2
0
        public async Task <IEnumerable <SnapshotMiniature> > GetSnapshotMiniaturesAsync(IEnumerable <LocationSnapshot> snapshots)
        {
            if (!snapshots.Any())
            {
                return(new List <SnapshotMiniature>());
            }

            var miniatures = _miniaturesCache.GetSnapshotMiniatures(snapshots);

            if (miniatures.Count() == snapshots.Count())
            {
                return(miniatures);
            }

            var picturesUrl = await GetPicturesUrl();

            picturesUrl = $"{picturesUrl}?snapshotsIds={string.Join(",", snapshots.Select(_ => _.Id))}";

            var result = await _webClient.GetAsync <IEnumerable <ExpandoObject> >(picturesUrl);

            miniatures = result.Select(_ =>
            {
                var descriptor = (IDictionary <string, object>)_;
                return(new
                {
                    PictureFileName = descriptor["pictureFileName"].ToString(),
                    Thumbnail = descriptor["thumbnail"].ToString()
                });
            }).Join(snapshots, desc => desc.PictureFileName, snap => snap.PictureFileName, (desc, snap) =>
            {
                var miniature = new SnapshotMiniature
                {
                    Snapshot = snap,
                    Data     = Convert.FromBase64String(desc.Thumbnail)
                };

                _miniaturesCache.AddSnapshotMiniature(miniature);

                return(miniature);
            })
                         .ToList();

            return(miniatures);
        }