public async Task <IEnumerable <JryCover> > QueryByUriAsync(JryCoverType coverType, string uri) { var filter = Builders <JryCover> .Filter; return(await(await this.Collection.FindAsync( filter.And( filter.Eq(t => t.CoverType, coverType), filter.Eq(t => t.Uri, uri)) )) .ToListAsync()); }
private async Task <string> TryGetCoverUrlFromDoubanIdAsync(JryCoverType type, string doubanId) { DoubanEntity json = null; switch (type) { case JryCoverType.Video: json = await DoubanHelper.TryGetMovieInfoAsync(doubanId); break; case JryCoverType.Artist: json = await DoubanHelper.TryGetArtistInfoAsync(doubanId); break; default: throw new ArgumentOutOfRangeException("type", type, null); } return(json != null?json.GetLargeImageUrl() : null); }
public async Task <string> GetCoverFromDoubanIdAsync(JryCoverType type, string doubanId) { if (String.IsNullOrWhiteSpace(doubanId)) { throw new ArgumentException(); } return(await Task.Run(async() => { foreach (var jryCover in await this.Source.QueryByDoubanIdAsync(type, doubanId)) { return jryCover.Id; } var url = await this.TryGetCoverUrlFromDoubanIdAsync(type, doubanId); if (url == null) { return null; } lock (this._syncRoot) { if (this._writingDoubanId.Contains(doubanId)) { return null; } this._writingDoubanId.Add(doubanId); this.Log(JasilyLogger.LoggerMode.Debug, String.Format("added thread for cover. total [{0}].", this._writingDoubanId.Count)); } var request = WebRequest.CreateHttp(url); var result = await request.GetResultAsBytesAsync(); if (result.IsSuccess) { var cover = new JryCover(); cover.BuildMetaData(); cover.CoverSourceType = JryCoverSourceType.Douban; cover.CoverType = JryCoverType.Video; cover.DoubanId = doubanId; cover.Uri = url; cover.BinaryData = result.Result; await this.InsertAsync(cover); lock (this._syncRoot) { this._writingDoubanId.Remove(doubanId); } return cover.Id; } else { lock (this._syncRoot) { this._writingDoubanId.Remove(doubanId); this.Log(JasilyLogger.LoggerMode.Debug, String.Format("finish thread for cover. total [{0}].", this._writingDoubanId.Count)); } return null; } })); }