예제 #1
0
        public void DeleteEntity(MediaEntity entityType, string entityName, string parentName = null)
        {
            switch (entityType)
            {
            case MediaEntity.Asset:
                _media.Assets.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                break;

            case MediaEntity.Transform:
                _media.Transforms.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                break;

            case MediaEntity.TransformJob:
                _media.Jobs.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, parentName, entityName);
                using (DatabaseClient databaseClient = new DatabaseClient())
                {
                    string collectionId = Constant.Database.Collection.MediaJobAccount;
                    databaseClient.DeleteDocument(collectionId, entityName);
                }
                break;

            case MediaEntity.ContentKeyPolicy:
                _media.ContentKeyPolicies.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                break;

            case MediaEntity.StreamingPolicy:
                _media.StreamingPolicies.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                break;

            case MediaEntity.StreamingEndpoint:
                _media.StreamingEndpoints.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                break;

            case MediaEntity.StreamingLocator:
                _media.StreamingLocators.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                break;

            case MediaEntity.FilterAccount:
                _media.AccountFilters.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                break;

            case MediaEntity.FilterAsset:
                _media.AssetFilters.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, parentName, entityName);
                break;

            case MediaEntity.LiveEvent:
                LiveEvent liveEvent = GetEntity <LiveEvent>(MediaEntity.LiveEvent, entityName);
                if (liveEvent != null)
                {
                    LiveOutput[] liveOutputs = GetAllEntities <LiveOutput>(MediaEntity.LiveEventOutput, null, entityName);
                    foreach (LiveOutput liveOutput in liveOutputs)
                    {
                        _media.LiveOutputs.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName, liveOutput.Name);
                    }
                    _media.LiveEvents.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, entityName);
                }
                break;

            case MediaEntity.LiveEventOutput:
                _media.LiveOutputs.Delete(MediaAccount.ResourceGroupName, MediaAccount.Name, parentName, entityName);
                break;
            }
        }
예제 #2
0
        private static MediaJobTask[] GetEncoderTasks(MediaClient mediaClient, MediaJobTask jobTask, MediaAssetInput[] inputAssets)
        {
            List <MediaJobTask> jobTasks = new List <MediaJobTask>();

            if (jobTask.MediaProcessor != MediaProcessor.EncoderStandard)
            {
                List <MediaAssetInput> assets = new List <MediaAssetInput>(inputAssets);
                assets.Sort(OrderByWorkflow);
                inputAssets = assets.ToArray();
            }
            else
            {
                if (string.Equals(jobTask.ProcessorConfig, Constants.Media.ProcessorConfig.EncoderStandardThumbnailsPreset, StringComparison.InvariantCultureIgnoreCase))
                {
                    string settingKey = Constants.AppSettingKey.MediaProcessorThumbnailGenerationDocumentId;
                    string documentId = AppSetting.GetValue(settingKey);
                    using (DatabaseClient databaseClient = new DatabaseClient(false))
                    {
                        JObject processorConfig = databaseClient.GetDocument(documentId);
                        jobTask.ProcessorConfig = processorConfig.ToString();
                    }
                }
                bool inputSubclipped = false;
                foreach (MediaAssetInput inputAsset in inputAssets)
                {
                    if (!string.IsNullOrEmpty(inputAsset.MarkIn))
                    {
                        inputSubclipped = true;
                    }
                }
                if (inputSubclipped && !jobTask.ProcessorConfig.StartsWith("{"))
                {
                    using (DatabaseClient databaseClient = new DatabaseClient(true))
                    {
                        string  collectionId  = Constants.Database.DocumentCollection.Encoding;
                        string  procedureId   = "getEncoderConfig";
                        JObject encoderConfig = databaseClient.ExecuteProcedure(collectionId, procedureId, "name", jobTask.ProcessorConfig);
                        jobTask.ProcessorConfig = encoderConfig.ToString();
                    }
                }
            }
            JArray inputSources = new JArray();

            foreach (MediaAssetInput inputAsset in inputAssets)
            {
                if (!string.IsNullOrEmpty(inputAsset.MarkIn))
                {
                    JObject inputSource = new JObject();
                    inputSource.Add("StartTime", inputAsset.MarkIn);
                    inputSource.Add("Duration", inputAsset.ClipDuration);
                    inputSources.Add(inputSource);
                }
            }
            if (inputSources.Count > 0)
            {
                JObject oldConfig = JObject.Parse(jobTask.ProcessorConfig);
                oldConfig.Remove("Sources");
                JObject newConfig = new JObject();
                newConfig.Add(oldConfig.First);
                newConfig.Add("Sources", inputSources);
                oldConfig.First.Remove();
                JEnumerable <JToken> children = oldConfig.Children();
                foreach (JToken child in children)
                {
                    newConfig.Add(child);
                }
                jobTask.ProcessorConfig = newConfig.ToString();
            }
            bool multipleInputTask = jobTask.MediaProcessor != MediaProcessor.EncoderStandard;

            MediaJobTask[] mappedJobTasks = MapJobTasks(mediaClient, jobTask, inputAssets, multipleInputTask);
            jobTasks.AddRange(mappedJobTasks);
            return(jobTasks.ToArray());
        }