示例#1
0
        public void CreateMissingThumbs()
        {
            VerifyAdmin();

            var imagePersister = new ServerEntryThumbPersister();
            var thumbGenerator = new ImageThumbGenerator(imagePersister);
            var artistIds      = new int[0];

            HandleQuery(session => {
                artistIds = session.Query <Artist>().Where(a => !a.Deleted && a.PictureMime != null && a.PictureMime != "").Select(a => a.Id).ToArray();
            });

            for (int i = 0; i < artistIds.Length; i += 100)
            {
                var ids = artistIds.Skip(i).Take(100).ToArray();

                HandleQuery(session => {
                    var artists = session.Query <Artist>().Where(a => ids.Contains(a.Id)).ToArray();

                    foreach (var artist in artists)
                    {
                        var data = new EntryThumb(artist, artist.PictureMime, ImagePurpose.Main);

                        if (artist.Picture.Bytes == null || imagePersister.HasImage(data, ImageSize.Thumb))
                        {
                            continue;
                        }

                        using (var stream = new MemoryStream(artist.Picture.Bytes)) {
                            thumbGenerator.GenerateThumbsAndMoveImage(stream, data, ImageSizes.Thumb | ImageSizes.SmallThumb | ImageSizes.TinyThumb);
                        }
                    }
                });
            }

            /*var albumIds = new int[0];
             *
             * HandleQuery(session => {
             *      albumIds = session.Query<Album>().Where(a => !a.Deleted && a.CoverPictureData.Mime != null && a.CoverPictureData.Mime != "").Select(a => a.Id).ToArray();
             * });
             *
             * for (int i = 0; i < albumIds.Length; i += 100) {
             *
             *      var ids = albumIds.Skip(i).Take(100).ToArray();
             *
             *      HandleQuery(session => {
             *
             *              var albums = session.Query<Album>().Where(a => ids.Contains(a.Id)).ToArray();
             *
             *              foreach (var album in albums) {
             *
             *                      var data = new EntryThumb(album, album.CoverPictureData.Mime);
             *
             *                      if (album.CoverPictureData.Bytes == null || imagePersister.HasImage(data, ImageSize.Thumb))
             *                              continue;
             *
             *                      using (var stream = new MemoryStream(album.CoverPictureData.Bytes)) {
             *                              thumbGenerator.GenerateThumbsAndMoveImage(stream, data, ImageSizes.Thumb | ImageSizes.SmallThumb | ImageSizes.TinyThumb);
             *                      }
             *
             *              }
             *
             *      });
             *
             * }*/

            HandleQuery(session => {
                /*var artistPic = session.Query<ArtistPictureFile>().ToArray();
                 *
                 * foreach (var pic in artistPic) {
                 *
                 *      var thumbFile = ImageHelper.GetImagePathSmallThumb(pic);
                 *      var origPath = ImageHelper.GetImagePath(pic);
                 *
                 *      if (File.Exists(origPath) && !File.Exists(thumbFile)) {
                 *
                 *              using (var original = Image.FromFile(ImageHelper.GetImagePath(pic))) {
                 *
                 *                      if (original.Width > ImageHelper.DefaultSmallThumbSize || original.Height > ImageHelper.DefaultSmallThumbSize) {
                 *                              using (var thumb = ImageHelper.ResizeToFixedSize(original, ImageHelper.DefaultSmallThumbSize, ImageHelper.DefaultSmallThumbSize)) {
                 *                                      thumb.Save(thumbFile);
                 *                              }
                 *                      } else {
                 *                              File.Copy(origPath, thumbFile);
                 *                      }
                 *
                 *              }
                 *
                 *      }
                 *
                 * }
                 *
                 * var albumPic = session.Query<AlbumPictureFile>().ToArray();
                 *
                 * foreach (var pic in albumPic) {
                 *
                 *      var thumbFile = ImageHelper.GetImagePathSmallThumb(pic);
                 *      var origPath = ImageHelper.GetImagePath(pic);
                 *
                 *      if (File.Exists(origPath) && !File.Exists(thumbFile)) {
                 *
                 *              using (var original = Image.FromFile(ImageHelper.GetImagePath(pic))) {
                 *
                 *                      if (original.Width > ImageHelper.DefaultSmallThumbSize || original.Height > ImageHelper.DefaultSmallThumbSize) {
                 *                              using (var thumb = ImageHelper.ResizeToFixedSize(original, ImageHelper.DefaultSmallThumbSize, ImageHelper.DefaultSmallThumbSize)) {
                 *                                      thumb.Save(thumbFile);
                 *                              }
                 *                      } else {
                 *                              File.Copy(origPath, thumbFile);
                 *                      }
                 *
                 *              }
                 *
                 *      }
                 *
                 * }*/
            });
        }