Esempio n. 1
0
        public ActionResult <ImageProgressResponse> CompareImagesSync(IFormFile[] files)
        {
            ImageProgressResponse response = new ImageProgressResponse();

            var requestValidationErrors = _requestValidator.ValidateFiles(files);

            if (requestValidationErrors.Count > 0)
            {
                return(CreateBadRequestResponse(response, requestValidationErrors).ToHttpResponse());
            }

            var originalImages = _formFileUtilities.ConvertFilesToImages(files);

            requestValidationErrors = _requestValidator.ValidateImages(originalImages);
            if (requestValidationErrors.Count > 0)
            {
                return(CreateBadRequestResponse(response, requestValidationErrors).ToHttpResponse());
            }

            var foundDiffObjects = _objectsFinder.FindAllDiffObjects(originalImages[0], originalImages[1]).ToArray();
            var resultImageData  = _imageGenerator.DrawRectangles(_formFileUtilities.SerializeFile(files[0]), files[0].ContentType, foundDiffObjects);

            int newImageId = GenerateImageId();

            SaveResutlImageToStorage(new ResultImage(newImageId, resultImageData, 100, files[0].ContentType, 1));

            response.ImageId = newImageId;
            response.Percent = 100;
            return(response.ToHttpResponse());
        }
Esempio n. 2
0
        public ActionResult <ImageProgressResponse> CompareImagesAsync(IFormFile[] files)
        {
            ImageProgressResponse response = new ImageProgressResponse();

            var requestValidationErrors = _requestValidator.ValidateFiles(files);

            if (requestValidationErrors.Count > 0)
            {
                return(CreateBadRequestResponse(response, requestValidationErrors).ToHttpResponse());
            }

            var originalImages = _formFileUtilities.ConvertFilesToImages(files);

            requestValidationErrors = _requestValidator.ValidateImages(originalImages);
            if (requestValidationErrors.Count > 0)
            {
                return(CreateBadRequestResponse(response, requestValidationErrors).ToHttpResponse());
            }

            int newImageId = GenerateImageId();

            SaveResutlImageToStorage(new ResultImage(newImageId, _formFileUtilities.SerializeFile(files[0]), 0,
                                                     files[0].ContentType, 1));

            response.ImageId = newImageId;

            FindObjectsAsync(originalImages, newImageId);

            return(response.ToHttpResponse());
        }
Esempio n. 3
0
        public ActionResult <ImageProgressResponse> GetImageProgress(int imageId)
        {
            ImageProgressResponse response = new ImageProgressResponse();

            var resultImage = _imageStorage.Get(imageId);

            if (resultImage == null)
            {
                response.HttpStatusCode = HttpStatusCode.NotFound;
            }
            else
            {
                response.ImageId      = resultImage.ImageId;
                response.Percent      = resultImage.PercentsProcessed;
                response.ImageVersion = resultImage.ImageVersion;
            }

            return(response.ToHttpResponse());
        }