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 Manifest Build(IProjectManifest projectManifest)
 {
     Manifest manifest = new Manifest();
     manifest.folders = new List<FolderDTO>(projectManifest.Directories).ToArray();
     manifest.files = new List<FileDTO>(projectManifest.Files).ToArray();
     manifest.packages = new List<PackageDTO>(projectManifest.Packages).ToArray();
     return manifest;
 }
示例#3
0
        public void LoadFromIspac(string filePath, string password)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException($"File {filePath} does not exist or you don't have permissions to access it.", filePath);
            }

            if (!filePath.EndsWith(".ispac", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidExtensionException(filePath, "ispac");
            }

            using (var ispacStream = new FileStream(filePath, FileMode.Open))
            {
                using (var ispacArchive = new ZipArchive(ispacStream, ZipArchiveMode.Read))
                {
                    foreach (var ispacArchiveEntry in ispacArchive.Entries)
                    {
                        var fileName = ispacArchiveEntry.FullName;
                        using (var fileStream = ispacArchiveEntry.Open())
                        {
                            switch (Path.GetExtension(fileName))
                            {
                            case ".manifest":
                                _projectManifest = new ProjectManifest();
                                _projectManifest.Initialize(fileStream, password);
                                break;

                            case ".params":
                                _projectParams = new ProjectParams();
                                _projectParams.Initialize(fileStream, password);
                                break;

                            case ".dtsx":
                                var package = new Package();
                                package.Initialize(fileStream, password);
                                _packages.Add(fileName, package);
                                break;

                            case ".conmgr":
                                var projectConnection = new ProjectConnection();
                                projectConnection.Initialize(fileStream, password);
                                _projectConnections.Add(fileName, projectConnection);
                                break;

                            case ".xml":
                                break;
                            }
                        }
                    }
                }
            }

            _isLoaded = true;
        }
 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 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 abstract bool Transform(IProjectManifest templateManifest, IProjectEnvironment environment, IProjectEnvironment templateEnvironment);
示例#8
0
        public void LoadFromDtproj(string filePath, string configurationName, string password)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException($"File {filePath} does not exist.", filePath);
            }

            if (!filePath.EndsWith(".dtproj", StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidExtensionException(filePath, "dtproj");
            }

            var dtprojXmlDoc = new XmlDocument();

            dtprojXmlDoc.Load(filePath);
            ValidateDeploymentMode(dtprojXmlDoc);

            var nsManager = dtprojXmlDoc.GetNameSpaceManager();

            var projectXmlNode = dtprojXmlDoc.SelectSingleNode("/Project/DeploymentModelSpecificContent/Manifest/SSIS:Project", nsManager);

            if (projectXmlNode == null)
            {
                throw new InvalidXmlException("Project Manifest Node was not found.", dtprojXmlDoc);
            }

            var projectDirectory = Path.GetDirectoryName(filePath);

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(projectXmlNode.OuterXml);
                    writer.Flush();
                    stream.Position = 0;

                    _projectManifest = new ProjectManifest();
                    _projectManifest.Initialize(stream, password);
                }
            }

            _projectParams = new ProjectParams();
            _projectParams.Initialize(Path.Combine(projectDirectory, "Project.params"), password);

            foreach (var connectionManagerName in _projectManifest.ConnectionManagerNames)
            {
                var projectConnection = new ProjectConnection();
                projectConnection.Initialize(Path.Combine(projectDirectory, connectionManagerName), password);
                _projectConnections.Add(connectionManagerName, projectConnection);
            }

            foreach (var packageName in _projectManifest.PackageNames)
            {
                var package = new Package();
                package.Initialize(Path.Combine(projectDirectory, packageName), password);
                _packages.Add(packageName, package);
            }

            _isLoaded = true;

            var configuration = new Configuration(configurationName);

            configuration.Initialize(filePath, password);
            foreach (var configurationParameter in configuration.Parameters)
            {
                UpdateParameter(configurationParameter.Key, configurationParameter.Value.Value, ParameterSource.Configuration);
            }

            var userConfigurationFilePath = $"{filePath}.user";
            var userConfiguration         = new UserConfiguration(configurationName);

            if (File.Exists(userConfigurationFilePath))
            {
                userConfiguration.Initialize(userConfigurationFilePath, password);
                foreach (var userConfigurationParameter in userConfiguration.Parameters)
                {
                    UpdateParameter(userConfigurationParameter.Key, null, ParameterSource.Configuration);
                }
            }
        }
 public virtual void Save(IProjectEnvironment environment, IProjectManifest projectManifest)
 {
     throw new NotImplementedException();
 }