Пример #1
0
        protected MongoImage CreateMongoImage(string url, HttpRequestParameters requestParameters = null)
        {
            HttpRequest httpRequest = new HttpRequest { Url = url };
            string file = _urlCache.GetUrlSubPath(httpRequest);
            string path = zPath.Combine(_urlCache.CacheDirectory, file);
            if (!zFile.Exists(path))
                HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters);
            Image image = null;
            if (zFile.Exists(path))
            {
                try
                {
                    image = zimg.LoadBitmapFromFile(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;
        }
Пример #2
0
 public void LoadImage(MongoImage mongoImage)
 {
     mongoImage.Image = zimg.LoadBitmapFromFile(zPath.Combine(_urlCache.CacheDirectory, mongoImage.File));
 }