public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "activities")]
            HttpRequestMessage req,
            [Queue("unprocessed-feed-items", Connection = "AzureWebJobsStorage")] ICollector <ActivityDTO> updateQueue,
            TraceWriter log)
        {
            log.Info("Activity Controller invoked by Streams webhook.");
            if (req.Method == HttpMethod.Get)
            {
                // stream api requires that the webhook answer back with the stream api key
                return(req.CreateResponse(HttpStatusCode.OK, "pgm68aj7ec9e"));
            }

            try
            {
                var jsonStream = req.Content.ReadAsStreamAsync();
                var serializer = new JsonSerializer();

                using (var streamReader = new StreamReader(jsonStream.Result))
                {
                    // todo: fix this ugliness. There's got to be a better way to do this.
                    var dataString = streamReader.ReadToEnd();
                    log.Info(dataString);
                    // todo: serialize the updates
                    var data = FeedUpdateDTO.FromJson(dataString);
                    return(req.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception e)
            {
                log.Error(e.StackTrace);
                return(req.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
Exemplo n.º 2
0
        // todo: This only tests inserts. Add tests for deleted items also
        public void Valid_FeedUpdateDTO_Succeeds(string jsonDataFilePath)
        {
            Assembly thisAssembly = Assembly.GetExecutingAssembly();
            var      stream       = thisAssembly.GetManifestResourceStream(jsonDataFilePath);
            var      sample       = new StreamReader(stream).ReadToEnd();

            JObject[] updates       = JArray.Parse(sample).Select(j => (JObject)j).ToArray();
            var       feedUpdateDTO = FeedUpdateDTO.FromJson(updates[0]);

            Assert.NotNull(feedUpdateDTO);
            Assert.NotEmpty(feedUpdateDTO.AppId);
            Assert.NotNull(feedUpdateDTO.DatePublished);
            Assert.NotNull(feedUpdateDTO.Feed);
            Assert.Single(feedUpdateDTO.ActivitiesAdded);
            Assert.Empty(feedUpdateDTO.ActivitiesDeleted);
            feedUpdateDTO.ActivitiesAdded.ToList().ForEach(a =>
            {
                Assert.NotEmpty(a.Id);
                Assert.NotEmpty(a.Verb);
                Assert.NotEmpty(a.Actor);
                Assert.NotEmpty(a.Time);
            }
                                                           );
        }
 public static void Run([QueueTrigger("stream-updates-queue", Connection = "AzureWebJobsStorage")] FeedUpdateDTO feedUpdate, TraceWriter log)
 {
     log.Info($"C# Queue trigger function processed: {feedUpdate}");
 }