Esempio n. 1
0
        public void ResultShouldBeSortedBySize()
        {
            _scanResult.Add(new ItemInfo {
                Size = 99, Name = "File1"
            });
            _scanResult.Add(new ItemInfo {
                Size = 10, Name = "File2"
            });

            _scanResult.Items[0].Name.Should().Be("File2");
            _scanResult.Items[1].Name.Should().Be("File1");
        }
Esempio n. 2
0
        public Task <ScanResult> ProcessImage(Stream bitmapStream)
        {
            var imageData = NSData.FromStream(bitmapStream);
            var image     = UIImage.LoadFromData(imageData);
            var v         = new VNImageOptions();

            if (image.CGImage == null)
            {
                throw new Exception("No image");
            }

            // TODO: Find a way to make orientation foolproof
            // (Probably convert stream to UIImage which has orientation encoded...)
            var requestHandler =
                new VNImageRequestHandler(image.CGImage, v);

            var completionSource = new TaskCompletionSource <ScanResult>();

            var request = new VNRecognizeTextRequest((vnRequest, error) =>
            {
                var results = vnRequest.GetResults <VNRecognizedTextObservation>();

                var scanResult = new ScanResult();
                foreach (var textObservation in results)
                {
                    var candidate = textObservation.TopCandidates(1).FirstOrDefault();
                    if (candidate != null)
                    {
                        scanResult.Add(GetBlock(candidate, textObservation));
                    }
                }
                completionSource.TrySetResult(scanResult);
            });

            requestHandler.Perform(new VNRequest[] { request }, out var nsError);
            // ReSharper disable once ConstantConditionalAccessQualifier
            if (!string.IsNullOrEmpty(nsError?.Description))
            {
                throw new Exception(nsError.Description);
            }

            return(completionSource.Task);
        }
Esempio n. 3
0
        public async Task GivenScanSucceed_ShouldReturnOKAndScanResult()
        {
            var scanResult = new ScanResult()
            {
                TotalFiles   = 1,
                TotalSize    = 99,
                TotalFolders = 1
            };

            scanResult.Add(new ItemInfo {
                LastWriteTime = DateTime.Now, Size = 99, Name = "File1"
            });

            _scanAgentMoq.Setup(x => x.ScanFolderAsync("ValidPath")).Returns(Task.FromResult(scanResult));
            var result = await _diskAgentController.Scan(new ScanDto { Path = "ValidPath" });

            if (result is Microsoft.AspNetCore.Mvc.ObjectResult objectResult)
            {
                objectResult.StatusCode.Should().Be(200);
                objectResult.Value.GetType().Should().Be(typeof(ScanResult));
            }
        }
Esempio n. 4
0
        public Task <ScanResult> ProcessImage(Stream bitmapStream)
        {
            if (!_recognizer.IsOperational)
            {
                throw new Exception("Recognizer not operational.");
            }

            using var bitmap  = BitmapFactory.DecodeStream(bitmapStream);
            using var frame   = new Frame.Builder().SetBitmap(bitmap).Build();
            using var results = _recognizer.Detect(frame);
            var result = new ScanResult();

            for (var i = 0; i < results.Size(); i++)
            {
                var androidBlock = (TextBlock)results.ValueAt(i);
                if (androidBlock != null)
                {
                    result.Add(GetBlock(androidBlock));
                }
            }

            return(Task.FromResult(result));
        }