Beispiel #1
0
        public async Task <Result <Unit, Error> > Persist(Name name, ProcessingConfiguration configuration)
        {
            var snapshot = new ConfigurationSnapshot
            {
                Name            = name.ToString(),
                AvoidDuplicates = configuration.AvoidDuplicates,
                Sizes           = configuration.Sizes.Select(s => new SizeConfigurationSnapshot
                {
                    Tag       = s.Tag.ToString(),
                    MaxWidth  = s.MaxWidth.ToNullable(),
                    MaxHeight = s.MaxHeight.ToNullable(),
                    Format    = s.Format.FileExtension,
                    Quality   = s.Quality.ToScaler(),
                    Crop      = s.Crop.Map(c => new CropConfigurationSnapshot
                    {
                        AspectRatio  = c.AspectRatio.ToString(),
                        Color        = c.BackgroundColor.Map(c => c.ToScalar()).ToNullable(),
                        CropStrategy = c.CropStrategy.ToString()
                    }).UnwrapOrDefault()
                }).ToArray()
            };

            await _client.Configurations.ReplaceOneAsync(g => g.Name == snapshot.Name, snapshot, new ReplaceOptions { IsUpsert = true });

            return(Result.Unit());
        }
Beispiel #2
0
 private ProcessingConfiguration ToConfiguration(ConfigurationSnapshot snapshot)
 {
     return(ProcessingConfiguration.New(
                avoidDuplicates: snapshot.AvoidDuplicates,
                sizes: snapshot.Sizes.Select(s => new SizeConfiguration(
                                                 tag: Name.FromString(s.Tag).UnwrapOrThrow(),
                                                 maxWidth: s.MaxWidth.ToOption(),
                                                 maxHeight: s.MaxHeight.ToOption(),
                                                 crop: s.Crop != null
                 ? Option.Some(new CropConfiguration(
                                   aspectRatio: AspectRatio.FromString(s.Crop.AspectRatio).UnwrapOrThrow(),
                                   cropStrategy: (CropStrategy)Enum.Parse(typeof(CropStrategy), s.Crop.CropStrategy, true),
                                   backgroundColor: s.Crop.Color.ToOption().Map(s => new Color(s))
                                   )) : Option.None(),
                                                 quality: Quality.FromScalar(s.Quality).UnwrapOrThrow(),
                                                 format: ImageFormat.FromExtension(s.Format).UnwrapOrThrow()
                                                 )).ToArray()
                ).UnwrapOrThrow());
 }