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 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); } } }