public IList <MeasureTaskInfo> List() { using var dbContext = new GbmDbContext(); return(dbContext.Tasks.Select(x => new MeasureTaskInfo { Id = new Guid(x.Id), CreatedAt = x.CreatedAt, Status = (MeasureTaskStatus)x.Status, OutputMetrics = x.OutputMetrics }).OrderBy(x => x.CreatedAt).ToList()); }
public IActionResult GetOutputImage(Guid id) { using var dbContext = new GbmDbContext(); var task = dbContext.Tasks.SingleOrDefault(x => x.Id == id.ToString().ToLower()); if (task == null) { return(NotFound()); } if (task.Status != (int)MeasureTaskStatus.Finished) { return(BadRequest("Task is not finished")); } var stream = new FileInfo(task.OutputImageFilePath).OpenRead(); return(File(stream, task.OutputImageMime)); }
public Task Execute(IJobExecutionContext context) { Console.WriteLine("Executing MeasureImageJob."); using var dbContext = new GbmDbContext(); foreach (var task in dbContext.Tasks.Where(t => t.Status == (int)MeasureTaskStatus.Segmented)) { var args = $"{ApplicationContext.Current.Configuration["PythonRepository"]}/measure.py {ApplicationContext.Current.Configuration["PythonRepository"]}/settings.json {task.OutputImageFilePath} {ApplicationContext.Current.Configuration["OutputMetricsDirectory"]}/{task.Id}.txt"; Console.WriteLine($"Processing task {task.Id}"); Console.WriteLine($"{ApplicationContext.Current.Configuration["PythonRuntime"]} {args}"); ProcessStartInfo start = new ProcessStartInfo { FileName = ApplicationContext.Current.Configuration["PythonRuntime"], Arguments = args, UseShellExecute = false, RedirectStandardOutput = true }; using (Process process = Process.Start(start)) { using (StreamReader reader = process.StandardOutput) { string result = reader.ReadToEnd(); Console.WriteLine(result); } } using (TextReader tr = new StreamReader($"{ApplicationContext.Current.Configuration["OutputMetricsDirectory"]}/{task.Id}.txt")) task.OutputMetrics = tr.ReadToEnd(); dbContext.Tasks.Single(t => t.Id == task.Id).Status = (int)MeasureTaskStatus.Finished; dbContext.SaveChanges(); } Console.WriteLine("MeasureImageJob finished."); return(Task.CompletedTask); }
public IActionResult Delete([FromQuery] string redirect_uri, Guid id) { using var dbContext = new GbmDbContext(); var task = dbContext.Tasks.SingleOrDefault(x => x.Id == id.ToString().ToLower()); if (task == null) { return(NotFound()); } dbContext.Tasks.Remove(task); dbContext.SaveChanges(); if (string.IsNullOrEmpty(redirect_uri)) { return(Ok()); } return(Redirect(redirect_uri)); }
public async Task <IActionResult> CreateAsync([FromQuery] string redirect_uri, IFormFile file) { using var dbContext = new GbmDbContext(); if (file == null) { return(BadRequest("Requires input image file")); } var id = Guid.NewGuid().ToString(); var filePath = $"{ApplicationContext.Current.Configuration["InputImagesDirectory"]}/{id}.jpg"; using (var stream = System.IO.File.Create(filePath)) { await file.CopyToAsync(stream); } dbContext.Tasks.Add(new MeasureTask { Id = id.ToLower(), CreatedAt = DateTime.Now, InputImageMime = file.ContentType, InputImageFilePath = filePath, Status = (int)MeasureTaskStatus.Created, OutputImageFilePath = $"{ApplicationContext.Current.Configuration["OutputImagesDirectory"]}/{id}.png", OutputImageMime = "image/png", }); dbContext.SaveChanges(); if (string.IsNullOrEmpty(redirect_uri)) { return(Ok()); } return(Redirect(redirect_uri)); }