Exemplo n.º 1
0
        public static async Task <string> Run
        (
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req,
            TraceWriter log
        )
        {
            try
            {
                var gifRepo = new GifRepository(log);

                var gif = CreateEntity(req, gifRepo);
                log.Info($"In testPost: new Entity: index: {gif.RowKey}, image_url: {gif.image_url}, text: {gif.text}");

                var insertResult = await gifRepo.AddGifsercise(gif);

                if (insertResult.HttpStatusCode < 300)
                {
                    var rowResult = gifRepo.UpdateRowCount();
                    log.Info($"Successful put gifsercise. new max index: {rowResult}.");

                    return($"Successfully addded gif with index: {rowResult}, url: {gif.image_url}, text: '{gif.text}' and statusCode: {insertResult.HttpStatusCode}.");
                }
                else
                {
                    log.Info($"failed a put request with result {insertResult.Result.ToString()}");
                    return($"Failed to add new Gifsercise {insertResult.Result.ToString()}");
                }
            }
            catch (System.Exception ex)
            {
                log.Error($"insert unsuccessful", ex);
                return($"Insert unsuccessful {ex.Message}, {ex.StackTrace}");
            }
        }
Exemplo n.º 2
0
        private static GifserciseEntity CreateEntity(HttpRequestMessage req, GifRepository repo)
        {
            var newGifIndex = repo.GetGifCount() + 1;

            var valuePairs = req.Content.ReadAsFormDataAsync().Result;

            char[] splitter = { ' ' };

            return(new GifserciseEntity(
                       partition: "gif",
                       row: newGifIndex.ToString(),
                       url: valuePairs["text"].Split(splitter, 2)[0],
                       text: valuePairs["text"].Split(splitter, 2)[1]
                       ));
        }
Exemplo n.º 3
0
        public static void Run([TimerTrigger("0 26 9-17 * * 1-5")] TimerInfo myTimer, TraceWriter log)
        {
            var gifRepo = new GifRepository(log);

            var slackMessage = gifRepo.GetGifsercise();

            var result = PostToSlack(slackMessage);

            if ((int)result.Result.StatusCode < 300)
            {
                log.Info($@"Successfully posted gif with url: {slackMessage.image_url}, 
                        text: '{slackMessage.text}' and statusCode: {result.Result.StatusCode}.");
            }
            else
            {
                log.Info($"failed to post to Slack with result {result.Result.ToString()}");
            }
        }