public static async void PublishTopic(QueryEvent qe) { const string ServiceBusConnectionString = "Endpoint=sb://cloud2fidosb.servicebus.windows.net/;SharedAccessKeyName=TheWriter;SharedAccessKey=0c3IeFz15pod35soz15yzBVtyj/Pyxx856Q3ty82ufA="; const string TopicName = "cloud2fidotopic"; ITopicClient topicClient = new TopicClient(ServiceBusConnectionString, TopicName); var message = new Message(Encoding.UTF8.GetBytes(RegisterQuery.ToJSON <QueryEvent>(qe))); await topicClient.SendAsync(message); await topicClient.CloseAsync(); }
public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log) { log.Info($"Webhook was triggered!"); try { // Deserialize the request var request = new Request(); var ms = await req.Content.ReadAsStreamAsync(); RegisterQuery.FromJSON <Request>(ms, out request); log.Info("Request Deserialized"); //create queryevent var qe = new QueryEvent(request); log.Info("QueryEvent Created"); //create blob log.Info($"Creating Blob contrainer"); await RegisterQuery.CreateBlobContainer(qe.QueryID); log.Info("Blob " + qe.QueryID + " Created"); log.Info("Publishing topic"); // publish event RegisterQuery.PublishTopic(qe); log.Info("Topic Published"); return(req.CreateResponse(HttpStatusCode.OK, new { body = string.Format("{{\"QueryID\" : \"{0}\"}}", qe.QueryID) })); } catch (Exception e) { log.Info("Error Occured"); log.Info(e.InnerException.ToString()); return(req.CreateResponse(HttpStatusCode.InternalServerError, new { body = string.Format("{{\"Error\" : \"{0}\"}}", e.ToString()) })); } }