Esempio n. 1
0
        public override void ExecuteProfile(Parser parser)
        {
            string file       = Path.Combine(Program.Configuration.Output, OutPutPath, GetRelativePath(parser.Filename), Path.GetFileNameWithoutExtension(parser.Filename));
            var    xmlMessage = Program.Configuration.XmlMessagesProfile.SearchXmlPattern(Path.GetFileNameWithoutExtension(parser.Filename));

            if (xmlMessage == null)
            {
                Program.Shutdown(string.Format("File {0} not found", file));
            }

            var engine = new Engine();
            var host   = new TemplateHost(TemplatePath);

            host.Session["Message"] = xmlMessage;
            host.Session["Profile"] = this;
            var output = engine.ProcessTemplate(File.ReadAllText(TemplatePath), host);

            foreach (CompilerError error in host.Errors)
            {
                Console.WriteLine("File:{0} Line:{1} : {2}", error.FileName, error.Line, error.ErrorText);
            }

            if (host.Errors.Count > 0)
            {
                Program.Shutdown();
            }

            File.WriteAllText(file + host.FileExtension, output);

            Console.WriteLine("Wrote {0}", file);
        }
Esempio n. 2
0
        public void LoadIncludeTextFile1()
        {
            // fields
            string path         = Directory.GetCurrentDirectory();
            string fileName     = "LoadIncludeTextFile1.inc";
            string fullFileName = Path.Combine(path, fileName);
            string fileContent  = "LoadIncludeTextFile1";

            // Create File
            File.WriteAllText(fullFileName, fileContent);

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            string a;
            string b;

            host.LoadIncludeText(fullFileName, out a, out b);

            // Evaluate result
            Assert.AreEqual(fileContent, a);

            // Delete File
            File.Delete(fullFileName);
        }
Esempio n. 3
0
        public override void ExecuteProfile(Parser parser)
        {
            string file = Path.Combine(BuilderConfiguration.Instance.Output, this.OutPutPath, this.GetRelativePath(parser.Filename), Path.GetFileNameWithoutExtension(parser.Filename));

            var engine = new Engine();
            var host   = new TemplateHost(this.TemplatePath);

            host.Session["Parser"]  = parser;
            host.Session["Profile"] = this;
            var output = engine.ProcessTemplate(File.ReadAllText(this.TemplatePath), host);

            foreach (CompilerError error in host.Errors)
            {
                Console.WriteLine(error.ErrorText);
            }

            if (host.Errors.Count > 0)
            {
                Program.Shutdown();
            }

            File.WriteAllText(file + host.FileExtension, output);

            Logger.Write(string.Format("Wrote {0}", file), ConsoleColor.Gray);
        }
        public override void ExecuteProfile(Parser parser)
        {
            string file = Path.Combine(Program.Configuration.Output, OutPutPath, GetRelativePath(parser.Filename),
                                       Path.GetFileNameWithoutExtension(parser.Filename));

            string moduleFile =
                parser.Fields.Where(entry => entry.Name == "MODULE").Select(entry => entry.Value).SingleOrDefault();

            var engine = new Engine();
            var host   = new TemplateHost(TemplatePath);

            host.Session["Parser"]  = parser;
            host.Session["Profile"] = this;
            string output = engine.ProcessTemplate(File.ReadAllText(TemplatePath), host);

            foreach (CompilerError error in host.Errors)
            {
                Console.WriteLine(error.ErrorText);
            }

            if (host.Errors.Count > 0)
            {
                Program.Shutdown();
            }

            File.WriteAllText(file + host.FileExtension, output);

            Console.WriteLine("Wrote {0}", file + host.FileExtension);
        }
        public override void ExecuteProfile(Parser parser)
        {
            string file   = Path.Combine(Program.Configuration.Output, OutPutPath, GetRelativePath(parser.Filename), Path.GetFileNameWithoutExtension(parser.Filename));
            var    engine = new Engine();
            var    host   = new TemplateHost(TemplatePath);

            if (_templateContentText == null)
            {
                _templateContentText = File.ReadAllText(TemplatePath);
            }
            host.Session["Profile"] = this;
            host.Session["Parser"]  = parser;
            SetTemplateParams(parser, file, host);
            var output = engine.ProcessTemplate(_templateContentText, host);

            foreach (CompilerError error in host.Errors)
            {
                Console.Error.WriteLine(error.ErrorText);
            }

            if (host.Errors.Count > 0)
            {
                Program.Shutdown();
            }

            File.WriteAllText(file + host.FileExtension, output);

            Console.WriteLine("Wrote {0}", file + host.FileExtension);
        }
Esempio n. 6
0
        public override void ExecuteProfile(Parser parser)
        {
            string file       = Path.Combine(BuilderConfiguration.Instance.Output, this.OutPutPath, this.GetRelativePath(parser.Filename), Path.GetFileNameWithoutExtension(parser.Filename));
            var    xmlMessage = BuilderConfiguration.Instance.XmlMessagesProfile.SearchXmlPattern(Path.GetFileNameWithoutExtension(parser.Filename));

            if (xmlMessage == null)
            {
                Program.Shutdown(string.Format("File {0} not found", file));
            }
            var engine = new Engine();
            var host   = new TemplateHost(this.TemplatePath);

            host.Session["Message"] = xmlMessage;
            host.Session["Profile"] = this;

            var output = engine.ProcessTemplate(File.ReadAllText(this.TemplatePath), host);

            foreach (CompilerError error in host.Errors)
            {
                this.logger.Error(error.ErrorText + " line (" + error.Line + ")");
            }

            if (host.Errors.Count > 0)
            {
                Program.Shutdown();
            }

            File.WriteAllText(file + host.FileExtension, output);


            Logger.Write(string.Format("Wrote {0}", Path.GetFileNameWithoutExtension(parser.Filename) + ".cs"), ConsoleColor.Gray);
        }
Esempio n. 7
0
        public void LoadIncludeTextFile2()
        {
            // fields
            string path         = Directory.GetCurrentDirectory();
            string fileName     = "LoadIncludeTextFile2.inc";
            string fullFileName = Path.Combine(path, fileName);
            string fileContent  = string.Empty;

            // Init fileContent
            StringBuilder sb = new StringBuilder();

            sb.Append("LoadIncludeTextFile2" + Environment.NewLine);

            for (int idx = Char.MinValue; idx < System.Int16.MaxValue; idx++)
            {
                sb.Append((Char)idx);
            }
            fileContent = sb.ToString();

            // Create File
            File.WriteAllText(fullFileName, fileContent);

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());
            string a;
            string b;

            host.LoadIncludeText(fullFileName, out a, out b);
            // Evaluate result
            Assert.AreEqual(fileContent, a);

            // Delete File
            File.Delete(fullFileName);
        }
Esempio n. 8
0
        public void ProvideTemplatingAppDomainWithStaticHostValues()
        {
            // fields
            string path         = Directory.GetCurrentDirectory();
            string content      = string.Empty;
            int    accountValue = 111;
            string clientName   = "ClientName";

            // Create Arguments object
            IDictionary <string, PropertyData> arguments = new Dictionary <string, PropertyData>();

            arguments.Add("Account", new PropertyData(accountValue, typeof(int)));
            arguments.Add("Client", new PropertyData(clientName, typeof(string)));

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, arguments);

            AppDomain appDomain = host.ProvideTemplatingAppDomain(content);

            object test = appDomain.CreateInstanceAndUnwrap(
                typeof(MockTransformationRunner).Assembly.FullName,
                typeof(MockTransformationRunner).FullName);
            MockTransformationRunner mock = (MockTransformationRunner)test;

            Assert.IsNotNull(test);
            Assert.AreEqual(typeof(MockTransformationRunner).FullName, test.GetType().FullName);

            int    accountResult = (int)((PropertyData)mock.GetHostArgumentValue("Account")).Value;
            string clientResult  = (string)((PropertyData)mock.GetHostArgumentValue("Client")).Value;

            Assert.AreEqual(accountValue, accountResult);
            Assert.AreEqual(clientName, clientResult);
        }
        private string Render(string templateCode, string templateFile)
        {
            EnvDTE.DTE vs       = this.GetService <EnvDTE.DTE>(true);
            string     basePath = this.GetBasePath();

            Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngine engine = new Microsoft.VisualStudio.TextTemplating.Engine();
            IValueInfoService service = (IValueInfoService)this.GetService(typeof(IValueInfoService));
            Dictionary <string, PropertyData> arguments = new Dictionary <string, PropertyData>();

            foreach (string str2 in base.additionalArguments.Keys)
            {
                Type type = null;
                try
                {
                    type = service.GetInfo(str2).Type;
                }
                catch (ArgumentException)
                {
                    if (base.additionalArguments[str2] != null)
                    {
                        type = base.additionalArguments[str2].GetType();
                    }
                    else
                    {
                        continue;
                    }
                }
                PropertyData data = new PropertyData(base.additionalArguments[str2], type);
                arguments.Add(str2, data);
            }
            TemplateHost host = new TemplateHost(basePath, arguments);

            host.TemplateFile = templateFile;
            Helpers.LogMessage(vs, this, templateFile);

            string str3 = engine.ProcessTemplate(templateCode, host);

            if (host.Errors.HasErrors)
            {
                string errors = "";
                foreach (CompilerError error in host.Errors)
                {
                    Helpers.LogMessage(vs, this, error.ErrorText);
                    errors += error.ErrorText + Environment.NewLine;
                }
                throw new TemplateException(host.Errors);
            }
            if (host.Errors.HasWarnings)
            {
                StringBuilder builder = new StringBuilder();
                foreach (CompilerError error in host.Errors)
                {
                    builder.AppendLine(error.ErrorText);
                }
                //Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "CompilationWarnings", new object[] { templateFile, builder.ToString() }));
            }
            return(str3);
        }
Esempio n. 10
0
        public void TemplateHostIsITextTemplatingEngineHost()
        {
            // fields
            string path = Directory.GetCurrentDirectory();

            // Create the Host
            TemplateHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            Assert.IsTrue(host is ITextTemplatingEngineHost);
        }
Esempio n. 11
0
        public void StandardImports()
        {
            // fields
            string path = Directory.GetCurrentDirectory();

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            Assert.IsNull(host.StandardImports);
        }
Esempio n. 12
0
        public void TemplateHostIsMarshalByRefObject()
        {
            // fields
            string path = Directory.GetCurrentDirectory();

            // Create the Host
            TemplateHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            Assert.IsTrue(host is MarshalByRefObject);
        }
Esempio n. 13
0
        public void IncludeTemplateThrowsIfTemplatePathNotUnderBinPath()
        {
            string path = Directory.GetCurrentDirectory();

            // Create the Host
            string       a;
            string       b;
            TemplateHost host    = new TemplateHost(path, new Dictionary <string, PropertyData>());
            bool         include = host.LoadIncludeText("C:\\Temp\\Outside.ipe", out a, out b);
        }
Esempio n. 14
0
        public void StandardAssemblyReferences()
        {
            // fields
            string path = Directory.GetCurrentDirectory();

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            Assert.IsTrue(host.StandardAssemblyReferences.Count == 1);
        }
Esempio n. 15
0
        public void ResolvesIncludeRelativeToTemplatePath()
        {
            // fields
            string path = Directory.GetCurrentDirectory();

            // Create the Host
            TemplateHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            Assert.AreEqual(path + "\\Templates\\File.t4", host.ResolveFileName("Templates\\File.t4"));
        }
Esempio n. 16
0
        public void CanCreateTemplateHostWithPaths()
        {
            // fields
            string path = Directory.GetCurrentDirectory();

            // Create the Host
            TemplateHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            Assert.IsNotNull(host);
        }
Esempio n. 17
0
        public void ResolveDirectiveProcessorWithNull()
        {
            // fields
            string path     = Directory.GetCurrentDirectory();
            string fileName = null;

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());
            Type result = host.ResolveDirectiveProcessor(fileName);
        }
Esempio n. 18
0
        protected override void SetTemplateParams(Parser parser, string file, TemplateHost host)
        {
            var xmlMessage = Program.Configuration.XmlMessagesProfile.SearchXmlPattern(Path.GetFileNameWithoutExtension(parser.Filename));

            if (xmlMessage == null)
            {
                Program.Shutdown($"File {file} not found");
            }

            host.Session["Message"] = xmlMessage;
        }
Esempio n. 19
0
        public void ResolveAssemblyReferenceWithNull()
        {
            // fields
            string path              = Directory.GetCurrentDirectory();
            string fileName          = null;
            string fileContentResult = string.Empty;

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            fileContentResult = host.ResolveAssemblyReference(fileName);
        }
Esempio n. 20
0
        public void ResolveDirectiveProcessorWrongName()
        {
            // fields
            string path          = Directory.GetCurrentDirectory();
            string processorName = "PropertyProcessorWrongName";

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            Type result = host.ResolveDirectiveProcessor(processorName);

            Assert.AreEqual(null, result);
        }
Esempio n. 21
0
        public void ThrowsIfLoadIncludeTextFileWithNull()
        {
            // fields
            string path              = Directory.GetCurrentDirectory();
            string fullFileName      = null;
            string fileContentResult = string.Empty;

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());
            string a;
            string b;

            host.LoadIncludeText(fullFileName, out a, out b);
        }
Esempio n. 22
0
        private object Render(string templateCode, string template)
        {
            string basePath              = GetBasePath();
            var    additionalArguments   = new Dictionary <string, string>();
            ITextTemplatingEngine engine = new Engine();
            var service   = (IValueInfoService)GetService(typeof(IValueInfoService));
            var arguments = new Dictionary <string, PropertyData>();

            additionalArguments.Add("StoreNamespace", string.Empty);
            additionalArguments.Add("StoreSelectedProxyType", ProxyTypes.NoProxy);
            additionalArguments.Add("StoreProxyApi", string.Empty);
            additionalArguments.Add("StoreSelectedExtends", GlobalConstants.FlatStore);
            additionalArguments.Add("StoreSelectedModel", "." + ModelNamespace + ModelClassName);
            additionalArguments.Add("StoreProxyParams", string.Empty);
            additionalArguments.Add("StoreClassName", ModelClassName + "s");

            foreach (string str2 in additionalArguments.Keys)
            {
                Type type = null;
                if (additionalArguments[str2] != null)
                {
                    type = additionalArguments[str2].GetType();
                }
                else
                {
                    continue;
                }
                var data = new PropertyData(additionalArguments[str2], type);
                arguments.Add(str2, data);
            }
            var host = new TemplateHost(basePath, arguments)
            {
                TemplateFile = template
            };
            string str3 = engine.ProcessTemplate(templateCode, host);

            if (host.Errors.HasErrors)
            {
                throw new TemplateException(host.Errors);
            }
            if (host.Errors.HasWarnings)
            {
                var builder = new StringBuilder();
                foreach (CompilerError error in host.Errors)
                {
                    builder.AppendLine(error.ToString());
                }
            }
            return(str3);
        }
Esempio n. 23
0
        public void ResolveAssemblyExistsBinPath()
        {
            if (Directory.Exists("Temp"))
            {
                Directory.Delete("Temp", true);
            }
            Directory.CreateDirectory("Temp");
            File.Copy(new Uri(this.GetType().Assembly.CodeBase).LocalPath, "Temp\\Test.dll");

            ITextTemplatingEngineHost host = new TemplateHost(
                "Temp", new Dictionary <string, PropertyData>());
            string result = host.ResolveAssemblyReference("Test.dll");

            Assert.AreEqual(new FileInfo("Temp\\Test.dll").FullName, result, "Resolution did not include bin path even if the file existed.");

            Directory.Delete("Temp", true);
        }
Esempio n. 24
0
        public void ResolveAssemblyNotExistsBinPathExistsCurrDir()
        {
            if (Directory.Exists("Temp"))
            {
                Directory.Delete("Temp", true);
            }
            Directory.CreateDirectory("Temp");
            string asmName = this.GetType().Module.Name;

            ITextTemplatingEngineHost host = new TemplateHost(
                "Temp", new Dictionary <string, PropertyData>());
            string result = host.ResolveAssemblyReference(asmName);

            Assert.AreEqual(asmName, result, "Resolution did not resolve to the dll in the base directory.");

            Directory.Delete("Temp", true);
        }
Esempio n. 25
0
        public void ProvideTemplatingAppDomain()
        {
            // fields
            string path    = Directory.GetCurrentDirectory();
            string content = string.Empty;

            // Create the Host
            ITextTemplatingEngineHost host = new TemplateHost(path, new Dictionary <string, PropertyData>());

            AppDomain appDomain = host.ProvideTemplatingAppDomain(content);

            object test = appDomain.CreateInstanceAndUnwrap(
                typeof(MockTransformationRunner).Assembly.FullName,
                typeof(MockTransformationRunner).FullName);

            Assert.IsNotNull(test);
            Assert.AreEqual(typeof(MockTransformationRunner).FullName, test.GetType().FullName);
        }
Esempio n. 26
0
        public void CanCreateTemplateHostWithArguments()
        {
            // fields
            string path         = Directory.GetCurrentDirectory();
            int    accountValue = 111;
            string clientName   = "ClientName";

            // Create Arguments object
            IDictionary <string, PropertyData> arguments = new Dictionary <string, PropertyData>();

            arguments.Add("Account", new PropertyData(accountValue, typeof(int)));
            arguments.Add("Client", new PropertyData(clientName, typeof(string)));

            // Create the Host
            TemplateHost host = new TemplateHost(path, arguments);

            Assert.IsNotNull(host);
        }
Esempio n. 27
0
        public void CanAccessArguments()
        {
            // fields
            string path         = Directory.GetCurrentDirectory();
            int    accountValue = 111;
            string clientName   = "ClientName";

            // Create Arguments object
            IDictionary <string, PropertyData> arguments = new Dictionary <string, PropertyData>();

            arguments.Add("Account", new PropertyData(accountValue, typeof(string)));
            arguments.Add("Client", new PropertyData(clientName, typeof(string)));

            // Create the Host
            TemplateHost host = new TemplateHost(path, arguments);

            Assert.AreEqual(accountValue, host.Arguments["Account"].Value);
            Assert.AreEqual(clientName, host.Arguments["Client"].Value);
        }
Esempio n. 28
0
        public override void ExecuteProfile(Parser parser)
        {
            // if (parser.Class.Name.Contains("FightCommonInformations"))
            //  {

            // }
            var relativePath = GetRelativePath(parser.Filename);

            string file    = Path.Combine(BuilderConfiguration.Instance.Output, OutPutPath, relativePath, Path.GetFileNameWithoutExtension(parser.Filename));
            var    xmlType = BuilderConfiguration.Instance.XmlTypesProfile.SearchXmlPattern(Path.GetFileNameWithoutExtension(parser.Filename));

            if (xmlType == null)
            {
                Program.Shutdown(string.Format("File {0} not found", file));
            }

            var engine = new Engine();
            var host   = new TemplateHost(TemplatePath);

            host.Session["Type"]    = xmlType;
            host.Session["Profile"] = this;
            var output = engine.ProcessTemplate(File.ReadAllText(TemplatePath), host);

            foreach (CompilerError error in host.Errors)
            {
                Console.WriteLine(error.ErrorText);
            }

            if (host.Errors.Count > 0)
            {
                Program.Shutdown();
            }

            File.WriteAllText(file + host.FileExtension, output);

            Logger.Write(string.Format("Wrote {0}", file), ConsoleColor.Gray);
        }
        private object Render(string templateCode, string template)
        {
            string basePath = GetBasePath();
            var additionalArguments = new Dictionary<string, string>();
            ITextTemplatingEngine engine = new Engine();
            var service = (IValueInfoService)GetService(typeof(IValueInfoService));
            var arguments = new Dictionary<string, PropertyData>();

            additionalArguments.Add("StoreNamespace", string.Empty);
            additionalArguments.Add("StoreSelectedProxyType", ProxyTypes.NoProxy);
            additionalArguments.Add("StoreProxyApi", string.Empty);
            additionalArguments.Add("StoreSelectedExtends", GlobalConstants.FlatStore);
            additionalArguments.Add("StoreSelectedModel", "." + ModelNamespace + ModelClassName);
            additionalArguments.Add("StoreProxyParams", string.Empty);
            additionalArguments.Add("StoreClassName", ModelClassName + "s");

            foreach (string str2 in additionalArguments.Keys)
            {
                Type type = null;
                if (additionalArguments[str2] != null)
                {
                    type = additionalArguments[str2].GetType();
                }
                else
                {
                    continue;
                }
                var data = new PropertyData(additionalArguments[str2], type);
                arguments.Add(str2, data);
            }
            var host = new TemplateHost(basePath, arguments)
            {
                TemplateFile = template
            };
            string str3 = engine.ProcessTemplate(templateCode, host);
            if (host.Errors.HasErrors)
            {
                throw new TemplateException(host.Errors);
            }
            if (host.Errors.HasWarnings)
            {
                var builder = new StringBuilder();
                foreach (CompilerError error in host.Errors)
                {
                    builder.AppendLine(error.ToString());
                }
            }
            return str3;
        }
Esempio n. 30
0
 public void ThrowsIfCreateTemplateHostWithArgumentsNull()
 {
     // Create the Host
     TemplateHost host = new TemplateHost(Directory.GetCurrentDirectory(), null);
 }
        private void GenerateTemplate()
        {
            tabControl1.TabPages.Clear();

            Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngine engine = new Microsoft.VisualStudio.TextTemplating.Engine();
            Dictionary<string, PropertyData> arguments = new Dictionary<string, PropertyData>();

            PropertyData data = new PropertyData(bcsModel, typeof(BCSModel));
            arguments.Add("BCSModel", data);

            arguments.Add("ProjectNamespace", new PropertyData("BBS.Project1", typeof(String)));
            arguments.Add("BCSModelName", new PropertyData("Model1", typeof(String)));
            arguments.Add("BCSDatabase", new PropertyData("BCSTest", typeof(String)));
            arguments.Add("BCSModelDisplayName", new PropertyData("Model 1", typeof(String)));
            arguments.Add("BCSModelIsCached", new PropertyData(false, typeof(Boolean)));
            arguments.Add("BCSPermissions", new PropertyData("contoso\\Administrator", typeof(String)));
            arguments.Add("BCSServer", new PropertyData("demo2010a", typeof(String)));
            arguments.Add("BCSModelVersion", new PropertyData("1.0.0.0", typeof(String)));
            arguments.Add("BCSEstimatedCount", new PropertyData("10000", typeof(String)));
            arguments.Add("ProjectAssemblyName", new PropertyData("BCS.Test.Model", typeof(String)));
            arguments.Add("GeneratedFileName", new PropertyData("OutputFileName", typeof(String)));
            arguments.Add("CopyrightCompanyName", new PropertyData("Company", typeof(String)));

            arguments.Add("BCSType", new PropertyData("Wcf", typeof(String)));

            foreach (string templateFile in checkedListBox1.CheckedItems)
            {
                tabControl1.TabPages.Add(templateFile, templateFile);
                TextBox txtbox = new TextBox();
                txtbox.Multiline = true;
                txtbox.ScrollBars = ScrollBars.Both;
                txtbox.Dock = DockStyle.Fill;
                txtbox.WordWrap = false;
                tabControl1.TabPages[templateFile].Controls.Add(txtbox);

                string templateCode = File.ReadAllText(@"F:\TFS\SPSF\Dev\Source\SPALM.SPSF\Templates\Text\BCS\" + templateFile);
                StringBuilder templateCodeLines = new StringBuilder();
                StringReader reader = new StringReader(templateCode);
                string line = "";
                bool headerinserted = false;
                while ((line = reader.ReadLine()) != null)
                {
                    templateCodeLines.AppendLine(line);

                    if (!headerinserted)
                    {
                        headerinserted = true;
                        templateCodeLines.AppendLine("<#@ assembly name=\"System.dll\" #>");
                        templateCodeLines.AppendLine("<#@ assembly name=\"SPALM.SPSF.Library.dll\" #>");
                        templateCodeLines.AppendLine("<#@ import namespace=\"SPALM.SPSF.Library\" #>");
                        foreach (string argument in arguments.Keys)
                        {
                            templateCodeLines.AppendLine("<#@ property processor=\"PropertyProcessor\" name=\"" + argument + "\" #>");
                        }
                    }
                }

                templateCode = templateCodeLines.ToString();

                TemplateHost host = new TemplateHost(@"F:\TFS\SPSF\Dev\Source\SPALM.SPSF\", arguments);
                host.TemplateFile = @"Templates\Text\BCS\BCSModel_SQL.bdcm.t4";
                string str3 = engine.ProcessTemplate(templateCode, host);

                foreach (CompilerError error in host.Errors)
                {
                    txtbox.Text += error.ErrorText + "(" + error.Line + ")";
                }

                if (!host.Errors.HasErrors)
                {
                    if (str3.Contains("<?xml"))
                    {
                        XmlDocument result = new XmlDocument();
                        result.LoadXml(str3);

                        XmlWriterSettings wSettings = new XmlWriterSettings();
                        wSettings.Indent = true;
                        wSettings.NewLineOnAttributes = false;
                        wSettings.IndentChars = "\t";

                        string path = Path.GetTempFileName();

                        XmlWriter xw = XmlWriter.Create(path, wSettings);
                        result.Save(xw);
                        xw.Flush();
                        xw.Close();

                        txtbox.Text += File.ReadAllText(path);
                    }
                    else
                    {
                        txtbox.Text += str3;
                    }
                }
            }
        }
Esempio n. 32
0
 public void ThrowsIfCreateTemplateHostWithBinPathNull()
 {
     // Create the Host
     TemplateHost host = new TemplateHost(null, new Dictionary <string, PropertyData>());
 }
        private string Render(string templateCode, string templateFile)
        {
            DTE vs = this.GetService<DTE>(true);
              string basePath = this.GetBasePath();
              Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngine engine = new Microsoft.VisualStudio.TextTemplating.Engine();
              IValueInfoService service = (IValueInfoService)this.GetService(typeof(IValueInfoService));
              Dictionary<string, PropertyData> arguments = new Dictionary<string, PropertyData>();
              foreach (string str2 in base.additionalArguments.Keys)
              {
            Type type = null;
            try
            {
              type = service.GetInfo(str2).Type;
            }
            catch (ArgumentException)
            {
              if (base.additionalArguments[str2] != null)
              {
                type = base.additionalArguments[str2].GetType();
              }
              else
              {
                continue;
              }
            }
            PropertyData data = new PropertyData(base.additionalArguments[str2], type);
            arguments.Add(str2, data);
              }
              TemplateHost host = new TemplateHost(basePath, arguments);
              host.TemplateFile = templateFile;
              Helpers.LogMessage(vs, this, templateFile);

              string str3 = engine.ProcessTemplate(templateCode, host);
              if (host.Errors.HasErrors)
              {
            string errors = "";
            foreach (CompilerError error in host.Errors)
            {
              Helpers.LogMessage(vs, this, error.ErrorText);
              errors += error.ErrorText + Environment.NewLine;
            }
            throw new TemplateException(host.Errors);
              }
              if (host.Errors.HasWarnings)
              {
            StringBuilder builder = new StringBuilder();
            foreach (CompilerError error in host.Errors)
            {
              builder.AppendLine(error.ErrorText);
            }
            //Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "CompilationWarnings", new object[] { templateFile, builder.ToString() }));
              }
              return str3;
        }