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 };
        }
Ejemplo n.º 2
0
        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 });
        }
Ejemplo n.º 3
0
        public override IEnumerable <ISavableFile> Create(FileCreationContext context)
        {
            var nodes = Type == TemplateType.Project ? GetProjectNodes() : GetFileNodes();

            foreach (var node in nodes)
            {
                foreach (var file in node.Create(context))
                {
                    yield return(file);
                }
            }
        }
Ejemplo n.º 4
0
        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 });
        }
Ejemplo n.º 5
0
            public FileCreationStringEvaluator(FileCreationContext context)
            {
                // TODO: escape strings.
                var solutionName      = context.CurrentSolution != null ? context.CurrentSolution.Name : null;
                var solutionDirectory = context.CurrentSolution != null ? context.CurrentSolution.FilePath.ParentDirectory.FullPath : null;
                var projectName       = context.CurrentProject != null ? context.CurrentProject.Name : null;
                var projectDirectory  = context.CurrentProject != null ? context.CurrentProject.FilePath.ParentDirectory.FullPath : null;

                var @namespace = FormatToNamespace(context.CurrentProject != null ? context.FilePath.ParentDirectory.GetRelativePath(context.CurrentProject) : context.FilePath.FileName);

                var namespaceProvider = context.CurrentProject as IRootNamespaceProvider;

                if (namespaceProvider != null)
                {
                    if (@namespace.Length > 0)
                    {
                        @namespace = namespaceProvider.RootNamespace + "." + @namespace;
                    }
                    else
                    {
                        @namespace = namespaceProvider.RootNamespace;
                    }
                }

                Arguments = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { "FullPath", context.FilePath.FullPath },
                    { "Directory", context.FilePath.ParentDirectory.FullPath },
                    { "Namespace", @namespace },
                    { "FileName", context.FilePath.FileName },
                    { "EscapedFileName", context.FilePath.FileName },
                    { "SolutionName", solutionName },
                    { "EscapedSolutionName", solutionName },
                    { "SolutionDirectory", solutionDirectory },
                    { "EscapedSolutionDirectory", solutionDirectory },
                    { "ProjectName", projectName },
                    { "EscapedProjectName", projectName },
                    { "ProjectDirectory", projectDirectory },
                    { "EscapedProjectDirectory", projectDirectory },
                };
            }
        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 FileCreationStringEvaluator(FileCreationContext context)
            {
                // TODO: escape strings.
                var solutionName = context.CurrentSolution != null ? context.CurrentSolution.Name : null;
                var solutionDirectory = context.CurrentSolution != null ? context.CurrentSolution.FilePath.ParentDirectory.FullPath : null;
                var projectName = context.CurrentProject != null ? context.CurrentProject.Name : null;
                var projectDirectory = context.CurrentProject != null ? context.CurrentProject.FilePath.ParentDirectory.FullPath : null;

                var @namespace = FormatToNamespace(context.CurrentProject != null ? context.FilePath.ParentDirectory.GetRelativePath(context.CurrentProject) : context.FilePath.FileName);

                var namespaceProvider = context.CurrentProject as IRootNamespaceProvider;
                if (namespaceProvider != null)
                {
                    if (@namespace.Length > 0)
                        @namespace = namespaceProvider.RootNamespace + "." + @namespace;
                    else
                        @namespace = namespaceProvider.RootNamespace;
                }

                Arguments = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    {"FullPath", context.FilePath.FullPath},
                    {"Directory", context.FilePath.ParentDirectory.FullPath},
                    {"Namespace", @namespace},
                    {"FileName", context.FilePath.FileName},
                    {"EscapedFileName", context.FilePath.FileName},
                    {"SolutionName", solutionName},
                    {"EscapedSolutionName", solutionName},
                    {"SolutionDirectory", solutionDirectory},
                    {"EscapedSolutionDirectory", solutionDirectory},
                    {"ProjectName", projectName},
                    {"EscapedProjectName", projectName},
                    {"ProjectDirectory", projectDirectory},
                    {"EscapedProjectDirectory", projectDirectory},
                };
            }
 public abstract IEnumerable<ISavableFile> Create(FileCreationContext context);
        public override IEnumerable<ISavableFile> Create(FileCreationContext context)
        {
            var nodes = Type == TemplateType.Project ? GetProjectNodes() : GetFileNodes();

            foreach (var node in nodes)
            {
                foreach (var file in node.Create(context))
                    yield return file;
            }
        }
Ejemplo n.º 10
0
 public abstract IEnumerable <ISavableFile> Create(FileCreationContext context);