public void AddImageFile(Domain.ImageFile imageFile)
 {
     if (imageFile != null)
     {
         ImageFile dbImageFile    = Mapper.Map <ImageFile>(imageFile);
         ImageFile addedImageFile = _computerVisionContext.ImageFile.Add(dbImageFile).Entity;
         _computerVisionContext.SaveChanges();
     }
 }
        public void AddDetectFaces(Domain.ImageFile imageFile, List <AzureFaceModels.DetectedFace> detectedFaces)
        {
            ImageFile dbImageFile = _computerVisionContext.ImageFile.SingleOrDefault(x => x.HashString == imageFile.HashString);

            List <DetectedFace> dbDetectedFaces = Mapper.Map <List <DetectedFace> >(detectedFaces);

            dbDetectedFaces.ForEach(x => x.ImageFileId = dbImageFile.Id);
            _computerVisionContext.DetectedFace.AddRange(dbDetectedFaces);
            _computerVisionContext.SaveChanges();
        }
        public Domain.ImageFile GetImageFile(Domain.ImageFile imageFile)
        {
            ImageFile savedImageFile = _computerVisionContext.ImageFile.SingleOrDefault(x => x.HashString == imageFile.HashString);

            if (savedImageFile != null)
            {
                return(Mapper.Map <Domain.ImageFile>(savedImageFile));
            }
            else
            {
                return(null);
            }
        }
        public void AddImageAnalysis(Domain.ImageFile imageFile, AzureCvModels.ImageAnalysis imageAnalysis)
        {
            ImageAnalysis dbImageAnalysis    = Mapper.Map <ImageAnalysis>(imageAnalysis);
            ImageAnalysis addedImageAnalysis = _computerVisionContext.ImageAnalysis.Add(dbImageAnalysis).Entity;

            _computerVisionContext.SaveChanges();
            ImageFile dbImageFile = _computerVisionContext.ImageFile.SingleOrDefault(x => x.HashString == imageFile.HashString);

            if (dbImageFile != null)
            {
                dbImageFile.AnylysisId = addedImageAnalysis.Id;
            }
            _computerVisionContext.SaveChanges();
        }
        public AzureCvModels.RecognitionResult GetRecognitionResult(Domain.ImageFile imageFile, AzureCvModels.TextRecognitionMode textRecognitionMode)
        {
            ImageFile dbImageFile = _computerVisionContext.ImageFile.SingleOrDefault(x => x.HashString == imageFile.HashString);

            if (dbImageFile != null)
            {
                RecognitionResult dbRecognitionResult             = GetRecognitionResult(dbImageFile, textRecognitionMode);
                AzureCvModels.RecognitionResult recognitionResult = null;
                if (dbRecognitionResult != null)
                {
                    recognitionResult = Mapper.Map <AzureCvModels.RecognitionResult>(dbRecognitionResult);
                }
                return(recognitionResult);
            }

            return(null);
        }
        public AzureCvModels.ImageAnalysis GetImageAnalysis(Domain.ImageFile imageFile)
        {
            ImageFile dbImageFile = _computerVisionContext.ImageFile.SingleOrDefault(x => x.HashString == imageFile.HashString);

            if (dbImageFile != null)
            {
                ImageAnalysis dbImageAnalysis             = GetImageAnalysis(dbImageFile);
                AzureCvModels.ImageAnalysis imageAnalysis = null;
                if (dbImageAnalysis != null)
                {
                    imageAnalysis = Mapper.Map <AzureCvModels.ImageAnalysis>(dbImageAnalysis);
                }
                return(imageAnalysis);
            }

            return(null);
        }
        public List <AzureFaceModels.DetectedFace> GetDetectFaces(Domain.ImageFile imageFile)
        {
            List <AzureFaceModels.DetectedFace> result = null;
            ImageFile dbImageFile = _computerVisionContext.ImageFile.SingleOrDefault(x => x.HashString == imageFile.HashString);

            if (dbImageFile != null)
            {
                List <DetectedFace> dbDetectedFaces = GetDetectedFace(dbImageFile);
                if (dbDetectedFaces?.Count > 0)
                {
                    result = Mapper.Map <List <AzureFaceModels.DetectedFace> >(dbDetectedFaces);
                }

                return(result);
            }

            return(null);
        }
        public void AddRecognitionResult(Domain.ImageFile imageFile, AzureCvModels.RecognitionResult recognizeText, AzureCvModels.TextRecognitionMode textRecognitionMode)
        {
            RecognitionResult dbRecognizeText    = Mapper.Map <RecognitionResult>(recognizeText);
            RecognitionResult addedRecognizeText = _computerVisionContext.RecognitionResult.Add(dbRecognizeText).Entity;

            _computerVisionContext.SaveChanges();
            ImageFile dbImageFile = _computerVisionContext.ImageFile.SingleOrDefault(x => x.HashString == imageFile.HashString);

            if (dbImageFile != null && textRecognitionMode == AzureCvModels.TextRecognitionMode.Printed)
            {
                dbImageFile.PrintedRecognitionResultId = addedRecognizeText.Id;
            }
            else if (dbImageFile != null && textRecognitionMode == AzureCvModels.TextRecognitionMode.Handwritten)
            {
                dbImageFile.HandwrittenRecognitionResultId = addedRecognizeText.Id;
            }
            _computerVisionContext.SaveChanges();
        }
Esempio n. 9
0
        public async Task <BlobInfo> AddImageFileIfMissing(Domain.ImageFile imageFile, byte[] bytes)
        {
            CloudStorageAccount storageAccount     = null;
            CloudBlobContainer  cloudBlobContainer = null;


            if (CloudStorageAccount.TryParse(_storageConnectionString, out storageAccount))
            {
                try
                {
                    CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

                    cloudBlobContainer = cloudBlobClient.GetContainerReference("images");
                    await cloudBlobContainer.CreateIfNotExistsAsync();

                    BlobContainerPermissions permissions = new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Off
                    };
                    await cloudBlobContainer.SetPermissionsAsync(permissions);

                    CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(imageFile.HashString + ".jpg");
                    if (!await cloudBlockBlob.ExistsAsync())
                    {
                        await cloudBlockBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);
                    }
                    string sasToken = GetSasToken();
                    string uri      = cloudBlockBlob.Uri.ToString();
                    return(new BlobInfo
                    {
                        Uri = uri,
                        UriWithSasToken = uri + sasToken,
                        SasToken = sasToken,
                    });
                    //Console.WriteLine("Listing blobs in container.");
                    //BlobContinuationToken blobContinuationToken = null;
                    //do
                    //{
                    //    var results = await cloudBlobContainer.ListBlobsSegmentedAsync(null, blobContinuationToken);
                    //    // Get the value of the continuation token returned by the listing call.
                    //    blobContinuationToken = results.ContinuationToken;
                    //    foreach (IListBlobItem item in results.Results)
                    //    {
                    //        Console.WriteLine(item.Uri);
                    //    }
                    //} while (blobContinuationToken != null); // Loop while the continuation token is not null.
                    //Console.WriteLine();

                    //// Download the blob to a local file, using the reference created earlier.
                    //// Append the string "_DOWNLOADED" before the .txt extension so that you can see both files in MyDocuments.
                    //destinationFile = sourceFile.Replace(".txt", "_DOWNLOADED.txt");
                    //Console.WriteLine("Downloading blob to {0}", destinationFile);
                    //Console.WriteLine();
                    //await cloudBlockBlob.DownloadToFileAsync(destinationFile, FileMode.Create);
                }
                catch (StorageException ex)
                {
                }
            }
            return(null);
        }