public static void Run([QueueTrigger("publish-insight")] string queueMessage, TraceWriter log)
 {
     log.Info($"Queue Message: {queueMessage}");
     MediaPublish insightPublish = JsonConvert.DeserializeObject<MediaPublish>(queueMessage);
     if (insightPublish != null)
     {
         MediaPublished insightPublished = MediaClient.PublishInsight(insightPublish);
         log.Info($"Insight Publish: {JsonConvert.SerializeObject(insightPublish)}");
         log.Info($"Insight Published: {JsonConvert.SerializeObject(insightPublished)}");
     }
 }
Beispiel #2
0
        public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log)
        {
            string notificationMessage = await req.Content.ReadAsStringAsync();

            log.Info($"Notification Message: {notificationMessage}");
            if (!string.IsNullOrEmpty(notificationMessage))
            {
                MediaJobNotification jobNotification = JsonConvert.DeserializeObject <MediaJobNotification>(notificationMessage);
                if (jobNotification != null)
                {
                    MediaPublish contentPublish = EnqueuePublish(jobNotification);
                    log.Info($"Content Publish: {JsonConvert.SerializeObject(contentPublish)}");
                }
            }
            return(req.CreateResponse(HttpStatusCode.OK));
        }
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestMessage req, TraceWriter log)
        {
            StringComparison stringComparison = StringComparison.OrdinalIgnoreCase;
            IEnumerable <KeyValuePair <string, string> > urlParameters = req.GetQueryNameValuePairs();
            string accountId = urlParameters.SingleOrDefault(q => string.Equals(q.Key, "account", stringComparison)).Value;
            string indexId   = urlParameters.SingleOrDefault(q => string.Equals(q.Key, "id", stringComparison)).Value;

            log.Info($"Account Id: {accountId}");
            log.Info($"Index Id: {indexId}");
            if (!string.IsNullOrEmpty(accountId) && !string.IsNullOrEmpty(indexId))
            {
                MediaPublish insightPublish = EnqueuePublish(accountId, indexId);
                log.Info($"Insight Publish: {JsonConvert.SerializeObject(insightPublish)}");
            }
            return(req.CreateResponse(HttpStatusCode.OK));
        }
        private static MediaPublish EnqueuePublish(string accountId, string indexId)
        {
            TableClient  tableClient    = new TableClient();
            string       tableName      = Constant.Storage.Table.InsightPublish;
            string       partitionKey   = accountId;
            string       rowKey         = indexId;
            MediaPublish insightPublish = tableClient.GetEntity <MediaPublish>(tableName, partitionKey, rowKey);

            if (insightPublish != null)
            {
                string      settingKey  = Constant.AppSettingKey.MediaPublishInsightQueue;
                string      queueName   = AppSetting.GetValue(settingKey);
                QueueClient queueClient = new QueueClient();
                queueClient.AddMessage(queueName, insightPublish);
            }
            return(insightPublish);
        }
Beispiel #5
0
        private static MediaPublish EnqueuePublish(MediaJobNotification jobNotification)
        {
            MediaPublish contentPublish = null;

            if (jobNotification.EventType == MediaJobNotificationEvent.JobStateChange &&
                jobNotification.Properties.OldState == MediaJobState.Processing &&
                jobNotification.Properties.NewState == MediaJobState.Finished)
            {
                TableClient tableClient  = new TableClient();
                string      tableName    = Constant.Storage.Table.ContentPublish;
                string      partitionKey = jobNotification.Properties.AccountName;
                string      rowKey       = jobNotification.Properties.JobId;
                contentPublish = tableClient.GetEntity <MediaPublish>(tableName, partitionKey, rowKey);
                if (contentPublish != null)
                {
                    string      settingKey  = Constant.AppSettingKey.MediaPublishContentQueue;
                    string      queueName   = AppSetting.GetValue(settingKey);
                    QueueClient queueClient = new QueueClient();
                    queueClient.AddMessage(queueName, contentPublish);
                }
            }
            return(contentPublish);
        }