Exemplo n.º 1
0
      /// <summary>Loads template info object from the specified file path.</summary>
      public static TemplateInfo Load(string filePath) {
         try {
            TemplateInfo ti = new TemplateInfo();
            ti.FilesContent = new Dictionary<string, string>();

            string stxContent = System.IO.File.ReadAllText(filePath);
            ti.FilesContent.Add(filePath, stxContent);

            ti.Name = Path.GetFileNameWithoutExtension(filePath);
            ti.GroupFile = Path.Combine(Path.GetDirectoryName(filePath), string.Format("{0}.stg", ti.Name));

            string stgContent = System.IO.File.ReadAllText(ti.GroupFile);
            ti.FilesContent.Add(ti.GroupFile, stgContent);

            XElement element = XElement.Load(filePath);
            ti.Description = element.Attribute("description").Value;
            ti.Lexer = element.Attribute("lexer").Value;

            // Load filters
            ti.Filters = new List<Regex>();
            foreach (XElement xItem in element.Element("Filters").Elements()) {
               string filter = xItem.Attribute("pattern").Value;
               ti.Filters.Add(new Regex(filter));
            }

            // Load types map
            ti.TypesMap = new Dictionary<string, string>();
            foreach (XElement xItem in element.Element("TypesMapper").Elements()) {
               string src = xItem.Attribute("type").Value;
               string dst = xItem.Attribute("to").Value;
               ti.TypesMap.Add(src, dst);
            }

            // Load template execution commands
            ti.RunCommands = new List<TemplateCommand>();
            foreach (XElement xItem in element.Element("Commands").Elements()) {
               string level = xItem.Attribute("level").Value;
               string tmplt = xItem.Attribute("template").Value;
               string folder = xItem.Attribute("folder").Value;
               string file = xItem.Attribute("file").Value;
               TemplateLevel tLevel = (TemplateLevel)Enum.Parse(typeof(TemplateLevel), level);
               ti.RunCommands.Add(new TemplateCommand(tLevel, tmplt, folder, file));
            }

            return ti;
         } catch (Exception ex) {
            throw new Exception(string.Format("Failed to load template from file: {0}", filePath), ex);
         }
      }
Exemplo n.º 2
0
      /// <summary>Updates the template view.</summary>
      public void UpdateTemplateView(TemplateInfo tInfo) {
         // Clear Template View
         TemplateView.Children.Clear();
         if (tInfo == null) return;


         var expanderStyle = (Style)FindResource("@SchemaExpander");
         var textboxStyle = (Style)FindResource("@SchemaTextBox");

         foreach (string key in tInfo.FilesContent.Keys) {
            string content = tInfo.FilesContent[key];
            TemplateView.Children.Add(new Expander {
               Header = key,
               IsExpanded = true,
               Style = expanderStyle,
               Content = new TextBox {
                  Style = textboxStyle,
                  Text = content
               }
            });
         }
      }
Exemplo n.º 3
0
 /// <summary>Creates a new <see cref="CodeGenerator"/> instance.</summary>
 public CodeGenerator(TemplateInfo templateInfo) {
    this.TemplateInfo = templateInfo;
 }