public override void ProcessDirective(string directiveName, IDictionary <string, string> arguments)
        {
            switch (directiveName)
            {
            case "template":
                string visibility;
                if (arguments.TryGetValue("visibility", out visibility))
                {
                    _result.Visibility = visibility;
                }
                break;

            case "output":
                string extension;
                if (arguments.TryGetValue("extension", out extension))
                {
                    _host.SetFileExtension(extension);
                }
                string encoding;
                if (arguments.TryGetValue("encoding", out encoding))
                {
                    int codepage;
                    _host.SetOutputEncoding(

                        /*int.TryParse(encoding, out codepage)
                         *  ? Encoding.GetEncoding(codepage)
                         *  : */Encoding.GetEncoding(encoding),
                        fromOutputDirective: true);
                }
                break;

            case "assembly":
                string name;
                if (arguments.TryGetValue("name", out name))
                {
                    _references.Add(name);
                }
                break;

            case "import":
                string @namespace;
                if (arguments.TryGetValue("namespace", out @namespace))
                {
                    _imports.Add(@namespace);
                }
                break;

            case "include":
                string file;
                if (arguments.TryGetValue("file", out file))
                {
                    string onceArgument;
                    arguments.TryGetValue("once", out onceArgument);
                    bool once;
                    bool.TryParse(onceArgument, out once);
                    _includeFiles.Add(new IncludeFile(file, once));
                }
                break;
            }
        }
        public string ProcessTemplate(string content, ITextTemplatingEngineHost host)
        {
            ParsedTemplate pt = ParsedTemplate.FromText(content, host);

            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            TemplateSettings settings = GetSettings(host, pt);

            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            CodeCompileUnit ccu = GenerateCompileUnit(host, pt, settings);

            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            System.Reflection.Assembly results = GenerateCode(host, pt, settings, ccu);
            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            if (!String.IsNullOrEmpty(settings.Extension))
            {
                host.SetFileExtension(settings.Extension);
            }
            if (settings.Encoding != null)
            {
                //FIXME: when is this called with false?
                host.SetOutputEncoding(settings.Encoding, true);
            }

            string output = "";

            try {
                output = Run(results, settings.Namespace + "." + settings.Name, host, settings.Culture);
            } catch (Exception ex) {
                pt.LogError("Error running transform: " + ex.ToString());
            }
            host.LogErrors(pt.Errors);
            return(output);
        }
        public CompiledTemplate CompileTemplate(string content, ITextTemplatingEngineHost host)
        {
            ParsedTemplate pt = ParsedTemplate.FromText(content, host);

            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            TemplateSettings settings = GetSettings(host, pt);

            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            CodeCompileUnit ccu = GenerateCompileUnit(host, pt, settings);

            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            System.Reflection.Assembly results = GenerateCode(host, pt, settings, ccu);
            if (pt.Errors.HasErrors)
            {
                host.LogErrors(pt.Errors);
                return(null);
            }

            if (!String.IsNullOrEmpty(settings.Extension))
            {
                host.SetFileExtension(settings.Extension);
            }
            if (settings.Encoding != null)
            {
                //FIXME: when is this called with false?
                host.SetOutputEncoding(settings.Encoding, true);
            }

            return(new CompiledTemplate(pt, host, results, settings));
        }
		public string ProcessTemplate (string content, ITextTemplatingEngineHost host)
		{
			ParsedTemplate pt = ParsedTemplate.FromText (content, host);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			TemplateSettings settings = GetSettings (host, pt);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			CodeCompileUnit ccu = GenerateCompileUnit (host, pt, settings);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			System.Reflection.Assembly results = GenerateCode (host, pt, settings, ccu);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			if (!String.IsNullOrEmpty (settings.Extension)) {
				host.SetFileExtension (settings.Extension);
			}
			if (settings.Encoding != null) {
				//FIXME: when is this called with false?
				host.SetOutputEncoding (settings.Encoding, true);
			}
			
			string output = "";
			try {
				output = Run (results, settings.Namespace + "." + settings.Name, host, settings.Culture);
			} catch (Exception ex) {
				pt.LogError ("Error running transform: " + ex.ToString ());
			}
			host.LogErrors (pt.Errors);
			return output;
		}
Example #5
0
		public CompiledTemplate CompileTemplate (string content, ITextTemplatingEngineHost host)
		{
			ParsedTemplate pt = ParsedTemplate.FromText (content, host);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			TemplateSettings settings = GetSettings (host, pt);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			CodeCompileUnit ccu = GenerateCompileUnit (host, pt, settings);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			System.Reflection.Assembly results = GenerateCode (host, pt, settings, ccu);
			if (pt.Errors.HasErrors) {
				host.LogErrors (pt.Errors);
				return null;
			}
			
			if (!String.IsNullOrEmpty (settings.Extension)) {
				host.SetFileExtension (settings.Extension);
			}
			if (settings.Encoding != null) {
				//FIXME: when is this called with false?
				host.SetOutputEncoding (settings.Encoding, true);
			}
			
			return new CompiledTemplate (pt, host, results, settings);
		}