public override IEnumerable<ISavableFile> Create(FileCreationContext context) { byte[] data = null; var evaluator = context.GetStringEvaluator(); if (ContentsType == Templates.ContentsType.Text) data = Encoding.UTF8.GetBytes(evaluator.EvaluateString(UnevaluatedContents)); else data = Convert.FromBase64String(UnevaluatedContents); var file = context.FileService.CreateFile(context.FilePath.ParentDirectory.Combine(evaluator.EvaluateString(UnevaluatedName)), data); if (!string.IsNullOrEmpty(DependentUpon)) file.Dependencies.Add(evaluator.EvaluateString(DependentUpon)); if (context.CurrentProject != null) { var entry = new ProjectFileEntry(file.FilePath); entry.Dependencies.AddRange(file.Dependencies); context.CurrentProject.ProjectFiles.Add(entry); } return new ISavableFile[] { file }; }
public override IEnumerable <ISavableFile> Create(FileCreationContext context) { byte[] data = null; var evaluator = context.GetStringEvaluator(); if (ContentsType == Templates.ContentsType.Text) { data = Encoding.UTF8.GetBytes(evaluator.EvaluateString(UnevaluatedContents)); } else { data = Convert.FromBase64String(UnevaluatedContents); } var file = context.FileService.CreateFile(context.FilePath.ParentDirectory.Combine(evaluator.EvaluateString(UnevaluatedName)), data); if (!string.IsNullOrEmpty(DependentUpon)) { file.Dependencies.Add(evaluator.EvaluateString(DependentUpon)); } if (context.CurrentProject != null) { var entry = new ProjectFileEntry(file.FilePath); entry.Dependencies.AddRange(file.Dependencies); context.CurrentProject.ProjectFiles.Add(entry); } return(new ISavableFile[] { file }); }
public override IEnumerable <ISavableFile> Create(FileCreationContext context) { // TODO: better detection of project descriptor... var descriptor = LanguageDescriptor.GetLanguageByName(LanguageName).GetProjectDescriptors().FirstOrDefault(); var evaluator = context.GetStringEvaluator(); var project = descriptor.CreateProject(evaluator.EvaluateString(Path.GetFileNameWithoutExtension(UnevaluatedName))); project.FilePath = context.FilePath.Combine(evaluator.EvaluateString(UnevaluatedName)); context.CurrentProject = project; var referenceProvider = project as IAssemblyReferenceProvider; var propertyProvider = project as IPropertyProvider; if (referenceProvider != null && ReferencesNode != null) { foreach (XmlNode child in ReferencesNode.ChildNodes) { referenceProvider.References.Add(new AssemblyReference(evaluator.EvaluateString(child.InnerText))); } } if (propertyProvider != null && PropertiesNode != null) { foreach (XmlNode child in PropertiesNode.ChildNodes) { propertyProvider.SetProperty( evaluator.EvaluateString(child.Attributes["Name"].Value), evaluator.EvaluateString(child.InnerText)); } } if (FilesNode != null) { foreach (XmlNode child in FilesNode.ChildNodes) { var newContext = context.Clone() as FileCreationContext; newContext.FilePath = project.FilePath; new FileTemplateNode(child).Create(newContext); } } context.CurrentProject = null; return(new ISavableFile[] { project }); }
public override IEnumerable<ISavableFile> Create(FileCreationContext context) { // TODO: better detection of project descriptor... var descriptor = LanguageDescriptor.GetLanguageByName(LanguageName).GetProjectDescriptors().FirstOrDefault(); var evaluator = context.GetStringEvaluator(); var project = descriptor.CreateProject(evaluator.EvaluateString(Path.GetFileNameWithoutExtension(UnevaluatedName))); project.FilePath = context.FilePath.Combine(evaluator.EvaluateString(UnevaluatedName)); context.CurrentProject = project; var referenceProvider = project as IAssemblyReferenceProvider; var propertyProvider = project as IPropertyProvider; if (referenceProvider != null && ReferencesNode != null) { foreach (XmlNode child in ReferencesNode.ChildNodes) referenceProvider.References.Add(new AssemblyReference(evaluator.EvaluateString(child.InnerText))); } if (propertyProvider != null && PropertiesNode != null) { foreach (XmlNode child in PropertiesNode.ChildNodes) propertyProvider.SetProperty( evaluator.EvaluateString(child.Attributes["Name"].Value), evaluator.EvaluateString(child.InnerText)); } if (FilesNode != null) { foreach (XmlNode child in FilesNode.ChildNodes) { var newContext = context.Clone() as FileCreationContext; newContext.FilePath = project.FilePath; new FileTemplateNode(child).Create(newContext); } } context.CurrentProject = null; return new ISavableFile[] { project }; }