Inheritance: ITaskTemplate
        private void ProtectTaskConfiguration(TaskTemplateData taskTemplate, ref X509Certificate2 certToUse, IMediaDataServiceContext dataContext)
        {
            using (ConfigurationEncryption configEncryption = new ConfigurationEncryption())
            {
                // Update the task template with the required data.
                taskTemplate.Configuration        = configEncryption.Encrypt(taskTemplate.Configuration);
                taskTemplate.EncryptionKeyId      = configEncryption.GetKeyIdentifierAsString();
                taskTemplate.EncryptionScheme     = ConfigurationEncryption.SchemeName;
                taskTemplate.EncryptionVersion    = ConfigurationEncryption.SchemeVersion;
                taskTemplate.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 void ResolveTaskTemplateInputsAndOuputs()
        {
            AssetPlaceholderToInstanceResolver assetPlaceholderToInstanceResolver = new AssetPlaceholderToInstanceResolver();

            using (StringReader stringReader = new StringReader(this.JobTemplateBody))
            {
                XElement root = XElement.Load(stringReader);

                foreach (XElement taskBody in root.Elements("taskBody"))
                {
                    List <IAsset> taskTemplateInputs  = new List <IAsset>();
                    List <IAsset> taskTemplateOutputs = new List <IAsset>();

                    string taskTemplateId = (string)taskBody.Attribute("taskTemplateId");

                    TaskTemplateData taskTemplate = this.TaskTemplates.Where(t => t.Id == taskTemplateId).Single();

                    foreach (XElement input in taskBody.Elements("inputAsset"))
                    {
                        string inputName  = (string)input.Value;
                        IAsset inputAsset = assetPlaceholderToInstanceResolver.CreateOrGetInputAsset(inputName);
                        if (inputAsset != null)
                        {
                            taskTemplateInputs.Add(inputAsset);
                        }
                    }

                    foreach (XElement output in taskBody.Elements("outputAsset"))
                    {
                        string outputName = (string)output.Value;
                        taskTemplateOutputs.Add(assetPlaceholderToInstanceResolver.CreateOrGetOutputAsset(outputName));
                    }

                    taskTemplate.TaskInputs  = taskTemplateInputs.ToArray();
                    taskTemplate.TaskOutputs = taskTemplateOutputs.ToArray();
                }
            }
        }
Beispiel #3
0
        private ITaskTemplate CreateTaskTemplate(ITask task)
        {
            TaskTemplateData taskTemplate = new TaskTemplateData
            {
                Name                 = task.Name,
                MediaProcessorId     = task.MediaProcessorId,
                Configuration        = task.Configuration,
                EncryptionKeyId      = task.EncryptionKeyId,
                EncryptionScheme     = task.EncryptionScheme,
                EncryptionVersion    = task.EncryptionVersion,
                InitializationVector = task.InitializationVector,
                TaskInputs           = task.InputAssets.ToArray(),
                TaskOutputs          = task.OutputAssets.ToArray(),
                NumberofInputAssets  = task.InputAssets.Count,
                NumberofOutputAssets = task.OutputAssets.Count,
                Options              = (int)task.Options,
                TaskTemplateBody     = task.TaskBody
            };

            taskTemplate.SetMediaContext(this.GetMediaContext());

            return(taskTemplate);
        }
        /// <summary>
        /// Copies this instance.
        /// </summary>
        /// <returns>The task template copy.</returns>
        internal TaskTemplateData Copy()
        {
            TaskTemplateData templateData = new TaskTemplateData
            {
                Name                 = this.Name,
                MediaProcessorId     = this.MediaProcessorId,
                Configuration        = this.Configuration,
                ConfigurationCopied  = this.Configuration,
                EncryptionKeyId      = this.EncryptionKeyId,
                EncryptionScheme     = this.EncryptionScheme,
                EncryptionVersion    = this.EncryptionVersion,
                InitializationVector = this.InitializationVector,
                TaskInputs           = this.TaskInputs,
                TaskOutputs          = this.TaskOutputs,
                NumberofInputAssets  = this.NumberofInputAssets,
                NumberofOutputAssets = this.NumberofOutputAssets,
                Options              = (int)this.Options,
                TaskTemplateBody     = this.TaskTemplateBody
            };

            templateData.InitCloudMediaContext(this._cloudMediaContext);

            return(templateData);
        }
        /// <summary>
        /// Copies this instance.
        /// </summary>
        /// <returns>The task template copy.</returns>
        internal TaskTemplateData Copy()
        {
            TaskTemplateData templateData = new TaskTemplateData
            {
                Name = this.Name,
                MediaProcessorId = this.MediaProcessorId,
                Configuration = this.Configuration,
                ConfigurationCopied = this.Configuration,
                EncryptionKeyId = this.EncryptionKeyId,
                EncryptionScheme = this.EncryptionScheme,
                EncryptionVersion = this.EncryptionVersion,
                InitializationVector = this.InitializationVector,
                TaskInputs = this.TaskInputs,
                TaskOutputs = this.TaskOutputs,
                NumberofInputAssets = this.NumberofInputAssets,
                NumberofOutputAssets = this.NumberofOutputAssets,
                Options = (int)this.Options,
                TaskTemplateBody = this.TaskTemplateBody
            };

            templateData.InitCloudMediaContext(this._cloudMediaContext);

            return templateData;
        }
        private ITaskTemplate CreateTaskTemplate(ITask task)
        {
            TaskTemplateData taskTemplate = new TaskTemplateData
                {
                    Name = task.Name,
                    MediaProcessorId = task.MediaProcessorId,
                    Configuration = task.Configuration,
                    EncryptionKeyId = task.EncryptionKeyId,
                    EncryptionScheme = task.EncryptionScheme,
                    EncryptionVersion = task.EncryptionVersion,
                    InitializationVector = task.InitializationVector,
                    TaskInputs = task.InputAssets.ToArray(),
                    TaskOutputs = task.OutputAssets.ToArray(),
                    NumberofInputAssets = task.InputAssets.Count,
                    NumberofOutputAssets = task.OutputAssets.Count,
                    Options = (int)task.Options,
                    TaskTemplateBody = task.TaskBody
                };

            taskTemplate.InitCloudMediaContext(this._cloudMediaContext);

            return taskTemplate;
        }
        private static void ProtectTaskConfiguration(TaskTemplateData taskTemplate, ref X509Certificate2 certToUse, DataServiceContext dataContext)
        {
            using (ConfigurationEncryption configEncryption = new ConfigurationEncryption())
            {
                // Update the task template with the required data.
                taskTemplate.Configuration = configEncryption.Encrypt(taskTemplate.Configuration);
                taskTemplate.EncryptionKeyId = configEncryption.GetKeyIdentifierAsString();
                taskTemplate.EncryptionScheme = ConfigurationEncryption.SchemeName;
                taskTemplate.EncryptionVersion = ConfigurationEncryption.SchemeVersion;
                taskTemplate.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);
            }
        }
Beispiel #8
0
        private static string CreateJobTemplateBody(AssetNamingSchemeResolver <AssetData, OutputAsset> assetMap, ITaskTemplate[] taskTemplates)
        {
            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                XmlWriterSettings outputSettings =
                    new XmlWriterSettings
                {
                    Encoding = Encoding.UTF8,
                    Indent   = true
                };

                XmlWriter jobTemplateBodyWriter = XmlWriter.Create(stringWriter, outputSettings);
                jobTemplateBodyWriter.WriteStartDocument();

                jobTemplateBodyWriter.WriteStartElement("jobTemplate");

                foreach (ITaskTemplate taskTemplate in taskTemplates)
                {
                    TaskTemplateData taskTemplateData = (TaskTemplateData)taskTemplate;
                    taskTemplateData.NumberofInputAssets  = taskTemplateData.TaskInputs.Length;
                    taskTemplateData.NumberofOutputAssets = taskTemplateData.TaskOutputs.Length;

                    string taskTemplateId   = string.Empty;
                    string taskTemplateBody = string.Empty;

                    if (!string.IsNullOrWhiteSpace(taskTemplateData.TaskTemplateBody))
                    {
                        // The task template was created using an already submitted job.
                        StringReader stringReader = null;
                        try
                        {
                            stringReader = new StringReader(taskTemplateData.TaskTemplateBody);
                            using (XmlReader taskTemplateBodyReader = XmlReader.Create(stringReader))
                            {
                                stringReader = null;
                                taskTemplateBodyReader.ReadToNextSibling(TaskBodyNodeName);

                                taskTemplateId   = taskTemplateBodyReader.GetAttribute(TaskTemplateIdAttributeName);
                                taskTemplateBody = taskTemplateBodyReader.ReadInnerXml();
                            }
                        }
                        finally
                        {
                            if (stringReader != null)
                            {
                                stringReader.Dispose();
                            }
                        }
                    }

                    taskTemplateData.Id = !string.IsNullOrWhiteSpace(taskTemplateId)
                        ? taskTemplateId
                        : string.Concat("nb:ttid:UUID:", Guid.NewGuid());

                    jobTemplateBodyWriter.WriteStartElement(TaskBodyNodeName);
                    jobTemplateBodyWriter.WriteAttributeString(TaskTemplateIdAttributeName, taskTemplateData.Id);

                    if (!string.IsNullOrWhiteSpace(taskTemplateBody))
                    {
                        // The task template was created using an already submitted job.
                        jobTemplateBodyWriter.WriteRaw(taskTemplateBody);
                    }
                    else
                    {
                        foreach (IAsset input in taskTemplateData.TaskInputs)
                        {
                            jobTemplateBodyWriter.WriteStartElement(InputAssetNodeName);
                            jobTemplateBodyWriter.WriteString(assetMap.GetAssetId(input));
                            jobTemplateBodyWriter.WriteEndElement();
                        }

                        foreach (IAsset output in taskTemplateData.TaskOutputs)
                        {
                            jobTemplateBodyWriter.WriteStartElement(OutputAssetNodeName);

                            int options = (int)output.Options;
                            jobTemplateBodyWriter.WriteAttributeString(AssetCreationOptionsAttributeName, options.ToString(CultureInfo.InvariantCulture));

                            if (!String.IsNullOrEmpty(output.StorageAccountName))
                            {
                                jobTemplateBodyWriter.WriteAttributeString(StorageAttributeName, output.StorageAccountName);
                            }

                            jobTemplateBodyWriter.WriteString(assetMap.GetAssetId(output));
                            jobTemplateBodyWriter.WriteEndElement();
                        }
                    }

                    jobTemplateBodyWriter.WriteEndElement();
                }

                jobTemplateBodyWriter.WriteEndDocument();
                jobTemplateBodyWriter.Flush();

                return(stringWriter.ToString());
            }
        }