Logo Search packages:      
Sourcecode: f-spot version File versions  Download package

System.IO.Stream FlickrNet::Flickr::DownloadPicture ( string  url  )  [inline]

Downloads the picture from a internet and transfers it to a stream object.

Parameters:
url The url of the image to download.
Returns:
A Stream object containing the downloaded picture.

The method checks the download cache first to see if the picture has already been downloaded and if so returns the cached image. Otherwise it goes to the internet for the actual image.

Definition at line 494 of file Flickr.cs.

References FlickrNet::PictureCacheItem::creationTime, DoDownloadPicture(), FlickrNet::PictureCacheItem::filename, FlickrNet::PictureCacheItem::fileSize, and FlickrNet::PictureCacheItem::url.

            {
                  lock(Cache.DownloadCache.SyncRoot)
                  {
                        if( Cache.DownloadCache.ContainsKey(url) )
                        {
                              PictureCacheItem cacheItem = (PictureCacheItem)Cache.DownloadCache[url];
                              return Utils.GetApplicationDataReadStream(cacheItem.filename);
                        }

                        PictureCacheItem picCache = new PictureCacheItem();
                        picCache.filename = Guid.NewGuid().ToString();
                        Stream read = DoDownloadPicture(url);
                        Stream write = Utils.GetApplicationDataWriteStream(picCache.filename);
                        int b = read.ReadByte();
                        long fileSize = 0;
                        while( b != -1 )
                        {
                              fileSize++;
                              write.WriteByte((byte)b);
                              b = read.ReadByte();
                        }
                        read.Close();
                        write.Close();

                        while( Cache.CacheSize + fileSize > Cache.CacheSizeLimit )
                        {
                              Cache.DeleteOldest();
                        }

                        Cache.CacheSize += fileSize;

                        picCache.url = url;
                        picCache.creationTime = DateTime.Now;
                        picCache.fileSize = fileSize;

                        Cache.DownloadCache.Add(url, picCache);

                        Cache.ForceSave();
                        return Utils.GetApplicationDataReadStream(picCache.filename);
                  }
            }


Generated by  Doxygen 1.6.0   Back to index