public virtual string GetProjectDirectory(IProjectEnvironment environment)
        {
            if (!String.IsNullOrEmpty(environment.ProjectDirectory))
            {
                if (_fileSystem.IsRooted(environment.ProjectDirectory))
                {
                    return
                        String.IsNullOrEmpty(environment.ProjectName)
                            ? environment.ProjectDirectory
                            : _fileSystem.Combine(environment.ProjectDirectory, environment.ProjectName);
                }
                else
                {
                    string path;
                    if (environment.IsTemplate)
                        path = _fileSystem.Combine(_fileSystem.ExecutingDirectory, environment.ProjectDirectory);
                    else
                        path = _fileSystem.Combine(_fileSystem.CurrentDirectory, environment.ProjectDirectory);

                    if (!String.IsNullOrEmpty(environment.ProjectName))
                        path = _fileSystem.Combine(path, environment.ProjectName);

                    return path;
                }
            }
            else
                return
                    String.IsNullOrEmpty(environment.ProjectName)
                        ? _fileSystem.CurrentDirectory
                        : _fileSystem.Combine(_fileSystem.CurrentDirectory, environment.ProjectName);
        }
        public override bool Transform(IProjectManifest templateManifest, IProjectEnvironment environment, IProjectEnvironment templateEnvironment)
        {
            string rootDirectory = _manifestRepository.GetProjectDirectory(environment);
            ITemplateContext context = BuildTemplateContext(_fileSystem, _processor, environment);
            foreach (FileDTO file in templateManifest.Files)
            {
                string templateRoot = _manifestRepository.GetProjectDirectory(templateEnvironment);
                string fileTemplatePath = JoinTemplatePath(templateRoot, file.Source);
                string fileProcessedPath = _processor.Process(fileTemplatePath, context);

                if (!_fileSystem.Exists(fileProcessedPath))
                    throw new FileNotFoundException(
                        string.Format(CultureInfo.CurrentUICulture, nuresources.FileTransformation_MissingFile, fileProcessedPath));

                string fileContent = _fileSystem.ReadToEnd(fileProcessedPath);
                string processedFileContent = _processor.Process(fileContent, context);

                string fileTemplateDestinationPath = JoinTemplatePath(rootDirectory, file.Destination);
                string fileProcessedDestinationPath = _processor.Process(fileTemplateDestinationPath, context);

                _fileSystem.Write(fileProcessedDestinationPath, processedFileContent);
                file.Source = string.Empty;
                file.Destination = fileProcessedDestinationPath;
            }
            return true;
        }
 public virtual ITemplateContext BuildTemplateContext(IFileSystem fileSystem,
     ITemplateProcessor templateProcessor, IProjectEnvironment environment)
 {
     ITemplateContext context = templateProcessor.CreateTemplateContext();
     context.Items[PROJECT_KEY] = environment.ProjectName;
     context.Items[DIRECTORY_KEY] = environment.ProjectDirectory;
     context.Items[DIRECTORY_SEPARATOR_KEY] = fileSystem.DirectorySeparatorChar;
     return context;
 }
 public void Process(IProjectManifest templateManifest, IProjectEnvironment environment, IProjectEnvironment templateEnvironment)
 {
     if(_elements != null)
     {
         foreach (ITransformationElement transformationElement in _elements)
         {
             if (!transformationElement.Transform(templateManifest, environment, templateEnvironment))
                 break;
         }
     }
 }
 public override void Save(IProjectEnvironment environment, IProjectManifest projectManifest)
 {
     string manifestPath = GetManifestPath(environment);
     ProjectManifestBuilder builder = new ProjectManifestBuilder();
     XmlSerializer serializer = new XmlSerializer(typeof (Manifest));
     using (StringWriter writer = new StringWriter())
     {
         serializer.Serialize(writer, builder.Build(projectManifest));
         PrepareManifestDirectory(environment);
         _fileSystem.Write(manifestPath, writer.ToString());
     }
 }
 public virtual string GetProjectName(IProjectEnvironment environment)
 {
     if (String.IsNullOrEmpty(environment.ProjectName))
     {
         int startIdx = environment.ProjectDirectory.LastIndexOf(_fileSystem.DirectorySeparatorChar.ToString()) + 1;
         return environment.ProjectDirectory.Substring(startIdx);
     }
     else
     {
         return environment.ProjectName;
     }
 }
 public override bool Transform(IProjectManifest templateManifest, IProjectEnvironment environment, IProjectEnvironment templateEnvironment)
 {
     string rootDirectory = _manifestRepository.GetProjectDirectory(environment);
     ITemplateContext context = BuildTemplateContext(_fileSystem, _templateProcessor, environment);
     foreach (FolderDTO folder in templateManifest.Directories)
     {
         string folderTemplatePath = _fileSystem.Combine(rootDirectory, folder.Path);
         string folderProcessedPath = _templateProcessor.Process(folderTemplatePath, context);
         _fileSystem.CreateDirectory(folderProcessedPath);
         folder.Path = folderProcessedPath;
     }
     return true;
 }
        public override IProjectManifest Load(IProjectEnvironment environment)
        {
            Manifest manifest;
            string manifestPath = GetManifestPath(environment);
            ProjectManifestBuilder builder = new ProjectManifestBuilder();
            XmlSerializer serializer = new XmlSerializer(typeof (Manifest));

            if(!Exists(environment))
                throw new FileNotFoundException(string.Format(CultureInfo.CurrentUICulture,
                    nuresources.ProjectManifest_ManifestDoesNotExist, manifestPath));

            using (Stream stream = _fileSystem.Read(manifestPath))
            {
                manifest = (Manifest) serializer.Deserialize(stream);
            }
            return builder.Build(manifest);
        }
 public abstract bool Transform(IProjectManifest templateManifest, IProjectEnvironment environment, IProjectEnvironment templateEnvironment);
 protected virtual void PrepareManifestDirectory(IProjectEnvironment environment)
 {
     if (!Exists(environment))
     {
         string manifestPath = GetManifestPath(environment);
         _fileSystem.CreateHiddenDirectory(
             RemoveManifestFileName(manifestPath));
     }
 }
 public virtual void Save(IProjectEnvironment environment, IProjectManifest projectManifest)
 {
     throw new NotImplementedException();
 }
 public virtual IProjectManifest Load(IProjectEnvironment environment)
 {
     throw new NotImplementedException();
 }
 public virtual string GetManifestPath(IProjectEnvironment environment)
 {
     return _fileSystem.Combine(GetProjectDirectory(environment),
         _fileSystem.Combine(PROJECT_MANIFEST_DIRECTORY, PROJECT_MANIFEST_FILE));
 }
 public virtual bool Exists(IProjectEnvironment environment)
 {
     string manifestPath = GetManifestPath(environment);
     return _fileSystem.Exists(manifestPath);
 }