Exemplo n.º 1
0
 static void EnsureParameterValuesExist(TemplateSettings settings, ITextTemplatingEngineHost host, ParsedTemplate pt)
 {
     foreach (var directive in settings.CustomDirectives)
     {
         if (directive.ProcessorName == nameof(ParameterDirectiveProcessor))
         {
             if (directive.Directive.Attributes.TryGetValue("name", out string parameterName))
             {
                 if (!string.IsNullOrEmpty(host.ResolveParameterValue(directive.Directive.Name, directive.ProcessorName, parameterName)))
                 {
                     continue;
                 }
             }
             pt.LogError(string.Format(CultureInfo.CurrentCulture, VsTemplatingErrorResources.CouldNotVerifyParameterValue, parameterName));
         }
     }
 }
        public override void ProcessDirective(string directiveName, IDictionary <string, string> arguments)
        {
            if (directiveName == null)
            {
                throw new ArgumentNullException("directiveName");
            }
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            var providesDictionary = new Dictionary <string, string>();
            var requiresDictionary = new Dictionary <string, string>();

            string provides;

            if (arguments.TryGetValue("provides", out provides))
            {
                foreach (var arg in ParseArgs(provides))
                {
                    providesDictionary.Add(arg.Key, arg.Value);
                }
            }

            string requires;

            if (arguments.TryGetValue("requires", out requires))
            {
                foreach (var arg in ParseArgs(requires))
                {
                    requiresDictionary.Add(arg.Key, arg.Value);
                }
            }

            InitializeRequiresDictionary(directiveName, requiresDictionary);
            InitializeProvidesDictionary(directiveName, providesDictionary);

            var id = ProvideUniqueId(directiveName, arguments, requiresDictionary, providesDictionary);

            foreach (var req in requiresDictionary)
            {
                var val = host.ResolveParameterValue(id, FriendlyName, req.Key);
                if (val != null)
                {
                    requiresDictionary[req.Key] = val;
                }
                else if (req.Value == null)
                {
                    throw new DirectiveProcessorException("Could not resolve required value '" + req.Key + "'");
                }
            }

            foreach (var req in providesDictionary)
            {
                var val = host.ResolveParameterValue(id, FriendlyName, req.Key);
                if (val != null)
                {
                    providesDictionary[req.Key] = val;
                }
            }

            PostProcessArguments(directiveName, requiresDictionary, providesDictionary);

            GeneratePreInitializationCode(directiveName, preInitBuffer, languageProvider, requiresDictionary, providesDictionary);
            GeneratePostInitializationCode(directiveName, postInitBuffer, languageProvider, requiresDictionary, providesDictionary);
            GenerateTransformCode(directiveName, codeBuffer, languageProvider, requiresDictionary, providesDictionary);
        }