public static IActionResult RunCryptonymLinkerForLists([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext executionContext)
        {
            string skillName = executionContext.FunctionName;
            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null)
            {
                return(new BadRequestObjectResult($"{skillName} - Invalid request record array."));
            }

            CryptonymLinker     cryptonymLinker = new CryptonymLinker(executionContext.FunctionAppDirectory);
            WebApiSkillResponse response        = WebApiSkillHelpers.ProcessRequestRecords(skillName, requestRecords,
                                                                                           (inRecord, outRecord) => {
                var words   = JsonConvert.DeserializeObject <JArray>(JsonConvert.SerializeObject(inRecord.Data["words"]));
                var cryptos = words.Select(jword =>
                {
                    var word = jword.Value <string>();
                    if (word.All(Char.IsUpper) && cryptonymLinker.Cryptonyms.TryGetValue(word, out string description))
                    {
                        return(new { value = word, description });
                    }
                    return(null);
                });

                outRecord.Data["cryptonyms"] = cryptos.ToArray();
                return(outRecord);
            });

            return((ActionResult) new OkObjectResult(response));
        }
        public static IActionResult RunHocrGenerator([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext executionContext)
        {
            string skillName = executionContext.FunctionName;
            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null || requestRecords.Count() != 1)
            {
                return(new BadRequestObjectResult($"{skillName} - Invalid request record array: Skill requires exactly 1 image per request."));
            }

            WebApiSkillResponse response = WebApiSkillHelpers.ProcessRequestRecords(skillName, requestRecords,
                                                                                    (inRecord, outRecord) => {
                List <OcrImageMetadata> imageMetadataList = JsonConvert.DeserializeObject <List <OcrImageMetadata> >(JsonConvert.SerializeObject(inRecord.Data["ocrImageMetadataList"]));

                List <HocrPage> pages = new List <HocrPage>();
                for (int i = 0; i < imageMetadataList.Count; i++)
                {
                    pages.Add(new HocrPage(imageMetadataList[i], i));
                }
                HocrDocument hocrDocument      = new HocrDocument(pages);
                outRecord.Data["hocrDocument"] = hocrDocument;
                return(outRecord);
            });

            return((ActionResult) new OkObjectResult(response));
        }
        public static async Task <IActionResult> RunImageStore([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext executionContext)
        {
            string skillName = executionContext.FunctionName;
            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null || requestRecords.Count() != 1)
            {
                return(new BadRequestObjectResult($"{skillName} - Invalid request record array: Skill requires exactly 1 image per request."));
            }

            string blobStorageConnectionString = GetAppSetting("BlobStorageAccountConnectionString");
            string blobContainerName           = String.IsNullOrEmpty(req.Headers["BlobContainerName"]) ? Config.AZURE_STORAGE_CONTAINER_NAME : (string)req.Headers["BlobContainerName"];

            if (String.IsNullOrEmpty(blobStorageConnectionString) || String.IsNullOrEmpty(blobContainerName))
            {
                return(new BadRequestObjectResult($"{skillName} - Information for the blob storage account is missing"));
            }
            ImageStore imageStore = new ImageStore(blobStorageConnectionString, blobContainerName);

            WebApiSkillResponse response = await WebApiSkillHelpers.ProcessRequestRecordsAsync(skillName, requestRecords,
                                                                                               async (inRecord, outRecord) => {
                string imageData = inRecord.Data["imageData"] as string;
                string imageUri  = await imageStore.UploadToBlob(imageData, Guid.NewGuid().ToString());
                outRecord.Data["imageStoreUri"] = imageUri;
                return(outRecord);
            });

            return((ActionResult) new OkObjectResult(response));
        }
        public static IActionResult RunCryptonymLinker([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, TraceWriter log, ExecutionContext executionContext)
        {
            string skillName = executionContext.FunctionName;
            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null)
            {
                return(new BadRequestObjectResult($"{skillName} - Invalid request record array."));
            }

            CryptonymLinker     cryptonymLinker = new CryptonymLinker(executionContext.FunctionAppDirectory);
            WebApiSkillResponse response        = WebApiSkillHelpers.ProcessRequestRecords(skillName, requestRecords,
                                                                                           (inRecord, outRecord) => {
                string word = inRecord.Data["word"] as string;
                if (word.All(Char.IsUpper) && cryptonymLinker.Cryptonyms.TryGetValue(word, out string description))
                {
                    outRecord.Data["cryptonym"] = new { value = word, description };
                }
                return(outRecord);
            });

            return((ActionResult) new OkObjectResult(response));
        }