private void AddNewFile(String location, String fileName, VSTemplate template) { if (template == null || this.Callback == null) { return; } if (String.IsNullOrEmpty(location) || String.IsNullOrEmpty(fileName)) { return; } fileName = System.IO.Path.GetFileNameWithoutExtension(fileName); String file = template.GetProjectFile(location, fileName); if (File.Exists(file)) { String msg = String.Format(Constants.Message.FileIsExist, this.ProjectName); System.Windows.MessageBox.Show(msg, Constants.Message.Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } // 1、复制相关文件; template.Copy(this.Location, fileName); // 2、 this.Callback(file, template.TemplateData.Type); }
private String GetValidName(VSTemplate template) { String name = template == null ? String.Empty : template.TemplateData.DefaultName; if (String.IsNullOrEmpty(name)) { return(name); } String defaultExt = System.IO.Path.GetExtension(template.Project.TargetFileName); String nameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(name); String folderName = System.IO.Path.Combine(this.Location, nameWithoutExt); String fileName = folderName + defaultExt; if (!Directory.Exists(folderName) && !File.Exists(fileName)) { return(name); } for (int i = 1; true; i++) { String path = folderName + i; fileName = path + defaultExt; if (!Directory.Exists(path) && !File.Exists(fileName)) { return(nameWithoutExt + i); } } }
private void LoadTemplates(String path, ref List <VSTemplate> templates) { if (File.Exists(path)) { // 如果后缀名一致,则直接解析文件; if (path.EndsWith(Constants.Extension.Template, StringComparison.OrdinalIgnoreCase)) { VSTemplate template = VSTemplate.Parse(path); if (template != null) { if (templates == null) { templates = new List <VSTemplate>(); } templates.Add(template); } } return; } if (Directory.Exists(path)) { IEnumerable <String> files = Directory.EnumerateFiles(path); foreach (String file in files) { this.LoadTemplates(file, ref templates); } IEnumerable <String> folders = Directory.EnumerateDirectories(path); foreach (String folder in folders) { this.LoadTemplates(folder, ref templates); } } }
public static VSTemplate Parse(String file) { if (!File.Exists(file)) { return(null); } XmlDocument doc = new XmlDocument(); doc.Load(file); XmlElement root = doc.DocumentElement; if (!Constants.TAG.Root.Equals(root.Name)) { return(null); } VSTemplate data = new VSTemplate(file); return(data.Parse(root) ? data : null); }
private void AddNewProject(String location, String projectName, VSTemplate template) { if (template == null || this.Callback == null) { return; } String projectFolder = System.IO.Path.Combine(location, ProjectName); // if (Directory.Exists(projectFolder)) { String message = String.Format(Constants.Message.ProjectIsExist, this.ProjectName); System.Windows.MessageBox.Show(message, Constants.Message.Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } // 3、复制相关模板文件; String projectFile = template.Copy(projectFolder, this.ProjectName); // 3、调用回调函数; this.Callback(projectFile, template.TemplateData.Type); }
private void NewProject(String solutionLocation, String solutionName, String projectName, VSTemplate template) { if (template == null || this.Callback == null) { return; } // String solutionFolder = System.IO.Path.Combine(this.Location, this.SolutionName); if (Directory.Exists(solutionFolder)) { // Solution文件夹已经存在; String message = String.Format(Constants.Message.ProjectIsExist, this.Location); System.Windows.MessageBox.Show(message, Constants.Message.Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } Directory.CreateDirectory(solutionFolder); // String projectFolder = System.IO.Path.Combine(solutionFolder, ProjectName); String projectFile = template.Copy(projectFolder, projectName); //this(projectFile, projectName, template.TemplateData.Type, solutionName, solutionFolder); this.Callback(projectFile, template.TemplateData.Type); }
public TemplateItemModel(VSTemplate template) { this.Template = template; this.Refresh(); }