public ScriptTaskWrapper(ContainerWrapper containerWrapper, string scriptProjectName, bool hasReference, ScriptTaskScope scope) : base(containerWrapper, "STOCK:ScriptTask") { ScriptTask = Convert.ChangeType(TaskHost.InnerObject, scriptTaskType); ScriptTask.ScriptLanguage = cSharpDisplayName; if (hasReference) { ScriptingEngine.VstaHelper.LoadProjectFromStorage(scriptStorages[scriptProjectName]); } else { try { ScriptingEngine.VstaHelper.LoadNewProject(ScriptTask.ProjectTemplatePath, null, scriptProjectName); } catch (System.IO.FileNotFoundException ex) { throw new InvalidOperationException($"Failed to load dependency {ex.FileName}. Ensure that you have installed the required SSIS components for your version of SQL Server.", ex); } // Add the ScriptStorage to the global list so it can be accessed later by a ScriptTaskReference. if (scope == ScriptTaskScope.Project) { scriptStorages[scriptProjectName] = ScriptStorage; } } ScriptingEngine.SaveProjectToStorage(); }
private static string GetVariableNames(List <ScriptVariable> scriptVariables, ScriptTaskScope scope, ProjectWrapper projectWrapper, PackageWrapper packageWrapper, ContainerWrapper containerWrapper) { if (scriptVariables == null) { return(string.Empty); // Return early if there are no variables configured for the script. } List <string> qualifiedVariableNames = new List <string>(); foreach (ScriptVariable scriptVariable in scriptVariables) { string qualifiedScriptVariableName = GetQualifiedVariableName(scriptVariable); switch (scriptVariable.Namespace) { case "$Package": if (scope == ScriptTaskScope.Package) { if (!packageWrapper.ContainsParameter(scriptVariable.VariableName)) { throw new InvalidOperationException($"Could find referenced package parameter {scriptVariable.VariableName}!"); } } break; case "$Project": if (!projectWrapper.ContainsParameter(scriptVariable.VariableName)) { throw new InvalidOperationException($"Could find referenced project parameter {scriptVariable.VariableName}!"); } break; default: if (scope == ScriptTaskScope.Package) { if (!containerWrapper.ContainsVariable(qualifiedScriptVariableName) && !packageWrapper.ContainsVariable(qualifiedScriptVariableName)) { throw new InvalidOperationException($"Couldn't find referenced variable {qualifiedScriptVariableName}!"); } } break; } qualifiedVariableNames.Add(qualifiedScriptVariableName); } return(string.Join(",", qualifiedVariableNames)); }