示例#1
0
文件: ArmIO.cs 项目: lulzzz/ExpandARM
        private void ExpandArmTemplateImpl(ArmTemplate armTemplate, HashSet <string> uniqueArmTemplateFullPaths)
        {
            armTemplate
            .ExpandedContent
            .SelectTokens("$..templateLink")
            .ToList()
            .ForEach(t =>
            {
                var templateFilePath    = ((string)((dynamic)t).uri).Replace("file://", "").Replace("/", "\\");
                string templateFullPath = GetFullPath(fileSystem.Path.GetDirectoryName(armTemplate.FilePath), templateFilePath);

                if (string.Equals(armTemplate.FilePath, templateFullPath, StringComparison.InvariantCultureIgnoreCase))
                {
                    throw new SelfReferenceException("This template contains a link to self which will cause a neverending expansion loop.");
                }

                if (uniqueArmTemplateFullPaths.Contains(templateFullPath))
                {
                    throw new ReferenceLoopException($"This template contains a link to one of its parents. File: {templateFullPath}");
                }

                uniqueArmTemplateFullPaths.Add(templateFullPath);

                var nestedTemplate = LoadArmTemplate(templateFullPath);

                ExpandArmTemplateImpl(nestedTemplate, uniqueArmTemplateFullPaths);

                t.Parent.Parent["template"] = nestedTemplate.ExpandedContent;

                ((JObject)t.Parent.Parent).Property("templateLink").Remove();
            });
        }
示例#2
0
文件: ArmIO.cs 项目: lulzzz/ExpandARM
        public string SaveExpandedTemplate(ArmTemplate armTemplate, string outputFilePath)
        {
            var acctualOutputFilePath =
                string.IsNullOrWhiteSpace(outputFilePath) ?
                fileSystem.Path.ChangeExtension(armTemplate.FilePath, "expanded.json") :
                outputFilePath;

            fileSystem.File.WriteAllText(acctualOutputFilePath, armTemplate.ExpandedContent.ToString());

            return(acctualOutputFilePath);
        }
示例#3
0
文件: ArmIO.cs 项目: lulzzz/ExpandARM
 public string SaveExpandedTemplate(ArmTemplate armTemplate)
 {
     return(SaveExpandedTemplate(armTemplate, null));
 }
示例#4
0
文件: ArmIO.cs 项目: lulzzz/ExpandARM
        public void ExpandArmTemplate(ArmTemplate armTemplate)
        {
            HashSet <string> uniqueArmTemplateFullPaths = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            ExpandArmTemplateImpl(armTemplate, uniqueArmTemplateFullPaths);
        }