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

            UnifiedProcessStatus myProcessStatus = BodyData.ToObject <UnifiedProcessStatus>();
            IActionsProvider     myActions       = ActionProviderFactory.GetActionProvider();

            //Check AssetStatus

            switch (myProcessStatus.AssetStatus.State)
            {
            case ExecutionStatus.Error:
                //Finished with error
                myProcessStatus.JobStatus.State      = ExecutionStatus.Error;
                myProcessStatus.JobStatus.FinishTime = DateTime.Now;
                myProcessStatus.JobStatus.Duration   = DateTime.Now.Subtract(myProcessStatus.JobStatus.StartTime);
                myActions.UpdateUnifiedProcessStatus(myProcessStatus);
                break;

            case ExecutionStatus.Running:
                //Same status for JOB
                //No Action
                myProcessStatus.JobStatus.State = ExecutionStatus.Running;

                var mmrklist = myActions.GetMMRKStatusList(myProcessStatus.AssetStatus.AssetId);

                int mmrkTotal    = mmrklist.Count();
                int mmrkFinished = mmrklist.Where(m => m.State == ExecutionStatus.Finished).Count();

                myProcessStatus.JobStatus.Details = $"Generating MMRK files {mmrkFinished} of {mmrkTotal}, last update {DateTime.Now.ToString()}";

                //var jobinfo = myActions.GetJobK8SDetail(myProcessStatus.JobStatus.JobID + "-1");
                //myProcessStatus.JobStatus.Details += Newtonsoft.Json.JsonConvert.SerializeObject(jobinfo, Newtonsoft.Json.Formatting.Indented);

                break;

            case ExecutionStatus.Finished:
                //Check EmbebedCodeList
                int nRunning = myProcessStatus.EmbebedCodesList.Where(emc => emc.State == ExecutionStatus.Running).Count();
                log.Info($"Current EMC Running {nRunning}");
                if (nRunning == 0)
                {
                    myProcessStatus.JobStatus.State      = ExecutionStatus.Finished;
                    myProcessStatus.JobStatus.FinishTime = DateTime.Now;
                    myProcessStatus.JobStatus.Duration   = DateTime.Now.Subtract(myProcessStatus.JobStatus.StartTime);
                    myProcessStatus.JobStatus.Details    = "Finished";
                }
                else
                {
                    int total = myProcessStatus.EmbebedCodesList.Count();
                    myProcessStatus.JobStatus.State   = ExecutionStatus.Running;
                    myProcessStatus.JobStatus.Details = $"Watermaerked copies {(total - nRunning)} of {total}";
                }
                myActions.UpdateUnifiedProcessStatus(myProcessStatus);
                log.Info($"Updated Manifest JOB Status {myProcessStatus.JobStatus.State.ToString()}");
                break;
            }

            return(req.CreateResponse(HttpStatusCode.OK, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public static async Task <HttpResponseMessage> EvalAssetStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus manifest = BodyData.ToObject <UnifiedProcessStatus>();

            IActionsProvider myActions = ActionProviderFactory.GetActionProvider(SingleWaterMarkStorageAccInstanceController);
            //1. Update EvalPreprocessorNotifications
            int nNotification = await myActions.EvalPreprocessorNotifications(manifest.JobStatus.JobID);

            //2. Eval Asset Status
            var OriginalAssetStatus = manifest.AssetStatus.State;

            manifest.AssetStatus = myActions.EvalAssetStatus(manifest.AssetStatus.AssetId);
            if (OriginalAssetStatus != manifest.AssetStatus.State)
            {
                //3. Update Manifest/ all process
                await myActions.UpdateUnifiedProcessStatus(manifest);

                //4. Log and replay
                log.Info($"[{manifest.JobStatus.JobID}] Preprocessor Notifications processed {nNotification} / Updated AssetId {manifest.AssetStatus.AssetId} Status {manifest.AssetStatus.State.ToString()} / previus status {OriginalAssetStatus}");
            }
            else
            {
                log.Info($"[{manifest.JobStatus.JobID}] Preprocessor Notifications processed {nNotification} / No Change AssetId {manifest.AssetStatus.AssetId} Status {OriginalAssetStatus}");
            }
            return(req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public static async Task <HttpResponseMessage> EvalEnbebedCodes([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            IActionsProvider myActions = ActionProviderFactory.GetActionProvider();
            dynamic          BodyData  = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus manifest = BodyData.ToObject <UnifiedProcessStatus>();
            string ParentAssetID          = manifest.AssetStatus.AssetId;
            //1. Process Embbeded Notifications
            int nNotification = await myActions.EvalPEmbeddedNotifications();

            log.Info($"Embedded Notifications processed {nNotification}");
            //2. Eval Each Watermark Render status
            List <WaterMarkedAssetInfo> UpdatedInfo = new List <WaterMarkedAssetInfo>();

            foreach (var item in manifest.EmbebedCodesList)
            {
                UpdatedInfo.Add(myActions.EvalWaterMarkedAssetInfo(ParentAssetID, item.EmbebedCodeValue));
            }
            //Replace New WaterMarkAssetInfo
            manifest.EmbebedCodesList = UpdatedInfo;
            //
            myActions.UpdateUnifiedProcessStatus(manifest);

            return(req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }
Exemplo n.º 4
0
        public static async Task <HttpResponseMessage> CreateWaterMArkedAssets([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            IActionsProvider myActions = ActionProviderFactory.GetActionProvider();

            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus manifest = BodyData.ToObject <UnifiedProcessStatus>();
            string ParentAssetID          = manifest.AssetStatus.AssetId;

            List <WaterMarkedAssetInfo> UpdatedInfo = new List <WaterMarkedAssetInfo>();

            try
            {
                //List only Finished without AsstID
                foreach (var watermarkedInfo in manifest.EmbebedCodesList)
                {
                    if ((watermarkedInfo.State == ExecutionStatus.Finished) && (string.IsNullOrEmpty(watermarkedInfo.AssetID)))
                    {
                        //Create new asset per embbeded code
                        IAMSProvider help = AMSProviderFactory.CreateAMSProvider();
                        var          xx   = await help.CreateEmptyWatermarkedAsset(manifest.JobStatus.JobID, ParentAssetID, watermarkedInfo.EmbebedCodeValue);

                        watermarkedInfo.AssetID = xx.WMAssetId;
                        ////Inject all Renders on New asset
                        foreach (var render in myActions.GetWaterMarkedRenders(ParentAssetID, watermarkedInfo.EmbebedCodeValue))
                        {
                            string url = render.MP4URL;
                            var    r   = await help.AddWatermarkedMediaFiletoAsset(watermarkedInfo.AssetID, watermarkedInfo.EmbebedCodeValue, url);

                            if (r.Status != "MMRK File Added")
                            {
                                //Error
                                watermarkedInfo.State   = ExecutionStatus.Error;
                                watermarkedInfo.Details = $"Error adding {render.RenderName} deatils: {r.StatusMessage}";
                                //Delete Asset
                                help.DeleteAsset(watermarkedInfo.AssetID);
                                watermarkedInfo.AssetID = "";
                                //Abort
                                break;
                            }
                        }
                        //Create New Manifest and set it as primary file.
                        await help.GenerateManifest(watermarkedInfo.AssetID);
                    }
                    UpdatedInfo.Add(watermarkedInfo);
                }
                //Replace New WaterMarkAssetInfo
                manifest.EmbebedCodesList = UpdatedInfo;

                myActions.UpdateUnifiedProcessStatus(manifest);
            }
            catch (Exception X)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType));
            }
            return(req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public static async Task <HttpResponseMessage> EvalAssetStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus manifest = BodyData.ToObject <UnifiedProcessStatus>();

            IActionsProvider myActions = ActionProviderFactory.GetActionProvider();
            //1. Update EvalPreprocessorNotifications
            int nNotification = await myActions.EvalPreprocessorNotifications();

            log.Info($"Preprocessor Notifications processed {nNotification}");
            //2. Eval Asset Status
            manifest.AssetStatus = myActions.EvalAssetStatus(manifest.AssetStatus.AssetId);
            //3. Update Manifest/ all process
            myActions.UpdateUnifiedProcessStatus(manifest);
            //4. Log and replay
            log.Info($"Updated Actions AssetId {manifest.AssetStatus.AssetId} staus {manifest.AssetStatus.ToString()}");
            return(req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public static async Task <HttpResponseMessage> UpdateJob([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            IActionsProvider myActions = ActionProviderFactory.GetActionProvider();

            UnifiedProcessStatus Manifest = BodyData.Manifest.ToObject <UnifiedProcessStatus>();

            ExecutionStatus AssetStatus = BodyData.AssetStatus.ToObject <ExecutionStatus>();

            ExecutionStatus JobState        = BodyData.JobState.ToObject <ExecutionStatus>();
            string          JobStateDetails = BodyData.JobStateDetails;

            ExecutionStatus WaterMarkCopiesStatus        = BodyData.WaterMarkCopiesStatus.ToObject <ExecutionStatus>();
            string          WaterMarkCopiesStatusDetails = BodyData.WaterMarkCopiesStatusDetails;

            switch (Manifest.AssetStatus.State)
            {
            case ExecutionStatus.Finished:
                AssetStatus = ExecutionStatus.Finished;
                break;

            case ExecutionStatus.Error:
                break;

            case ExecutionStatus.Running:
                break;

            case ExecutionStatus.New:
                break;

            case ExecutionStatus.Aborted:
                break;

            default:
                break;
            }
            var updatedManifest = myActions.UpdateJob(Manifest, AssetStatus, JobState, JobStateDetails, WaterMarkCopiesStatus, WaterMarkCopiesStatusDetails);

            return(req.CreateResponse(HttpStatusCode.OK, Manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public static async Task <HttpResponseMessage> CancelJobTimeOut([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log, ExecutionContext context)
        {
            var     watch    = System.Diagnostics.Stopwatch.StartNew();
            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            IActionsProvider     myActions       = ActionProviderFactory.GetActionProvider(SingleWaterMarkStorageAccInstanceController);
            UnifiedProcessStatus myProcessStatus = BodyData.ToObject <UnifiedProcessStatus>();

            try
            {
                myProcessStatus = myActions.GetUnifiedProcessStatus(myProcessStatus.AssetStatus.AssetId, myProcessStatus.JobStatus.JobID);
                myProcessStatus.JobStatus.State      = ExecutionStatus.Finished;
                myProcessStatus.JobStatus.Details    = $"Embedder copies time out, check copies status.";
                myProcessStatus.JobStatus.FinishTime = DateTime.Now;
                myProcessStatus.JobStatus.Duration   = DateTime.Now.Subtract(myProcessStatus.JobStatus.StartTime);

                //Update all running copies like Errro time out
                foreach (var copy in myProcessStatus.EmbebedCodesList.Where(c => (c.State == ExecutionStatus.Running)))
                {
                    copy.State   = ExecutionStatus.Error;
                    copy.Details = $"Timeout error: {copy.Details}";
                }
                //Update All Finished  copies without AssetID (No ASSET copy created)
                foreach (var copy in myProcessStatus.EmbebedCodesList.Where(c => (c.State == ExecutionStatus.Finished) && (string.IsNullOrEmpty(c.AssetID))))
                {
                    copy.State   = ExecutionStatus.Error;
                    copy.Details = $"Timeout error: {copy.Details}";
                }
                await myActions.UpdateUnifiedProcessStatus(myProcessStatus);
            }
            catch (Exception X)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType));
            }
            watch.Stop();
            log.Info($"[Time] Method CancelJobTimeOut {watch.ElapsedMilliseconds} [ms]");
            return(req.CreateResponse(HttpStatusCode.OK, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType));
        }
Exemplo n.º 8
0
        public static async Task <HttpResponseMessage> EvalEnbebedCodes([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            IActionsProvider myActions = ActionProviderFactory.GetActionProvider();
            dynamic          BodyData  = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus manifest = BodyData.ToObject <UnifiedProcessStatus>();
            string ParentAssetID          = manifest.AssetStatus.AssetId;

            try
            {
                //1. Process Embbeded Notifications (From share Queue)
                int nNotification = await myActions.EvalPEmbeddedNotifications(manifest.JobStatus.JobID);

                log.Info($"Embedded Notifications processed {nNotification}");
                //2. Eval Each Watermark Render status
                List <WaterMarkedAssetInfo> UpdatedInfo = new List <WaterMarkedAssetInfo>();
                foreach (var item in manifest.EmbebedCodesList)
                {
                    //2.1 EvalWatermarkeAssetInfo
                    var watermarkedRender = myActions.EvalWaterMarkedAssetInfo(ParentAssetID, item.EmbebedCodeValue);
                    UpdatedInfo.Add(watermarkedRender);
                    //log.Info($"{watermarkedRender.AssetID} status {watermarkedRender.State.ToString()}");
                }
                //Replace New WaterMarkAssetInfo
                manifest.EmbebedCodesList = UpdatedInfo;
                //
                myActions.UpdateUnifiedProcessStatus(manifest);
            }
            catch (Exception X)
            {
                log.Error($"[{manifest.JobStatus.JobID}] Error on EvalEnbebedCodes {X.Message}");
                return(req.CreateResponse(HttpStatusCode.InternalServerError, manifest, JsonMediaTypeFormatter.DefaultMediaType));
            }
            watch.Stop();
            log.Info($"[Time] Method EvalEnbebedCodes {watch.ElapsedMilliseconds} [ms]");
            return(req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public static async Task <HttpResponseMessage> GetUnifiedProcessStatus([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var     watch    = System.Diagnostics.Stopwatch.StartNew();
            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            IActionsProvider myActions = ActionProviderFactory.GetActionProvider(SingleWaterMarkStorageAccInstanceController);
            string           AssetId   = BodyData.AssetId;
            string           JobID     = BodyData.JobID;

            UnifiedProcessStatus myProcessStatus = null;

            try
            {
                myProcessStatus = myActions.GetUnifiedProcessStatus(AssetId, JobID);
            }
            catch (Exception X)
            {
                log.Error(X.Message);
                return(req.CreateResponse(HttpStatusCode.NotFound, X, JsonMediaTypeFormatter.DefaultMediaType));
            }
            watch.Stop();
            log.Info($"[Time] GetUnifiedProcessStatus {watch.ElapsedMilliseconds} [ms]");
            return(req.CreateResponse(HttpStatusCode.OK, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType));
        }
        public static async Task <HttpResponseMessage> EvalJobProgress([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var     watch    = System.Diagnostics.Stopwatch.StartNew();
            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus myProcessStatus = BodyData.ToObject <UnifiedProcessStatus>();
            IActionsProvider     myActions       = ActionProviderFactory.GetActionProvider(SingleWaterMarkStorageAccInstanceController);
            int watingCopies = 0;

            //Check AssetStatus
            log.Info($"[{myProcessStatus.JobStatus.JobID}] Job Status: {myProcessStatus.JobStatus.State.ToString()} / Asset Status {myProcessStatus.AssetStatus.State.ToString()}");
            switch (myProcessStatus.AssetStatus.State)
            {
            case ExecutionStatus.Error:
                //Finished with error
                myProcessStatus.JobStatus.State      = ExecutionStatus.Error;
                myProcessStatus.JobStatus.FinishTime = DateTime.Now;
                myProcessStatus.JobStatus.Duration   = DateTime.Now.Subtract(myProcessStatus.JobStatus.StartTime);
                await myActions.UpdateUnifiedProcessStatus(myProcessStatus);

                break;

            case ExecutionStatus.Running:
                //Same status for JOB
                //No Action
                myProcessStatus.JobStatus.State = ExecutionStatus.Running;
                var mmrklist     = myActions.GetMMRKStatusList(myProcessStatus.AssetStatus.AssetId);
                int mmrkTotal    = mmrklist.Count();
                int mmrkFinished = mmrklist.Where(m => m.State == ExecutionStatus.Finished).Count();
                myProcessStatus.JobStatus.Details = $"Generating MMRK files {mmrkFinished} of {mmrkTotal}, last update {DateTime.Now.ToString()}";
                await myActions.UpdateUnifiedProcessStatus(myProcessStatus);

                break;

            case ExecutionStatus.Finished:
                //Check EmbebedCodeList, Count running renders plus Finished render without AssetID (not created asset yet)
                int nRunning = myProcessStatus.EmbebedCodesList.Where(emc => (emc.State == ExecutionStatus.Running) || ((emc.AssetID == "") && (emc.State == ExecutionStatus.Finished))).Count();
                //Check Errros
                int nErrors = myProcessStatus.EmbebedCodesList.Where(emc => emc.State == ExecutionStatus.Error).Count();
                //Total
                int total = myProcessStatus.EmbebedCodesList.Count();

                log.Info($"Current EMC Running {nRunning}");
                if (nRunning == 0)
                {
                    myProcessStatus.JobStatus.State      = ExecutionStatus.Finished;
                    myProcessStatus.JobStatus.FinishTime = DateTime.Now;
                    myProcessStatus.JobStatus.Duration   = DateTime.Now.Subtract(myProcessStatus.JobStatus.StartTime);
                    myProcessStatus.JobStatus.Details    = $"Process Finished. Total Watermarked copies {total}, Success {total-nErrors} & Errors {nErrors}";
                }
                else
                {
                    myProcessStatus.JobStatus.State   = ExecutionStatus.Running;
                    myProcessStatus.JobStatus.Details = $"Process Running. Total Watermark copies {total}, Success {total - nRunning - nErrors} & Errors {nErrors}";
                    watingCopies = myProcessStatus.EmbebedCodesList.Where(emc => ((emc.AssetID == "") && (emc.State == ExecutionStatus.Finished))).Count();
                }
                await myActions.UpdateUnifiedProcessStatus(myProcessStatus);

                log.Info($"Updated Manifest JOB Status {myProcessStatus.JobStatus.State.ToString()}");
                break;
            }
            //Control Signal to LogicApp, to accelearete
            var myResponse = req.CreateResponse(HttpStatusCode.OK, myProcessStatus, JsonMediaTypeFormatter.DefaultMediaType);

            myResponse.Headers.Add("watingCopies", watingCopies.ToString());

            watch.Stop();
            log.Info($"[Time] Method EvalJobProgress {watch.ElapsedMilliseconds} [ms]");
            return(myResponse);
        }
        public static async Task <HttpResponseMessage> CreateWaterMArkedAssets([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            IActionsProvider myActions = ActionProviderFactory.GetActionProvider(SingleWaterMarkStorageAccInstanceController);

            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus manifest = BodyData.ToObject <UnifiedProcessStatus>();
            string ParentAssetID          = manifest.AssetStatus.AssetId;

            try
            {
                IAMSProvider help = AMSProviderFactory.CreateAMSProvider(_WaterMarkStorage);
                //Max number of Asset to create per iteration, to avoid Function Time out.
                int maxAssetCreate = int.Parse(System.Configuration.ConfigurationManager.AppSettings["maxAssetCreate"] ?? "10");
                int accAssetCreate = 0;
                //List only Finished without AsstID
                foreach (var watermarkedInfo in manifest.EmbebedCodesList)
                {
                    bool swError = false;
                    if ((watermarkedInfo.State == ExecutionStatus.Finished) && (string.IsNullOrEmpty(watermarkedInfo.AssetID) && (accAssetCreate <= maxAssetCreate)))
                    {
                        var watchAsset = System.Diagnostics.Stopwatch.StartNew();
                        ////Inject all Renders on New asset
                        var AssetWatermarkedRenders = myActions.GetWaterMarkedRenders(ParentAssetID, watermarkedInfo.EmbebedCodeValue);
                        if (AssetWatermarkedRenders.Count() > 0)
                        {
                            //Create new asset per embbeded code
                            var watchCreateAsset = System.Diagnostics.Stopwatch.StartNew();
                            var xx = await help.CreateEmptyWatermarkedAsset(manifest.JobStatus.JobID, ParentAssetID, watermarkedInfo.EmbebedCodeValue);

                            watermarkedInfo.AssetID = xx.WMAssetId;
                            watchCreateAsset.Stop();
                            log.Info($"[{manifest.JobStatus.JobID}] Created Asset {watermarkedInfo.AssetID} on {watchCreateAsset.ElapsedMilliseconds} [ms]");
                            //Renders exist, so Process
                            //Creat all togheter
                            var all = await help.AddWatermarkedRendersFiletoAsset(watermarkedInfo.AssetID, AssetWatermarkedRenders, watermarkedInfo.EmbebedCodeValue);

                            var onlyError = all.Where(r => r.Status != "MMRK File Added");
                            if (onlyError.Count() > 0)
                            {
                                //Error
                                watermarkedInfo.State = ExecutionStatus.Error;
                                foreach (var renderResult in onlyError)
                                {
                                    watermarkedInfo.Details += $"Error adding {renderResult.Status} deatils: {renderResult.StatusMessage}";
                                }
                                //Delete Asset
                                help.DeleteAsset(watermarkedInfo.AssetID);
                                watermarkedInfo.AssetID = "";
                                log.Error($"[{manifest.JobStatus.JobID}] Asset deleted  {watermarkedInfo.Details}");
                                swError = true;
                            }
                            //If not Error Create Manifest
                            if (!swError)
                            {
                                //Create New Manifest and set it as primary file.
                                var manifestResult = await help.GenerateManifest(watermarkedInfo.AssetID);

                                if (manifestResult.Status != "OK")
                                {
                                    //Error Creating Manifest
                                    help.DeleteAsset(watermarkedInfo.AssetID);
                                    watermarkedInfo.State   = ExecutionStatus.Error;
                                    watermarkedInfo.Details = $"Error  Creating MAnifest deatils: {manifestResult.StatusMessage}";
                                    log.Error($"[{manifest.JobStatus.JobID}] Error at GenerateManifest  {watermarkedInfo.Details}");
                                }
                                else
                                {
                                    //Delete Watermarked MP4 renders
                                    await myActions.DeleteWatermarkedRenderTmpInfo(AssetWatermarkedRenders);

                                    //One Asset created
                                    accAssetCreate += 1;
                                }
                            }
                        }
                        else
                        {
                            //Watermarked Copy error, It has not renders.
                            watermarkedInfo.State   = ExecutionStatus.Error;
                            watermarkedInfo.Details = $"Error adding {watermarkedInfo.EmbebedCodeValue} renders deatils: Has not renders MP4";
                            watermarkedInfo.AssetID = "";
                            log.Error($"[{manifest.JobStatus.JobID}] Error processing Wateramark copy {watermarkedInfo.EmbebedCodeValue} error: {watermarkedInfo.Details}");
                        }
                        //Update WatermarkedCopy
                        myActions.UpdateWaterMarkedAssetInfo(watermarkedInfo, manifest.AssetStatus.AssetId);
                        //TimeTrack
                        watchAsset.Stop();
                        log.Info($"[Time][{manifest.JobStatus.JobID}] Asset Creation {watchAsset.ElapsedMilliseconds} [ms] code {watermarkedInfo.EmbebedCodeValue} assetID: {watermarkedInfo.AssetID}");
                    }
                    if (watch.ElapsedMilliseconds >= 100000)
                    {
                        log.Warning($"[{manifest.JobStatus.JobID}] Asset Creation time limite achieved, break loop with {accAssetCreate-1} copies");
                        break;
                    }
                }
            }
            catch (Exception X)
            {
                log.Error($"{X.Message}");
                return(req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType));
            }
            watch.Stop();
            log.Info($"[Time] Method CreateWaterMArkedAssets {watch.ElapsedMilliseconds} [ms]");
            return(req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }
Exemplo n.º 12
0
        public static async Task <HttpResponseMessage> CreateWaterMArkedAssets([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            IActionsProvider myActions = ActionProviderFactory.GetActionProvider();

            dynamic BodyData = await req.Content.ReadAsAsync <object>();

            UnifiedProcessStatus manifest = BodyData.ToObject <UnifiedProcessStatus>();
            string ParentAssetID          = manifest.AssetStatus.AssetId;

            try
            {
                IAMSProvider help = AMSProviderFactory.CreateAMSProvider();
                //Max number of Asset to create per iteration, to avoid Function Time out.
                int  maxAssetCreate = int.Parse(System.Configuration.ConfigurationManager.AppSettings["maxAssetCreate"] ?? "10");
                int  accAssetCreate = 0;
                bool swError        = false;
                //List only Finished without AsstID
                foreach (var watermarkedInfo in manifest.EmbebedCodesList)
                {
                    if ((watermarkedInfo.State == ExecutionStatus.Finished) && (string.IsNullOrEmpty(watermarkedInfo.AssetID) && (accAssetCreate <= maxAssetCreate)))
                    {
                        var watchAsset = System.Diagnostics.Stopwatch.StartNew();
                        //Create new asset per embbeded code
                        var xx = await help.CreateEmptyWatermarkedAsset(manifest.JobStatus.JobID, ParentAssetID, watermarkedInfo.EmbebedCodeValue);

                        watermarkedInfo.AssetID = xx.WMAssetId;
                        //log.Info($"[{manifest.JobStatus.JobID}] Watermarket created form {manifest.JobStatus.JobID} {watermarkedInfo.EmbebedCodeValue} with assett id {watermarkedInfo.AssetID}");
                        ////Inject all Renders on New asset
                        foreach (var render in myActions.GetWaterMarkedRenders(ParentAssetID, watermarkedInfo.EmbebedCodeValue))
                        {
                            string url = render.MP4URL;
                            var    r   = await help.AddWatermarkedMediaFiletoAsset(watermarkedInfo.AssetID, watermarkedInfo.EmbebedCodeValue, url);

                            if (r.Status != "MMRK File Added")
                            {
                                //Error
                                watermarkedInfo.State   = ExecutionStatus.Error;
                                watermarkedInfo.Details = $"Error adding {render.RenderName} deatils: {r.StatusMessage}";
                                //Delete Asset
                                help.DeleteAsset(watermarkedInfo.AssetID);
                                watermarkedInfo.AssetID = "";
                                log.Info($"[{manifest.JobStatus.JobID}] Asset deleted  {r.Status}");
                                //Abort
                                swError = true;
                                break;
                            }
                        }
                        //If not Error Create Manifest
                        if (!swError)
                        {
                            //Create New Manifest and set it as primary file.
                            await help.GenerateManifest(watermarkedInfo.AssetID);

                            //One Asset created
                            accAssetCreate += 1;
                        }

                        watchAsset.Stop();
                        log.Info($"[Time][{manifest.JobStatus.JobID}] Asset Creation {watchAsset.ElapsedMilliseconds} [ms] code {watermarkedInfo.EmbebedCodeValue} assetID: {watermarkedInfo.AssetID}");
                    }
                    if (watch.ElapsedMilliseconds >= 100000)
                    {
                        log.Warning($"[{manifest.JobStatus.JobID}] Asset Creation time limite achieved, break loop with {accAssetCreate-1} copies");
                        break;
                    }
                }
                myActions.UpdateUnifiedProcessStatus(manifest);
            }
            catch (Exception X)
            {
                log.Error($"{X.Message}");
                return(req.CreateResponse(HttpStatusCode.InternalServerError, X, JsonMediaTypeFormatter.DefaultMediaType));
            }
            watch.Stop();
            log.Info($"[Time] Method CreateWaterMArkedAssets {watch.ElapsedMilliseconds} [ms]");
            return(req.CreateResponse(HttpStatusCode.OK, manifest, JsonMediaTypeFormatter.DefaultMediaType));
        }