Пример #1
0
        private static string CreateTaskBody(AssetNamingSchemeResolver <AssetData, OutputAsset> assetNamingSchemeResolver, IEnumerable <IAsset> inputs, IEnumerable <IAsset> outputs)
        {
            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                XmlWriterSettings outputSettings = new XmlWriterSettings();
                outputSettings.Encoding = Encoding.UTF8;
                outputSettings.Indent   = true;
                XmlWriter taskBody = XmlWriter.Create(stringWriter, outputSettings);
                taskBody.WriteStartDocument();
                taskBody.WriteStartElement(TaskBodyNodeName);

                foreach (IAsset input in inputs)
                {
                    taskBody.WriteStartElement(InputAssetNodeName);
                    taskBody.WriteString(assetNamingSchemeResolver.GetAssetId(input));
                    taskBody.WriteEndElement();
                }

                foreach (IAsset output in outputs)
                {
                    taskBody.WriteStartElement(OutputAssetNodeName);
                    var outputAsset = (OutputAsset)output;

                    if (!assetNamingSchemeResolver.IsExistingOutputAsset(outputAsset))
                    {
                        int options      = (int)outputAsset.Options;
                        int formatOption = (int)outputAsset.FormatOption;
                        taskBody.WriteAttributeString(AssetCreationOptionsAttributeName,
                                                      options.ToString(CultureInfo.InvariantCulture));
                        taskBody.WriteAttributeString(AssetFormatOptionAttributeName,
                                                      formatOption.ToString(CultureInfo.InvariantCulture));
                        if (!string.IsNullOrEmpty(outputAsset.Name)) // Ignore empty string for the name
                        {
                            taskBody.WriteAttributeString(OutputAssetNameAttributeName, outputAsset.Name);
                        }
                        if (!string.IsNullOrEmpty(outputAsset.StorageAccountName))
                        // Ignore empty string for the storage account
                        {
                            taskBody.WriteAttributeString(StorageAttributeName, outputAsset.StorageAccountName);
                        }
                    }
                    taskBody.WriteString(assetNamingSchemeResolver.GetAssetId(output));
                    taskBody.WriteEndElement();
                }

                taskBody.WriteEndDocument();
                taskBody.Flush();

                return(stringWriter.ToString());
            }
        }
Пример #2
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());
            }
        }