Exemplo n.º 1
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> 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.º 3
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));
        }