Ejemplo n.º 1
0
        public Task Execute(IJobExecutionContext context)
        {
            Console.WriteLine("Executing ProcessImageJob.");

            using var dbContext = new GbmDbContext();

            foreach (var task in dbContext.Tasks.Where(t => t.Status == (int)MeasureTaskStatus.Created))
            {
                dbContext.Tasks.Single(t => t.Id == task.Id).Status = (int)MeasureTaskStatus.InProcess;
                dbContext.SaveChanges();

                var args =
                    $"{ApplicationContext.Current.Configuration["PythonRepository"]}/process.py {ApplicationContext.Current.Configuration["PythonRepository"]}/settings.json {task.InputImageFilePath} {task.OutputImageFilePath}";

                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);
                    }
                }

                dbContext.Tasks.Single(t => t.Id == task.Id).Status = (int)MeasureTaskStatus.Segmented;
                dbContext.SaveChanges();
            }

            Console.WriteLine("ProcessImageJob finished.");
            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }