Inheritance: ITask, ICloudMediaContextInit
Esempio n. 1
0
        /// <summary>
        /// Adds a new task.
        /// </summary>
        /// <param name="taskName">The task name.</param>
        /// <param name="mediaProcessor">The media processor id.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="options">The options.</param>
        /// <returns>The new task.</returns>
        public ITask AddNew(string taskName, IMediaProcessor mediaProcessor, string configuration, TaskOptions options)
        {
            if (taskName == null)
            {
                throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, StringTable.ErrorArgCannotBeNullOrEmpty, "taskName"));
            }

            if (taskName.Length == 0)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, StringTable.ErrorArgCannotBeNullOrEmpty, "taskName"));
            }

            if (mediaProcessor == null)
            {
                throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, StringTable.ErrorArgCannotBeNull, "mediaProcessor"));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, StringTable.ErrorArgCannotBeNull, "configuration"));
            }

            this.CheckIfJobIsPersistedAndThrowNotSupported();

            var task = new TaskData
                           {
                               Name = taskName,
                               Configuration = configuration,
                               MediaProcessorId = mediaProcessor.Id,
                               Options = (int)options,
                               ParentJob = _job
                           };

            task.SetMediaContext(MediaContext);

            this._tasks.Add(task);

            return task;
        }
Esempio n. 2
0
        private void ProtectTaskConfiguration(TaskData task, ref X509Certificate2 certToUse, IMediaDataServiceContext dataContext)
        {
            using (ConfigurationEncryption configEncryption = new ConfigurationEncryption())
            {
                // Update the task with the required data.
                task.Configuration        = configEncryption.Encrypt(task.Configuration);
                task.EncryptionKeyId      = configEncryption.GetKeyIdentifierAsString();
                task.EncryptionScheme     = ConfigurationEncryption.SchemeName;
                task.EncryptionVersion    = ConfigurationEncryption.SchemeVersion;
                task.InitializationVector = configEncryption.GetInitializationVectorAsString();

                if (certToUse == null)
                {
                    // Get the certificate to use to encrypt the configuration encryption key.
                    certToUse = ContentKeyBaseCollection.GetCertificateToEncryptContentKey(GetMediaContext(), ContentKeyType.ConfigurationEncryption);
                }

                // Create a content key object to hold the encryption key.
                ContentKeyData contentKeyData = ContentKeyBaseCollection.InitializeConfigurationContentKey(configEncryption, certToUse);
                dataContext.AddObject(ContentKeyBaseCollection.ContentKeySet, contentKeyData);
            }
        }
        private static void ProtectTaskConfiguration(TaskData task, ref X509Certificate2 certToUse, DataServiceContext dataContext)
        {
            using (ConfigurationEncryption configEncryption = new ConfigurationEncryption())
            {
                // Update the task with the required data.
                task.Configuration = configEncryption.Encrypt(task.Configuration);
                task.EncryptionKeyId = configEncryption.GetKeyIdentifierAsString();
                task.EncryptionScheme = ConfigurationEncryption.SchemeName;
                task.EncryptionVersion = ConfigurationEncryption.SchemeVersion;
                task.InitializationVector = configEncryption.GetInitializationVectorAsString();

                if (certToUse == null)
                {
                    // Get the certificate to use to encrypt the configuration encryption key.
                    certToUse = ContentKeyBaseCollection.GetCertificateToEncryptContentKey(dataContext, ContentKeyType.ConfigurationEncryption);
                }

                // Create a content key object to hold the encryption key.
                ContentKeyData contentKeyData = ContentKeyBaseCollection.CreateConfigurationContentKey(configEncryption, certToUse);
                dataContext.AddObject(ContentKeyCollection.ContentKeySet, contentKeyData);
            }
        }
Esempio n. 4
0
        private void InnerSubmit(IMediaDataServiceContext dataContext)
        {
            if (!string.IsNullOrWhiteSpace(this.TemplateId))
            {
                dataContext.AddObject(JobBaseCollection.JobSet, this);

                foreach (IAsset asset in this.InputMediaAssets)
                {
                    AssetData target = asset as AssetData;
                    if (target == null)
                    {
                        throw new ArgumentException(StringTable.ErrorInputTypeNotSupported);
                    }

                    dataContext.AttachTo(AssetCollection.AssetSet, asset);
                    dataContext.AddLink(this, InputMediaAssetsPropertyName, target);
                }
            }
            else
            {
                X509Certificate2 certToUse = null;
                Verify(this);

                dataContext.AddObject(JobBaseCollection.JobSet, this);

                List <AssetData> inputAssets = new List <AssetData>();
                AssetNamingSchemeResolver <AssetData, OutputAsset> assetNamingSchemeResolver = new AssetNamingSchemeResolver <AssetData, OutputAsset>(inputAssets);

                foreach (ITask task in ((IJob)this).Tasks)
                {
                    Verify(task);
                    TaskData taskData = (TaskData)task;

                    if (task.Options.HasFlag(TaskOptions.ProtectedConfiguration))
                    {
                        ProtectTaskConfiguration(taskData, ref certToUse, dataContext);
                    }

                    taskData.TaskBody = CreateTaskBody(assetNamingSchemeResolver, task.InputAssets.ToArray(), task.OutputAssets.ToArray());
                    taskData.InputMediaAssets.AddRange(task.InputAssets.OfType <AssetData>().ToArray());
                    taskData.OutputMediaAssets.AddRange(
                        task.OutputAssets
                        .OfType <OutputAsset>()
                        .Select(
                            c =>
                    {
                        AssetData assetData = new AssetData {
                            Name = c.Name, Options = (int)c.Options, AlternateId = c.AlternateId
                        };
                        assetData.SetMediaContext(this.GetMediaContext());

                        return(assetData);
                    })
                        .ToArray());
                    dataContext.AddRelatedObject(this, TasksPropertyName, taskData);
                }

                foreach (IAsset asset in inputAssets)
                {
                    dataContext.AttachTo(AssetCollection.AssetSet, asset);
                    dataContext.AddLink(this, InputMediaAssetsPropertyName, asset);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OutputAssetCollection"/> class.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="assets">The assets.</param>
 /// <param name="cloudMediaContext">The <seealso cref="CloudMediaContext"/> instance.</param>
 internal OutputAssetCollection(TaskData task, IEnumerable <IAsset> assets, MediaContextBase cloudMediaContext)
 {
     this._assets            = new List <IAsset>(assets);
     this._task              = task;
     this._cloudMediaContext = cloudMediaContext;
 }