Exemple #1
0
        private async Task <ImageInfo> SaveImages(SKImage image, SKImage miniature, string directory)
        {
            string formatStr = reader.Format == SKEncodedImageFormat.Jpeg ? "jpg" : reader.Format.ToString().ToLower();
            string id        = GenerateId();
            string path      = $"{directory}/{id}.{formatStr}";

            var tasks = new List <Task>()
            {
                writer.Write(image, path, reader.Format)
            };

            string minipath;

            if (miniature != null)
            {
                minipath = $"{directory}/{options.MiniaturePrefix}{id}.{formatStr}";
                tasks.Add(writer.Write(miniature, minipath, reader.Format));
            }
            else
            {
                minipath = path;
            }

            try
            {
                await Task.WhenAll(tasks);
            }
            catch
            {
                await writer.TryClearUp(path, minipath);

                throw;
            }

            return(new ImageInfo {
                Id = id, Path = path, MiniaturePath = minipath, Format = formatStr
            });
        }