protected override IList <IParameter> ExtractParameters() { var parameters = new List <IParameter>(); var configurationNode = FileXmlDocument.SelectSingleNode( $"/Project/Configurations/Configuration[Name=\"{_configurationName}\"]", NamespaceManager); if (configurationNode == null) { throw new InvalidConfigurationNameException(_configurationName); } var parameterNodes = configurationNode.SelectNodes( $"./Options/ParameterConfigurationValues/ConfigurationSetting", NamespaceManager); if (parameterNodes == null || parameterNodes.Count == 0) { return(parameters); } foreach (XmlNode parameterNode in parameterNodes) { var parameter = new ConfigurationParameter(parameterNode, false); if (parameter.Name != null) { parameters.Add(parameter); } } return(parameters); }
/// <summary> /// parses an <see cref="InsertBatchQuery"/> from <paramref name="tableDataXmlDocument"/>. /// </summary> /// <seealso cref="InsertBatchQuery.Parse(XmlNode)"/> /// <param name="tableDataXmlDocument"></param> /// <returns> /// <see cref="InsertBatchQuery"/> parsed from <paramref name="tableDataXmlDocument"/> /// </returns> /// <exception cref="InvalidFileXmlDocumentException"> /// thrown if parsing <see cref="InsertBatchQuery"/> failed /// </exception> public static InsertBatchQuery ParseInsertBatchQuery(FileXmlDocument tableDataXmlDocument) { try { InsertBatchQuery insertBatchQuery; // get table data xml node XmlNode tableDataXmlNode = tableDataXmlDocument.GetNodes("table")[0]; insertBatchQuery = InsertBatchQuery.Parse(tableDataXmlNode); return(insertBatchQuery); } catch (Exception exception) { // parsing InsertBatchQuery failed if ( exception is XmlNodeMissingNodeException || exception is InsertBatchQueryParseException) { throw new InvalidFileXmlDocumentException( tableDataXmlDocument, exception); } else // unhandled exception { throw exception; } } }
public InvalidFileXmlDocumentException( FileXmlDocument databaseFileXmlDocument, Exception innerException = null) : base(formatExceptionMessage(databaseFileXmlDocument.FilePath), innerException) { this.filePath = databaseFileXmlDocument.FilePath; }
protected override IList <IParameter> ExtractParameters() { var parameters = new List <IParameter>(); var projectConnectionParameterXmlNodes = FileXmlDocument.SelectNodes("/SSIS:Project/SSIS:DeploymentInfo/SSIS:ProjectConnectionParameters/SSIS:Parameter", NamespaceManager); if (projectConnectionParameterXmlNodes != null) { foreach (XmlNode projectConnectionParameterXmlNode in projectConnectionParameterXmlNodes) { parameters.Add(new ProjectParameter("Project", projectConnectionParameterXmlNode)); } } var packageParameterXmlNodes = FileXmlDocument.SelectNodes("/SSIS:Project/SSIS:DeploymentInfo/SSIS:PackageInfo/SSIS:PackageMetaData/SSIS:Parameters/SSIS:Parameter", NamespaceManager); if (packageParameterXmlNodes != null) { foreach (XmlNode packageParameterXmlNode in packageParameterXmlNodes) { var packageName = packageParameterXmlNode.SelectSingleNode("../../SSIS:Properties/SSIS:Property[@SSIS:Name = \"Name\"]", NamespaceManager)?.InnerText; parameters.Add(new ProjectParameter(packageName, packageParameterXmlNode)); } } return(parameters); }
private string[] ExtractConnectionManagerNames() { return(FileXmlDocument.SelectNodes("/SSIS:Project/SSIS:ConnectionManagers/SSIS:ConnectionManager", NamespaceManager)? .OfType <XmlElement>().Select(e => e.Attributes["SSIS:Name"]?.Value) .Where(v => !string.IsNullOrWhiteSpace(v)) .ToArray()); }
private void ResolveProtectionLevel() { _protectionLevelAttribute = FileXmlDocument.SelectSingleNode("/DTS:Executable", NamespaceManager)?.Attributes?["DTS:ProtectionLevel"]; // At least in Visual Studio 2017 (14.0.0800.98), the DTS:ProtectionLevel elemented is ommited in case it is set to DontSaveSensitive. if (_protectionLevelAttribute == null) { var attr = FileXmlDocument.CreateAttribute("DTS:ProtectionLevel"); attr.Value = "DontSaveSensitive"; _protectionLevelAttribute = attr; } var protectionLevelValue = _protectionLevelAttribute?.Value; ProtectionLevel protectionLevel; if (!Enum.TryParse(protectionLevelValue, true, out protectionLevel)) { throw new InvalidXmlException($"Invalid DTS:ProtectionLevel value {protectionLevelValue}.", FileXmlDocument); } if (!Enum.IsDefined(typeof(ProtectionLevel), protectionLevel)) { throw new InvalidXmlException($"Invalid DTS:ProtectionLevel value {protectionLevelValue}.", FileXmlDocument); } }
/// <summary> /// parses an <see cref="InsertQuery"/> array from <paramref name="tableDataXmlDocument"/>. /// </summary> /// <seealso cref="ParseInsertBatchQuery(FileXmlDocument)"/> /// <param name="tableDataXmlDocument"></param> /// <returns> /// <see cref="InsertQuery"/> array parsed from <paramref name="tableDataXmlDocument"/> /// </returns> /// <exception cref="InvalidFileXmlDocumentException"> /// <seealso cref="ParseInsertQueries(FileXmlDocument)"/> /// </exception> public static InsertQuery[] ParseInsertQueries(FileXmlDocument tableDataXmlDocument) { InsertQuery[] insertQueries; InsertBatchQuery insertBatchQuery = ParseInsertBatchQuery(tableDataXmlDocument); insertQueries = insertBatchQuery.InsertQueries; return(insertQueries); }
/// <summary> /// parses <see cref="DatabaseSchema"/> from <paramref name="databaseFileXmlDocument"/>. /// </summary> /// <seealso cref="DatabaseSchema.Parse(XmlNode)"/> /// <param name="databaseFileXmlDocument"></param> /// <returns> /// <see cref="DatabaseSchema"/> parsed from <paramref name="databaseFileXmlDocument"/> /// </returns> /// <exception cref="InvalidFileXmlDocumentException"> /// thrown if parsing <see cref="DatabaseSchema"/> from /// <paramref name="databaseFileXmlDocument"/> fails /// </exception> public static DatabaseSchema ParseDatabaseSchema(FileXmlDocument databaseFileXmlDocument) { try { XmlNode databaseSchemaXmlNode = databaseFileXmlDocument.GetElementsByTagName("database")[0]; DatabaseSchema databaseSchema = DatabaseSchema.Parse(databaseSchemaXmlNode); return(databaseSchema); } catch (DatabaseSchemaParseException databaseSchemaParseException) { throw new InvalidFileXmlDocumentException( databaseFileXmlDocument, databaseSchemaParseException); } }
protected override IList <IParameter> ExtractParameters() { var parameterNodes = FileXmlDocument.SelectNodes("/SSIS:Parameters/SSIS:Parameter", NamespaceManager); if (parameterNodes == null || parameterNodes.Count == 0) { return(null); } var parameters = new List <IParameter>(); foreach (XmlNode parameterNode in parameterNodes) { parameters.Add(new ProjectParameter("Project", parameterNode)); } return(parameters); }
private void ResolveProtectionLevel() { _protectionLevelAttribute = FileXmlDocument.SelectSingleNode("/DTS:Executable", NamespaceManager)?.Attributes?["DTS:ProtectionLevel"]; var protectionLevelValue = _protectionLevelAttribute?.Value; if (protectionLevelValue == null) { throw new InvalidXmlException("Failed to determine protection level. DTS:ProtectionLevel attribute was not found.", FileXmlDocument); } ProtectionLevel protectionLevel; if (!Enum.TryParse(protectionLevelValue, true, out protectionLevel)) { throw new InvalidXmlException($"Invalid DTS:ProtectionLevel value {protectionLevelValue}.", FileXmlDocument); } if (!Enum.IsDefined(typeof(ProtectionLevel), protectionLevel)) { throw new InvalidXmlException($"Invalid DTS:ProtectionLevel value {protectionLevelValue}.", FileXmlDocument); } }
private void ResolveProtectionLevel() { _protectionLevelAttribute = FileXmlDocument.SelectSingleNode("/DTS:Executable", NamespaceManager)?.Attributes?["DTS:ProtectionLevel"]; if (_protectionLevelAttribute == null) { _protectionLevelAttribute = FileXmlDocument.SelectSingleNode("/DTS:Executable", NamespaceManager).Attributes.Append(FileXmlDocument.CreateAttribute("DTS:ProtectionLevel")); ProtectionLevel = ProtectionLevel.DontSaveSensitive; } var protectionLevelValue = _protectionLevelAttribute.Value; ProtectionLevel protectionLevel; if (!Enum.TryParse(protectionLevelValue, true, out protectionLevel)) { throw new InvalidXmlException($"Invalid DTS:ProtectionLevel value {protectionLevelValue}. For Project {FilePath}", FileXmlDocument); } if (!Enum.IsDefined(typeof(ProtectionLevel), protectionLevel)) { throw new InvalidXmlException($"Invalid DTS:ProtectionLevel value {protectionLevelValue}. . For Project {FilePath}", FileXmlDocument); } }
protected override void PostInitialize() { var manifestXml = FileXmlDocument.DocumentElement; var projectProtectionLevelAttribute = manifestXml?.Attributes["SSIS:ProtectionLevel"]; var protectionLevelString = projectProtectionLevelAttribute?.Value; if (string.IsNullOrWhiteSpace(protectionLevelString)) { throw new InvalidXmlException("Invalid project file. SSIS:Project node must contain a SSIS:ProtectionLevel attribute.", manifestXml); } ProtectionLevel protectionLevel; if (!Enum.TryParse(protectionLevelString, out protectionLevel)) { throw new InvalidXmlException($"Invalid Protection Level {protectionLevelString}.", manifestXml); } if (protectionLevel == ProtectionLevel.EncryptAllWithUserKey || protectionLevel == ProtectionLevel.EncryptSensitiveWithUserKey) { throw new InvalidProtectionLevelException(protectionLevel); } _protectionLevelNodes.Add(projectProtectionLevelAttribute); PackageNames = ExtractPackageNames(); ConnectionManagerNames = ExtractConnectionManagerNames(); foreach (XmlElement packageProtectionLevelNode in FileXmlDocument.SelectNodes("//SSIS:Property[@SSIS:Name = \"ProtectionLevel\"]", NamespaceManager)) { packageProtectionLevelNode.InnerText = protectionLevel.ToString("D"); _protectionLevelNodes.Add(packageProtectionLevelNode); } var versionMajorNode = FileXmlDocument.SelectSingleNode("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionMajor\"]", NamespaceManager); if (versionMajorNode == null) { throw new InvalidXmlException("Version Major Xml Node was not found", FileXmlDocument); } var versionMajorString = versionMajorNode.InnerText; int test; if (!int.TryParse(versionMajorString, out test)) { throw new InvalidXmlException($"Invalid value of Version Major Xml Node: {versionMajorString}.", FileXmlDocument); } var versionMajorNodes = FileXmlDocument.SelectNodes("//*[@SSIS:Name = \"VersionMajor\"]", NamespaceManager); if (versionMajorNodes != null) { foreach (XmlElement element in versionMajorNodes) { if (element != null) { element.InnerText = versionMajorString; _versionMajorNodes.Add(element); } } } var versionMinorNode = FileXmlDocument.SelectSingleNode("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionMinor\"]", NamespaceManager); if (versionMinorNode == null) { throw new InvalidXmlException("Version Minor Xml Node was not found", FileXmlDocument); } var versionMinorString = versionMinorNode.InnerText; if (!int.TryParse(versionMinorString, out test)) { throw new InvalidXmlException($"Invalid value of Version Minor Xml Node: {versionMinorString}.", FileXmlDocument); } var versionMinorNodes = FileXmlDocument.SelectNodes("//*[@SSIS:Name = \"VersionMinor\"]", NamespaceManager); if (versionMinorNodes != null) { foreach (XmlElement element in versionMinorNodes) { if (element != null) { element.InnerText = versionMinorString; _versionMinorNodes.Add(element); } } } var versionBuildNode = FileXmlDocument.SelectSingleNode("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionBuild\"]", NamespaceManager); if (versionBuildNode == null) { throw new InvalidXmlException("Version Build Xml Node was not found", FileXmlDocument); } var versionBuildString = versionBuildNode.InnerText; if (!int.TryParse(versionBuildString, out test)) { throw new InvalidXmlException($"Invalid value of Version Build Xml Node: {versionBuildString}.", FileXmlDocument); } var versionBuildNodes = FileXmlDocument.SelectNodes("//*[@SSIS:Name = \"VersionBuild\"]", NamespaceManager); if (versionBuildNodes != null) { foreach (XmlElement element in versionBuildNodes) { if (element != null) { element.InnerText = versionBuildString; _versionBuildNodes.Add(element); } } } var versionCommentsNode = FileXmlDocument.SelectSingleNode("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"VersionComments\"]", NamespaceManager); if (versionCommentsNode == null) { throw new InvalidXmlException("Version Comments Xml Node was not found", FileXmlDocument); } var versionCommentsString = versionCommentsNode.InnerText; var versionCommentsNodes = FileXmlDocument.SelectNodes("//*[@SSIS:Name = \"VersionComments\"]", NamespaceManager); if (versionCommentsNodes != null) { foreach (XmlElement element in versionCommentsNodes) { if (element != null) { element.InnerText = versionCommentsString; _versionCommentsNodes.Add(element); } } } _descriptionNode = FileXmlDocument.SelectSingleNode("/SSIS:Project/SSIS:Properties/SSIS:Property[@SSIS:Name = \"Description\"]", NamespaceManager) as XmlElement; if (_descriptionNode == null) { throw new InvalidXmlException("Description Xml Node was not found", FileXmlDocument); } }