예제 #1
0
        private static void ImportPhotoBlobs()
        {
            var rootPhotoPath = @"http://imdt.friendsofdt.org/";

            var media_items = oldDatabaseConnection.Query("SELECT * FROM media_items").ToList();

            Log("Importing " + media_items.Count + " Media Blobs");

            var count = 0;

            foreach (var _row in media_items)
            {
                var entity = new Photo();
                if (_row.guid == null)
                {
                    throw new InvalidOperationException("Media Item is Missing GUID. Row needs to be updated before Importing");
                }
                Guid guid = _row.guid;
                entity.PhotoId = (int)_row.ID;
                entity.GUID    = (Guid)_row.guid;

                byte[] original = null;
                original = AzureBlogStorageUtil.DownloadPublicBlob(rootPhotoPath + _row.item.ToString().Replace("./", ""));

                if (original == null)
                {
                    Log("Missing File!" + _row.item.ToString());
                    continue;
                }

                var fullSize  = ImageUtilities.LoadBitmap(original);
                var thumbnail = ImageUtilities.GetBytes(ImageUtilities.Resize(fullSize, 240, 240), ImageFormat.Jpeg);
                var tiny      = ImageUtilities.GetBytes(ImageUtilities.Resize(fullSize, 50, 50), ImageFormat.Jpeg);

                PutBlob(entity.GetOriginalFileName(), original);
                PutBlob(entity.GetThumbnailFileName(), thumbnail);
                PutBlob(entity.GetTinyFileName(), tiny);

                if (fullSize.Width > 600 || fullSize.Height > 800)
                {
                    entity.LargeFileIsSameAsOriginal = false;
                    // original image is too large for general display
                    var large = ImageUtilities.GetBytes(ImageUtilities.Resize(fullSize, 600, 800), ImageFormat.Jpeg);
                    PutBlob(entity.GetLargeFileName(), large);
                }

                count++;
                if (count % 100 == 0)
                {
                    Log("Imported " + count + " Photo Blobs");
                }
            }
            Log("Imported " + count + " Photo Blobs");
        }
예제 #2
0
        private static void FixLargePhotoFlag()
        {
            var rootPhotoPath = @"http://imdt.friendsofdt.org/";

            var media_items = oldDatabaseConnection.Query("SELECT * FROM media_items").ToList();

            Log("Checking " + media_items.Count + " Media Blobs For Large Images");

            var count = 0;

            foreach (var _row in media_items)
            {
                if (_row.guid == null)
                {
                    throw new InvalidOperationException("Media Item is Missing GUID. Row needs to be updated before Importing");
                }
                var photoID = (int)_row.ID;

                byte[] original = null;
                original = AzureBlogStorageUtil.DownloadPublicBlob(rootPhotoPath + _row.item.ToString().Replace("./", ""));

                if (original == null)
                {
                    Log("Missing File!" + _row.item.ToString());
                    continue;
                }

                using (var fullSize = ImageUtilities.LoadBitmap(original))
                {
                    if (fullSize.Width > 600 || fullSize.Height > 800)
                    {
                        // original image is too large for general display
                        using (var session = sessionFactory.OpenSession())
                        {
                            session.Execute("UPDATE dbo.Photo SET LargeFileIsSameAsOriginal = 0 WHERE PhotoId = @PhotoId", new { PhotoId = photoID });
                        }
                        count++;
                    }
                }
            }
            Log("Fixed " + count + " Large Photos");
        }