示例#1
0
        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));
        }
示例#2
0
        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));
        }