public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "emoji/{emoji}")] HttpRequest req, string emoji, ILogger log) { if (!string.IsNullOrWhiteSpace(emoji) && EmojiMetadata.Lookup.ContainsKey(emoji)) { var emojiEntity = await EmojiTable.GetEmoji( EmojiMetadata.Lookup[emoji].groupId.ToString(EmojiMetadata.IdFormat), EmojiMetadata.Lookup[emoji].emojiId.ToString(EmojiMetadata.IdFormat)); if (emojiEntity != null) { var jsonObject = new { Group = emojiEntity.Group, SubGroup = emojiEntity.SubGroup, Emoji = emojiEntity.Emoji, Cldr = emojiEntity.Cldr, Codes = emojiEntity.Code.Split('_'), Keywords = emojiEntity.Keywords }; var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); return(new JsonResult(jsonObject, serializerSettings)); } } return(new NotFoundResult()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "emoji/random")] HttpRequest req, ILogger log) { var numOfGroups = EmojiMetadata.Groups.Count; var randomPartition = Random.Next(0, numOfGroups - 1); var gk = EmojiMetadata.Groups.Keys.ElementAt(randomPartition); var randomRowKey = Random.Next(EmojiMetadata.Groups[gk].min, EmojiMetadata.Groups[gk].max); var emoji = await EmojiTable.GetEmoji( randomPartition.ToString(EmojiMetadata.IdFormat), randomRowKey.ToString(EmojiMetadata.IdFormat)); var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); return(new JsonResult(new { emoji.Emoji, emoji.Cldr }, serializerSettings)); }