Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Pass first argument with connection string to database, second with file storage type (fs/azure), third a connection to azure storage or local path template (relative path not supported).");
                return;
            }

            string connectionString = args[0];

            Console.WriteLine("Creating context.");
            using var entries = new EntriesDataContext(DbContextOptions <EntriesDataContext>(connectionString, "Entries"), Schema <EntriesDataContext>("Entries"));

            var imageFormat = ImageFormatDefinition.Jpeg;

            IFileStorage fileStorage = null;
            string       storageType = args[1];

            if (storageType == "fs")
            {
                fileStorage = new SystemIoFileStorage(path => path, Options.Create(new SystemIoStorageOptions()
                {
                    PathTemplate = args[2]
                }), imageFormat);
            }
            else if (storageType == "azure")
            {
                fileStorage = new AzureFileStorage(Options.Create(new AzureStorageOptions()
                {
                    ConnectionString = args[2]
                }));
            }
            else
            {
                Console.WriteLine($"Not supported type of file storage '{storageType}'.");
                return;
            }

            var resizeService = new ImageResizeService(imageFormat);

            Console.WriteLine("Getting images.");
            var images = await entries.Images
                         .Include(i => i.Entry)
                         //.Where(i => i.OriginalWidth == 0 || i.OriginalHeight == 0)
                         .ToListAsync();

            Console.WriteLine($"Found '{images.Count}' images.");
            foreach (var image in images)
            {
                if (!await TryUpdateOriginalSizeAsync(entries, fileStorage, resizeService, image, ImageType.Original))
                {
                    await TryUpdateOriginalSizeAsync(entries, fileStorage, resizeService, image, ImageType.Preview);
                }
            }

            Console.WriteLine("Saving changes.");
            await entries.SaveChangesAsync();

            Console.WriteLine("Done.");
        }
Ejemplo n.º 2
0
 internal MigrationController(ImageService service, SystemIoFileStorage fileStorage, DataContext dbContext)
 {
     Ensure.NotNull(service, "service");
     Ensure.NotNull(fileStorage, "fileStorage");
     Ensure.NotNull(dbContext, "dbContext");
     this.service     = service;
     this.fileStorage = fileStorage;
     this.dbContext   = dbContext;
 }