private void ResolveComponentCustomProperties() { _dataProfileFileName = ComponentMetaData.CustomPropertyCollection[DATA_PROFILE_FILE_NAME_PROPERTY_NAME].Value.ToString(); if (VariableDispenser.Contains(_dataProfileFileName)) { IDTSVariables100 variables = null; VariableDispenser.LockOneForRead(_dataProfileFileName, ref variables); _dataProfileFileName = (String)variables[0].Value; } _dataProfileColumnName = ComponentMetaData.CustomPropertyCollection[DATA_PROFILE_COLUMN_NAME_PROPERTY_NAME].Value.ToString(); if (VariableDispenser.Contains(_dataProfileColumnName)) { IDTSVariables100 variables = null; VariableDispenser.LockOneForRead(_dataProfileColumnName, ref variables); _dataProfileColumnName = (String)variables[0].Value; } _regexPatterns.Clear(); _regexPatterns = this.LoadRegularExpressions(_dataProfileFileName, _dataProfileColumnName); _emailAddressInputColumnName = ComponentMetaData.InputCollection[INPUT_NAME].CustomPropertyCollection[INPUT_COLUMN_NAME].Value.ToString(); // v2 _regexOptionsNumber = (Int64)(ComponentMetaData.CustomPropertyCollection[REGEX_OPTIONS_PROPERTY_NAME].Value); }
/// <summary>Reads a variable's value.</summary> /// <typeparam name="T">The type of the value.</typeparam> /// <param name="source">The source.</param> /// <param name="name">The variable name.</param> /// <param name="defaultValue">The default value to return if the variable does not exist.</param> /// <returns>The value of the variable.</returns> /// <remarks> /// The variable is locked for reading while the value is being read. /// </remarks> public static T TryGetValue <T> (this VariableDispenser source, string name, T defaultValue) { if (!source.Contains(name)) { return(defaultValue); } Variables variables = null; try { source.LockForRead(name); source.GetVariables(ref variables); T value = defaultValue; if (variables.TryGetVar <T>(name, out value)) { return(value); } return(defaultValue); } finally { if (variables != null) { variables.Unlock(); } }; }
public override DTSExecResult Validate(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log) { if (sleepInterval <= 0) { componentEvents.FireError(0, Resources.WaitForSignalTaskName, Resources.ErrorSleepInterval, string.Empty, 0); return(DTSExecResult.Failure); } if (string.IsNullOrEmpty(SignalVariable)) { componentEvents.FireError(0, Resources.WaitForSignalTaskName, Resources.ErrorSignalVariableHasToBeSpecified, string.Empty, 0); return(DTSExecResult.Failure); } if (!variableDispenser.Contains(SignalVariable)) { componentEvents.FireError(0, Resources.WaitForSignalTaskName, string.Format(Resources.ErrorSignalVariableDoesNotExists, SignalVariable), string.Empty, 0); return(DTSExecResult.Failure); } else { Variables vars = null; try { variableDispenser.LockOneForRead(SignalVariable, ref vars); if (vars != null && vars.Contains(SignalVariable)) { Variable v = vars[SignalVariable]; if (v.DataType != TypeCode.Boolean) { componentEvents.FireError(0, Resources.WaitForSignalTaskName, string.Format(Resources.ErrorSignalVariableNotBoolean, SignalVariable), string.Empty, 0); return(DTSExecResult.Failure); } else if (v.Namespace != "User") { componentEvents.FireError(0, Resources.WaitForSignalTaskName, Resources.ErrorSignalWariableNotFromUser, string.Empty, 0); return(DTSExecResult.Failure); } } else { componentEvents.FireError(0, Resources.WaitForSignalTaskName, string.Format(Resources.ErrorLockSignalVariable, SignalVariable), string.Empty, 0); return(DTSExecResult.Failure); } } finally { if (vars != null && vars.Locked) { vars.Unlock(); } } } return(base.Validate(connections, variableDispenser, componentEvents, log)); }
public override DTSExecResult Validate(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log) { const string METHOD_NAME = "CustomLoggingTask-Validate"; try { if (string.IsNullOrEmpty(_eventType)) { componentEvents.FireError(0, METHOD_NAME, "The event property must be specified", "", -1); return(DTSExecResult.Failure); } if (string.IsNullOrEmpty(_connectionName)) { componentEvents.FireError(0, METHOD_NAME, "No connection has been specified", "", -1); return(DTSExecResult.Failure); } //SqlConnection connection = connections[_connectionName].AcquireConnection(null) as SqlConnection; _connection = connections[_connectionName].AcquireConnection(null) as DbConnection; if (_connection == null) { ConnectionManager cm = connections[_connectionName]; Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSConnectionManagerDatabaseParameters100 cmParams = cm.InnerObject as Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSConnectionManagerDatabaseParameters100; _connection = cmParams.GetConnectionForSchema() as OleDbConnection; if (_connection == null) { componentEvents.FireError(0, METHOD_NAME, "The connection is not a valid ADO.NET or OLEDB connection", "", -1); return(DTSExecResult.Failure); } } if (!variableDispenser.Contains("System::SourceID")) { componentEvents.FireError(0, METHOD_NAME, "No System::SourceID variable available. This task can only be used in an Event Handler", "", -1); return(DTSExecResult.Failure); } return(DTSExecResult.Success); } catch (Exception exc) { componentEvents.FireError(0, METHOD_NAME, "Validation Failed: " + exc.ToString(), "", -1); return(DTSExecResult.Failure); } }
/// <summary> /// Sets the variable value. /// </summary> /// <param name="varName">Name of the var.</param> /// <param name="value">The value.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <returns></returns> public static void SetVariableValue(string varName, object value, VariableDispenser variableDispenser) { if (String.IsNullOrEmpty(varName)) { return; } if (variableDispenser.Contains(varName)) { Variables vars = null; variableDispenser.LockForRead(varName); variableDispenser.GetVariables(ref vars); Variable var = vars.OfType <Variable>().Where(x => x.QualifiedName == varName).FirstOrDefault(); var.Value = value; } }
/// <summary> /// Reads the Value of an SSIS Variable by a given variablename and a VariableDispenser /// </summary> /// <param name="variableDispenser">the variableDispenser of a running SSIS instance</param> /// <param name="variableName">the name of the SSIS variable</param> /// <returns>the value of the variable as a string, returns an empty string if variable is not found</returns> public static string GetValueFromVariable(VariableDispenser variableDispenser, string variableName) { if (!variableDispenser.Contains(variableName)) { return(string.Empty); } Variables vars = null; variableDispenser.LockOneForRead(variableName, ref vars); string result = vars[variableName].Value.ToString(); vars.Unlock(); return(result); }
/// <summary> /// Gets the type of the variable. /// </summary> /// <param name="varName">Name of the var.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <returns></returns> public static TypeCode GetVariableType(string varName, VariableDispenser variableDispenser) { if (String.IsNullOrEmpty(varName)) { return(TypeCode.Empty); } TypeCode typeCode = TypeCode.Empty; if (variableDispenser.Contains(varName)) { Variables vars = null; variableDispenser.LockForRead(varName); variableDispenser.GetVariables(ref vars); typeCode = vars.OfType <Variable>().Where(x => x.QualifiedName == varName).FirstOrDefault().DataType; } return(typeCode); }
private void ReadVariables(VariableDispenser variableDispenser) { variableDispenser.LockForRead("System::StartTime"); variableDispenser.LockForRead("System::PackageName"); variableDispenser.LockForRead("System::SourceName"); variableDispenser.LockForRead("System::MachineName"); variableDispenser.LockForRead("System::ExecutionInstanceGUID"); variableDispenser.LockForRead("System::EventHandlerStartTime"); variableDispenser.LockForRead("User::UID"); bool includesError = variableDispenser.Contains("System::ErrorCode"); if (includesError) { variableDispenser.LockForRead("System::ErrorCode"); variableDispenser.LockForRead("System::ErrorDescription"); } Variables vars = null; variableDispenser.GetVariables(ref vars); DateTime startTime = (DateTime)vars["System::StartTime"].Value; _packageDuration = DateTime.Now.Subtract(startTime).TotalSeconds; _packageName = vars["System::PackageName"].Value.ToString(); _taskName = vars["System::SourceName"].Value.ToString(); _machineName = vars["System::MachineName"].Value.ToString(); _executionid = vars["System::ExecutionInstanceGUID"].Value.ToString(); _handlerdatetime = (DateTime)vars["System::EventHandlerStartTime"].Value; _uid = vars["User::UID"].Value.ToString(); if (includesError) { _errorCode = vars["System::ErrorCode"].Value.ToString(); _errorDescription = vars["System::ErrorDescription"].Value.ToString(); } // release the variable locks. vars.Unlock(); // reset the dispenser variableDispenser.Reset(); }
private bool GetSignalledState(VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, out bool failure) { bool isSignalled = false; failure = false; if (string.IsNullOrEmpty(SignalVariable)) { componentEvents.FireError(0, Resources.WaitForSignalTaskName, Resources.ErrorSignalVariableHasToBeSpecified, string.Empty, 0); failure = true; } if (!variableDispenser.Contains(SignalVariable)) { componentEvents.FireError(0, Resources.WaitForSignalTaskName, string.Format(Resources.ErrorSignalVariableDoesNotExists, SignalVariable), string.Empty, 0); failure = true; } else { Variables vars = null; variableDispenser.LockOneForRead(SignalVariable, ref vars); if (vars != null && vars.Contains(SignalVariable)) { Variable v = vars[SignalVariable]; if (v.DataType != TypeCode.Boolean) { componentEvents.FireError(0, Resources.WaitForSignalTaskName, string.Format(Resources.ErrorSignalVariableNotBoolean, SignalVariable), string.Empty, 0); failure = true; } isSignalled = (bool)v.Value; vars.Unlock(); } else { componentEvents.FireError(0, Resources.WaitForSignalTaskName, string.Format(Resources.ErrorLockSignalVariable, SignalVariable), string.Empty, 0); failure = true; } } return(isSignalled); }
/// <summary> /// Gets the variable value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="varName">Name of the var.</param> /// <param name="variableDispenser">The variable dispenser.</param> /// <returns></returns> public static T GetVariableValue <T>(string varName, VariableDispenser variableDispenser) { if (String.IsNullOrEmpty(varName)) { return(default(T)); } T value = default(T); if (variableDispenser.Contains(varName)) { Variables vars = null; variableDispenser.LockForRead(varName); variableDispenser.GetVariables(ref vars); string obj = vars.OfType <Variable>().Where(x => x.QualifiedName == varName).FirstOrDefault().Value.ToString(); value = (T)System.ComponentModel.TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(obj); } return(value); }
/// <summary>Gets a variable's definition.</summary> /// <param name="source">The source.</param> /// <param name="name">The variable name.</param> /// <returns>The variable, if it exists or <see langword="null"/> otherwise.</returns> /// <remarks> /// The variable is locked for reading while the value is read. /// </remarks> public static Variable TryGetInfo(this VariableDispenser source, string name) { if (!source.Contains(name)) { return(null); } source.LockForRead(name); Variables variables = null; try { source.GetVariables(ref variables); return(variables[name]); } finally { if (variables != null) { variables.Unlock(); } }; }
private string _CheckVarName(string var_name, VariableDispenser variableDispenser) { try { if (!var_name.StartsWith("@[")) { return(var_name); } else { string tmp_var_name = var_name.Replace("@[", "").Replace("]", ""); if (variableDispenser.Contains(tmp_var_name)) { Variables result_variables = null; variableDispenser.LockForRead(tmp_var_name); variableDispenser.GetVariables(ref result_variables); if (result_variables.Contains(tmp_var_name)) { return((string)result_variables[tmp_var_name].Value); } else { return(var_name); } } else { return(var_name); } } } catch (Exception ex) { return(ex.Message + " - " + ex.StackTrace); } }
/// <summary> /// Validates the Task /// </summary> /// <param name="connections"></param> /// <param name="variableDispenser"></param> /// <param name="componentEvents"></param> /// <param name="log"></param> /// <returns></returns> public override DTSExecResult Validate(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log) { Debug.Print("Validation Started"); string xmlVariableQualifiedName = string.Empty; //Check XmlVariables if (string.IsNullOrEmpty(_xmlVariable)) { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorXmlVariableEmpty, string.Empty, 0); return(DTSExecResult.Failure); } else if (!variableDispenser.Contains(_xmlVariable)) //Check Variable exists { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, string.Format(Resources.ErrorXmlVariableNotExists, _xmlVariable), string.Empty, 0); return(DTSExecResult.Failure); } else { Variables vars = null; try { variableDispenser.Reset(); variableDispenser.LockOneForWrite(_xmlVariable, ref vars); if (vars == null || vars.Locked == false) //Check if wariable is writable { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, string.Format(Resources.ErrorLockingXmlVariable, _xmlVariable), string.Empty, 0); return(DTSExecResult.Failure); } else { Variable v = vars[0]; TypeCode dataType = v.DataType; xmlVariableQualifiedName = v.QualifiedName; if (v.Namespace != "User") //Check namespace. Vaiabe should be writable in the user name space { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorXmlVariableNotUser, string.Empty, 0); return(DTSExecResult.Failure); } if (v.DataType != TypeCode.String && v.DataType != TypeCode.Object) //Variable has to be string or object data type to be able to store XML { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorXmlVaraibleNotString, string.Empty, 0); return(DTSExecResult.Failure); } if (v.EvaluateAsExpression == true) //Variable cannot be expression to be writable { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorXmlVariableCannotHaveExpression, string.Empty, 0); return(DTSExecResult.Failure); } } } finally { if (vars != null && vars.Locked) { vars.Unlock(); } } } //Check VariableElementName if (string.IsNullOrEmpty(_variableElementName)) //Variable element has to be specified { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorVariableElementEmpty, string.Empty, 0); return(DTSExecResult.Failure); } else { try { XElement element = new XElement(_variableElementName); //Check the VariableElementName is proper name for XmlElement } catch { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, string.Format(Resources.ErrorNotValidElementName, _rootElementName), string.Empty, 0); return(DTSExecResult.Failure); } } //Check RootElementName if (string.IsNullOrEmpty(_rootElementName)) //Che that RootElementName is specified { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorRootXmlElementCannotBeEmpty, string.Empty, 0); return(DTSExecResult.Failure); } else { try { XElement element = new XElement(_rootElementName); //Check that RootElementName is valid XmlElement name } catch { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, string.Format(Resources.ErrorNotValidElementName, _rootElementName), string.Empty, 0); return(DTSExecResult.Failure); } } //Check ExportVaraibles if (_exportVariables.Count > 0) { Variables vars = null; try { variableDispenser.Reset(); foreach (string var in _exportVariables) { if (!variableDispenser.Contains(var)) //Check that all variables to be exported exists { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorInvalidVariables, string.Empty, 0); return(DTSExecResult.Failure); } variableDispenser.LockForRead(var); } variableDispenser.GetVariables(ref vars); if (vars == null || vars.Locked == false) //Check that all varaibles to be exported are readable { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorLockingReadVariables, string.Empty, 0); return(DTSExecResult.Failure); } else { foreach (Variable v in vars) { if (v.QualifiedName == xmlVariableQualifiedName) //Check that XmlVariable is not present int he Export Variable list. (Cannot export and write to the same variable) { componentEvents.FireError(0, Resources.VariablesToXmlTaskName, Resources.ErrorXmlVariableCannotBeExported, string.Empty, 0); } } } } finally { if (vars != null && vars.Locked) { vars.Unlock(); } variableDispenser.Reset(); } } Debug.Print("Validation Finished Successfully"); return(base.Validate(connections, variableDispenser, componentEvents, log)); }
/// <summary> /// Reads the Value of an SSIS Variable by a given variablename and a VariableDispenser /// </summary> /// <param name="variableDispenser">the variableDispenser of a running SSIS instance</param> /// <param name="variableName">the name of the SSIS variable</param> /// <returns>the value of the variable as a string, returns an empty string if variable is not found</returns> public static string GetValueFromVariable(VariableDispenser variableDispenser, string variableName) { if (!variableDispenser.Contains(variableName)) return string.Empty; Variables vars = null; variableDispenser.LockOneForRead(variableName, ref vars); string result = vars[variableName].Value.ToString(); vars.Unlock(); return result; }