public static async Task <HttpResponseMessage> UpdateWaterMarkCode([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            IActionsProvider myActions = ActionProviderFactory.GetActionProvider(SingleWaterMarkStorageAccInstanceController);
            dynamic          BodyData  = await req.Content.ReadAsAsync <object>();

            try
            {
                EnbebedCode myCode                  = BodyData.EnbebedCode.ToObject <EnbebedCode>();
                string      ParentAssetID           = BodyData.ParentAssetID;
                List <WaterMarkedRender> RenderList = new List <WaterMarkedRender>();
                foreach (var info in myCode.MP4WatermarkedURL)
                {
                    WaterMarkedRender data = new WaterMarkedRender()
                    {
                        Details          = "Submited",
                        EmbebedCodeValue = myCode.EmbebedCode,
                        MP4URL           = info.WaterMarkedMp4,
                        RenderName       = info.FileName,
                        ParentAssetID    = ParentAssetID,
                        State            = ExecutionStatus.Running
                    };
                    RenderList.Add(data);
                }
                //Update all renders in a single call
                await myActions.UpdateWaterMarkedRender(RenderList);
            }
            catch (Exception X)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, new { Error = X.Message }, JsonMediaTypeFormatter.DefaultMediaType));
            }

            return(req.CreateResponse(HttpStatusCode.OK, new { Status = ExecutionStatus.Finished.ToString() }, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public async Task <int> EvalPEmbeddedNotifications()
        {
            int nNotification            = 0;
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("embeddernotification");

            foreach (CloudQueueMessage message in await queue.GetMessagesAsync(20, TimeSpan.FromMinutes(60), null, null))
            {
                try
                {
                    NotificationEmbedder rawdata = Newtonsoft.Json.JsonConvert.DeserializeObject <NotificationEmbedder>(message.AsString);
                    WaterMarkedRender    data    = GetWaterMarkedRender(rawdata.AssetID, rawdata.EmbebedCode, rawdata.FileName);
                    string url = data.MP4URL;
                    data = new WaterMarkedRender(rawdata, url);
                    var outputData = UpdateWaterMarkedRender(data);
                }
                catch (Exception X)
                {
                    Trace.TraceError($"EvalPEmbeddedNotifications Error: {X.Message}");
                    CloudQueue deadletter = queueClient.GetQueueReference("deadletter");
                    await deadletter.AddMessageAsync(message);
                }
                await queue.DeleteMessageAsync(message);

                nNotification += 1;
            }
            return(nNotification);
        }
Example #3
0
        public async Task <int> EvalPEmbeddedNotifications(string JobId)
        {
            int nNotification            = 0;
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("embeddernotification");

            //Process more than 32 message
            for (int i = 0; i < _embeddedmessagecount; i++)
            {
                bool swMetaLoop = true;
                foreach (CloudQueueMessage message in await queue.GetMessagesAsync(_embeddedmessagecount, TimeSpan.FromMinutes(10), null, null))
                {
                    swMetaLoop = false;
                    //Trace.TraceInformation($"[{JobId}] {message.AsString}");
                    try
                    {
                        NotificationEmbedder rawdata = Newtonsoft.Json.JsonConvert.DeserializeObject <NotificationEmbedder>(message.AsString);
                        rawdata.JobID = rawdata.JobID.Split('-')[0];
                        Trace.TraceInformation($"JobId={JobId} and messageJobId={rawdata.JobID}");
                        // This message if for JOB
                        WaterMarkedRender data = GetWaterMarkedRender(rawdata.AssetID, rawdata.EmbebedCode, rawdata.FileName);
                        string            url  = data.MP4URL;
                        //Adding Idempotent control for exceptional case of recieve multiple time
                        //notifications from K8S container (fail on container)
                        if (data.State == ExecutionStatus.Running)
                        {
                            //WatermarkRender is on right state(first message)
                            data = new WaterMarkedRender(rawdata, url);
                            var outputData = UpdateWaterMarkedRender(data);
                            Trace.TraceInformation($"{JobId} processesd Message {rawdata.Status} ");
                        }
                        else
                        {
                            //poison message, means Embbedecode was already porcessed
                            Trace.TraceInformation($"{rawdata.JobID} Idenpotent Message Control  {message.AsString}");
                            await SendToDeadLetterQueue(queueClient, message.AsString);
                        }
                    }
                    catch (Exception X)
                    {
                        Trace.TraceError($"[{JobId}] EvalPEmbeddedNotifications Error: {X.Message}");
                        await SendToDeadLetterQueue(queueClient, message.AsString);
                    }

                    await queue.DeleteMessageAsync(message);

                    nNotification += 1;
                }

                //No more Message
                if (swMetaLoop)
                {
                    Trace.TraceInformation($"[{JobId}] No more messages");
                    break;
                }
            }
            return(nNotification);
        }
        public static async Task <HttpResponseMessage> UpdateWaterMarkCode([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            IActionsProvider myActions = ActionProviderFactory.GetActionProvider();
            dynamic          BodyData  = await req.Content.ReadAsAsync <object>();

            EnbebedCode myCode        = BodyData.EnbebedCode.ToObject <EnbebedCode>();
            string      ParentAssetID = BodyData.ParentAssetID;

            foreach (var info in myCode.MP4WatermarkedURL)
            {
                WaterMarkedRender data = new WaterMarkedRender()
                {
                    Details          = "Submited",
                    EmbebedCodeValue = myCode.EmbebedCode,
                    MP4URL           = info.WaterMarkedMp4,
                    RenderName       = info.FileName,
                    ParentAssetID    = ParentAssetID,
                    State            = ExecutionStatus.Running
                };
                myActions.UpdateWaterMarkedRender(data);
                var outputData = myActions.UpdateWaterMarkedRender(data);
            }
            return(req.CreateResponse(HttpStatusCode.OK, new { Status = ExecutionStatus.Finished.ToString() }, JsonMediaTypeFormatter.DefaultMediaType));
        }