コード例 #1
0
    public ImageItem.ThumbnailInfo GetThumbnailForImage(ImageItem item)
    {
        string imageid = item.ImageID;
        string thumb_file;
        string lc_filename = item.Filename.ToLower();

        if (lc_filename.EndsWith("jpg") || lc_filename.EndsWith("png") || lc_filename.EndsWith("jpeg"))
        {
            thumb_file = item.Dirname + Util.DirSep + ".thumbnails" + Util.DirSep + item.Filename;
        }
        else
        {
            thumb_file = item.Dirname + Util.DirSep + ".thumbnails" + Util.DirSep + item.Filename + ".jpg";
        }

        FileInfo thumbfi = new FileInfo(thumb_file);

        if (!thumbfi.Exists)
        {
            DirectoryInfo thumb_dinfo = new DirectoryInfo(item.Dirname + Util.DirSep + ".thumbnails");
            Console.WriteLine(item.Dirname + Util.DirSep + ".thumbnails");
            thumb_dinfo.Create();

            // we need to create a thumbnail
            Thumbnailer.ThumbnailerInfo tinfo = new Thumbnailer.ThumbnailerInfo();
            tinfo.id     = imageid;
            tinfo.source = item.Dirname + Util.DirSep + item.Filename;
            tinfo.target = thumb_file;

#if NO_MULTITHREAD
            thumbnailer.MakeThumbnail(tinfo);
            // fall through
#else
            thumbnailer.Thumbnail(tinfo);
            return(null);
#endif
        }

        ImageItem.ThumbnailInfo ti = new ImageItem.ThumbnailInfo();
        ti.filename = thumb_file;
        return(ti);
    }
コード例 #2
0
    // IImageRepository
    public ImageItem.ThumbnailInfo GetThumbnailForImage(ImageItem item)
    {
        if (item.Repo != this)
        {
            throw new InvalidOperationException();
        }

//        Console.WriteLine ("GetThumbnailForImage: " + item.ImageID);

        int i_id = Convert.ToInt32(item.ImageID);

        IDbCommand cmd = db_conn.CreateCommand();

        cmd.CommandText =
            DbProvider.SqlHelper.sqlDbGetThumbnail(i_id);

        string thumb_file;

        object o = cmd.ExecuteScalar();

        if (o == null)
        {
            // no thumbnail in database, check if one exists in the filesystem
            string thumb_dir = item.Dirname + Util.DirSep + ".thumbnails";
            if (item.Filename.ToLower().EndsWith(".jpg"))
            {
                thumb_file = thumb_dir + Util.DirSep + item.Filename;
            }
            else
            {
                thumb_file = thumb_dir + Util.DirSep + item.Filename + ".jpg";
            }

            FileInfo thumb_finfo = new FileInfo(thumb_file);
            if (!thumb_finfo.Exists)
            {
                DirectoryInfo thumb_dinfo = new DirectoryInfo(thumb_dir);
                thumb_dinfo.Create();

                Thumbnailer.ThumbnailerInfo tinfo = new Thumbnailer.ThumbnailerInfo();
                tinfo.id     = item.ImageID;
                tinfo.source = item.Dirname + Util.DirSep + item.Filename;
                tinfo.target = thumb_file;

#if NO_MULTITHREAD
                thumbnailer.MakeThumbnail(tinfo);
                // fall through
#else
                thumbnailer.Thumbnail(tinfo);
                // thumbnailing in progress, return null
                return(null);
#endif
            }

            // thumb file exists from something else, but wasn't present in our database
            // save it
            SaveThumbToDb(i_id, thumb_file);
        }
        else
        {
            thumb_file = (string)o;
        }

        ImageItem.ThumbnailInfo ti = new ImageItem.ThumbnailInfo();
        ti.filename = thumb_file;

//        Console.WriteLine (" -- returning " + thumb_file);
        return(ti);
    }