public static async Task <object> SelfRunCall(string runType, string argument, ILoggerFactory factory) { var logger = factory.CreateLogger <ImageManipulator_Direct>(); var manipulator = new ImageManipulator_Direct(logger); if (runType == SelfRunSystem.RunImageResize) { var realArg = SelfRunSystem.ParseArgument <ImageManipulationFitToSizeArgument>(argument); using (var file = File.OpenRead(realArg.inFile)) { return(await manipulator.FitToSizeAndSave(file, realArg.savePath, realArg.maxSize)); } } else if (runType == SelfRunSystem.RunImageThumbnail) { var realArg = SelfRunSystem.ParseArgument <ImageManipulationMakeThumbnailArgument>(argument); using (var file = File.OpenRead(realArg.inFile)) { return(await manipulator.MakeThumbnailAndSave(file, realArg.savePath, realArg.modify)); } } else { throw new InvalidOperationException($"Unknown runtype for image manipulator: {runType}"); } }
public Task <ImageManipulationInfo> MakeThumbnailAndSave(Stream fileData, string savePath, GetFileModify modify) { return(SelfRunSystem.RunProcessWithFileAsync <ImageManipulationInfo>(fileData, SelfRunSystem.RunImageThumbnail, new ImageManipulationMakeThumbnailArgument { modify = modify, savePath = Path.GetFullPath(savePath) })); }
public Task <ImageManipulationInfo> FitToSizeAndSave(Stream fileData, string savePath, int maxSize) { return(SelfRunSystem.RunProcessWithFileAsync <ImageManipulationInfo>(fileData, SelfRunSystem.RunImageResize, new ImageManipulationFitToSizeArgument { maxSize = maxSize, savePath = Path.GetFullPath(savePath) })); }
/// <summary> /// A wrapper for RunProcess that lets you pass a file as part of the argument list (as a stream) /// </summary> /// <param name="fileData"></param> /// <param name="runType"></param> /// <param name="args"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static async Task <T> RunProcessWithFileAsync <T>(Stream fileData, string runType, IInfileArgument args) { var tempFile = Path.GetFullPath(Path.Combine(TempLocation, Guid.NewGuid().ToString().Replace("-", ""))); Directory.CreateDirectory(Path.GetDirectoryName(tempFile) ?? throw new InvalidOperationException("No temp file path!")); using (var file = File.Create(tempFile)) { fileData.Seek(0, SeekOrigin.Begin); await fileData.CopyToAsync(file); } args.inFile = tempFile; try { return(await SelfRunSystem.RunProcessAsync <T>(runType, args)); } finally { File.Delete(tempFile); } }