Пример #1
0
 public bool NeedsDownload(string videoId, StorageFile storageFile)
 {
     if (UrlCaches.ContainsKey(videoId) && storageFile.Exists())
     {
         var fileName = storageFile.ToString();
         var urlCache = UrlCaches[videoId];
         if (storageFile.Length >= urlCache.Length)
         {
             if (!VideoCaches.ContainsKey(fileName))
             {
                 SetFinished(urlCache.VideoId, fileName, false);
             }
             else if (VideoCaches[fileName].Finished)
             {
                 return(false);
             }
         }
         foreach (var item in VideoCaches.Where(p => p.Value.FileName != fileName && p.Value.Finished && File.Exists(p.Value.FileName) && p.Value.VideoId == videoId))
         {
             try {
                 File.Copy(item.Value.FileName, fileName, true);
             } catch (IOException) {
                 return(true);
             }
             SetFinished(urlCache.VideoId, fileName, true);
             return(false);
         }
     }
     return(true);
 }
        public async Task <int> InsertNewTrendingGifs(List <GifObject> gifObjects)
        {
            var existingGifObjects = from gifObject in gifObjects
                                     join urlCache in UrlCaches on gifObject.Id equals urlCache.Id
                                     select gifObject;
            var newGifObjects = gifObjects.Except(existingGifObjects);
            var newUrlCaches  = newGifObjects.Select(s => new UrlCache {
                Id = s.Id, Url = s.Url, Stamp = DateTime.Now
            });

            UrlCaches.AddRange(newUrlCaches);
            return(await SaveChangesAsync());
        }
Пример #3
0
 public void SetUrl(string videoId, string title, long length)
 {
     if (UrlCaches.ContainsKey(videoId))
     {
         var item = UrlCaches[videoId];
         item.Length = length;
         item.Title  = title;
     }
     else
     {
         var cache = new UrlCache {
             Length = length, Title = title, VideoId = videoId
         };
         _urlCaches.Add(cache);
         UrlCaches.Add(cache.VideoId, cache);
     }
 }
 public async Task <List <UrlCache> > GetUrlCachesAsync()
 {
     return(await UrlCaches.AsNoTracking().ToListAsync());
 }