protected MongoImage CreateMongoImage(string url, HttpRequestParameters_v1 requestParameters = null) { string file = _urlCache.GetUrlSubPath(url, requestParameters); string path = zPath.Combine(_urlCache.CacheDirectory, file); if (!zFile.Exists(path)) { //Http2.LoadToFile(url, path, requestParameters); Http_v3.LoadToFile(url, path, requestParameters); } Image image = null; if (zFile.Exists(path)) { try { image = zimg.LoadFromFile(path); } catch (Exception exception) { Trace.WriteLine("error unable to load image url \"{0}\" to \"{1}\" (WebImageMongoCacheManager.CreateMongoImage())", url, path); Trace.Write("error : "); Trace.WriteLine(exception.Message); } } else { Trace.WriteLine("error unable to load image url \"{0}\" to \"{1}\" (WebImageMongoCacheManager.CreateMongoImage())", url, path); } MongoImage mongoImage = new MongoImage(); mongoImage.Url = url; mongoImage.File = file; mongoImage.Width = image != null ? image.Width : 0; mongoImage.Height = image != null ? image.Height : 0; mongoImage.Image = image; GetCollection().zUpdate(new QueryDocument { { "_id", BsonValue.Create(url) } }, new UpdateDocument { { "$set", mongoImage.ToBsonDocument() } }, UpdateFlags.Upsert); return(mongoImage); }
public static void Test_RapideDdl_LoadPostImages_01(string query = null, string sort = null, int limit = 10, bool loadImage = false) { //IEnumerable<ImageHtml> images = from image in (from post in RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage) select post.images) select image; //IEnumerable<ImageHtml> images = from post in RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage) select (from image in post.images select image); //RunSource.CurrentRunSource.View(from image in (from post in RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage) select post.images) select image); //RunSource.CurrentRunSource.View(from post in RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage) select (from image in post.images select image)); //var q = RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage).SelectMany(post => post.images); //var q = from post in RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage) select (from image in post.images select image); //var q = from post in RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage) // select (from image in post.images // select new { source = image.Source, title = image.Title, width = image.ImageWidth, height = image.ImageHeight, date = post.creationDate, url = post.sourceUrl }); //var q1 = from post in RapideDdl_LoadPostDetail.Find(query, sort: sort, limit: limit, loadImage: loadImage) select (from image in post.images select image.Source); var q1 = from post in RapideDdl_LoadPostDetail.CurrentLoadPostDetail.FindDocuments(query, sort: sort, limit: limit, loadImage: loadImage) select(from image in post.images select image.Url); var q2 = q1.SelectMany(image => image).Distinct().OrderBy(image => image); UrlCache_v1 urlCache = new UrlCache_v1(@"c:\pib\_cacheImage", UrlFileNameType.Path | UrlFileNameType.Host, (url, requestParameters) => zurl.GetDomain(url)); var q3 = from image in q2 select new { image = image, file = zurl.UrlToFileName(image, UrlFileNameType.Path | UrlFileNameType.Host), file2 = urlCache.GetUrlSubPath(image) }; var q = q3; //RunSource.CurrentRunSource.View(q); q.zView(); }