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);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public override object Execute(Package package, DtsContainer container)
        {
            object returnValue;

            CommandParentType commandParentType = GetCommandParentType();

            try
            {
                OnCommandStarted(new CommandStartedEventArgs(DateTime.Now, CommandName, null, null, commandParentType));

                Variables         vars      = null;
                VariableDispenser dispenser = container.VariableDispenser;

                string varName = VariableName;

                if (Operation == VariableOperation.Get)
                {
                    dispenser.LockOneForRead(varName, ref vars);
                    returnValue = vars[varName].Value;
                    vars.Unlock();
                }
                else
                {
                    // writing to the variable
                    object varValue = Value;
                    dispenser.LockOneForWrite(varName, ref vars);
                    vars[varName].Value = Convert.ChangeType(varValue, vars[varName].DataType);
                    vars.Unlock();
                    returnValue = varValue;
                }

                OnCommandCompleted(new CommandCompletedEventArgs(DateTime.Now, CommandName, null, null, string.Format("The {0} command has completed.", CommandName), commandParentType));
            }
            catch (Exception ex)
            {
                OnCommandFailed(new CommandFailedEventArgs(DateTime.Now, CommandName, null, null, ex.Message, commandParentType));

                throw;
            }

            return(returnValue);
        }
        public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction)
        {
            //initialize report execution service
            string RSExecURL = @"http://" + Server + "/ReportServer/ReportExecution2005.asmx";
            ReportExecutionService RSExec2005 = new ReportExecutionService();

            RSExec2005.Credentials = System.Net.CredentialCache.DefaultCredentials;
            RSExec2005.Url         = RSExecURL;

            //prepare variables
            byte[]    Results  = null;
            Warning[] warnings = null;
            string    encoding;
            string    mimetype;

            string[] streamids = null;
            string   extension;

            try
            {
                ExecutionInfo Info = new ExecutionInfo();
                Info = RSExec2005.LoadReport(SelectedReport, null);


                if (DtParameters != null)
                {
                    if (DtParameters.Rows.Count > 0)
                    {
                        List <Tuple <string, string> > lstParameters = new List <Tuple <string, string> >();
                        foreach (DataRow row in DtParameters.Rows)
                        {
                            if (row["ParameterValue"] != null)
                            {
                                if (!string.IsNullOrEmpty(row["ParameterValue"].ToString()))
                                {
                                    //the parameter value has to be a variable
                                    string pName = row["ParameterName"].ToString();

                                    Variables varPValue = null;
                                    variableDispenser.LockOneForRead(row["ParameterValue"].ToString(), ref varPValue);
                                    string pValue = varPValue[0].Value.ToString();

                                    lstParameters.Add(Tuple.Create(pName, pValue));
                                }
                            }
                        }

                        ParameterValue[] Parameters;
                        if (lstParameters.Count > 0)
                        {
                            Parameters = new ParameterValue[lstParameters.Count];

                            for (int i = 0; i < lstParameters.Count; i++)
                            {
                                Parameters[i]       = new ParameterValue();
                                Parameters[i].Name  = lstParameters[i].Item1;
                                Parameters[i].Value = lstParameters[i].Item2;
                            }

                            RSExec2005.SetExecutionParameters(Parameters, "en-us");
                        }
                    }
                }

                //output format and name
                Variables varFileFormat = null;
                variableDispenser.LockOneForRead(FileFormat, ref varFileFormat);

                Variables varFileName = null;
                variableDispenser.LockOneForRead(FileName, ref varFileName);

                Results = RSExec2005.Render(varFileFormat[0].Value.ToString(), null, out extension, out mimetype, out encoding, out warnings, out streamids);
                Info    = RSExec2005.GetExecutionInfo();

                FileStream FS = File.Create(varFileName[0].Value.ToString(), Results.Length);
                FS.Write(Results, 0, Results.Length);
                FS.Close();

                return(DTSExecResult.Success);
            }
            catch (Exception ex)
            {
                componentEvents.FireError(0, "Reporting Service Task", "Task Error: " + ex.ToString(), "", -1);
                return(DTSExecResult.Failure);
            }
        }
Exemplo n.º 7
0
        private bool isValidVariable(VariableDispenser variableDispenser, string var, TypeCode type)
        {
            Variables variables = (Variables)null;

            try
            {
                variableDispenser.LockOneForRead(var, ref variables);

                Variable variable = variables[var];

                if (variable.DataType != type)
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
            finally
            {
                if (variables != null)
                    variables.Unlock();
            }

            return true;
        }
Exemplo n.º 8
0
        // The main data flow function
        public override void PrimeOutput(int outputs, int[] outputIDs, PipelineBuffer[] buffers)
        {
            // Get teh model
            JSONDataModel model = getModel();

            // Initialize Couchbase Client
            CouchbaseClientConfiguration config = new CouchbaseClientConfiguration();

            config.Urls.Add(new Uri(ComponentMetaData.CustomPropertyCollection["url"].Value.ToString().TrimEnd('/') + "/pools/"));
            config.Bucket         = ComponentMetaData.CustomPropertyCollection["bucket"].Value.ToString();
            config.BucketPassword = ComponentMetaData.CustomPropertyCollection["password"].Value.ToString();
            CouchbaseClient client = new CouchbaseClient(config);

            // Extract the parameters
            string designDoc    = ComponentMetaData.CustomPropertyCollection["designDoc"].Value.ToString();
            string viewName     = ComponentMetaData.CustomPropertyCollection["view"].Value.ToString();
            bool   forceReindex = (bool)ComponentMetaData.CustomPropertyCollection["forceReindex"].Value;
            bool   descending   = (bool)ComponentMetaData.CustomPropertyCollection["descending"].Value;


            // Define the view to be executed
            IView <IViewRow> view = ((IView <IViewRow>)client.GetView(designDoc, viewName))
                                    .Stale(forceReindex ? StaleMode.False : StaleMode.AllowStale)
                                    .Descending(descending);

            // Extract the variables from the package
            IDTSVariables100 variables = null;

            // StartKey can be set from another task prior of running this task
            string startKey = ComponentMetaData.CustomPropertyCollection["startKey"].Value;

            if (startKey != null && startKey.StartsWith("@"))
            {
                VariableDispenser.LockOneForRead(startKey.Substring(1), ref variables);
                startKey = variables[0].Value.ToString();
                variables.Unlock();

                ComponentMetaData.PostLogMessage("Couchbase", ComponentMetaData.Name, "Found a variable StartKey. Using " + startKey + " as value.", DateTime.Now, DateTime.Now, 0, null);
            }

            // EndKey can be set from another task prior of running this task
            string endKey = ComponentMetaData.CustomPropertyCollection["endKey"].Value;

            if (endKey != null && endKey.StartsWith("@"))
            {
                VariableDispenser.LockOneForRead(endKey.Substring(1), ref variables);
                endKey = variables[0].Value.ToString();
                variables.Unlock();

                ComponentMetaData.PostLogMessage("Couchbase", ComponentMetaData.Name, "Found a variable EndKey. Using " + endKey + " as value.", DateTime.Now, DateTime.Now, 0, null);
            }

            // Apply variables to the view if necessary
            if (startKey != null && !startKey.Equals(""))
            {
                view = view.StartKey <string>(startKey);
            }

            if (endKey != null && !endKey.Equals(""))
            {
                view = view.EndKey <string>(endKey);
            }

            // Iterate over each document returned by the view
            foreach (IViewRow row in view)
            {
                // Say that we have read it
                ComponentMetaData.IncrementPipelinePerfCounter(101, 1);

                // Write it out to the outputs
                writeDocToBuffers(row.ItemId, row.GetItem().ToString(), model, outputIDs, buffers);

                // Say that we wrote it
                ComponentMetaData.IncrementPipelinePerfCounter(103, 1);
            }

            // Flush out all buffers and get outta here
            foreach (PipelineBuffer buffer in buffers)
            {
                /// Notify the data flow task that no more rows are coming.
                buffer.SetEndOfRowset();
            }
        }
        public override void PreExecute()
        {
            bool             debugging = false;
            IDTSVariables100 vars      = null;

            try
            {
                VariableDispenser.LockOneForRead(JSON_SOURCE_DEBUG_VAR, ref vars);
                object o = vars[JSON_SOURCE_DEBUG_VAR].Value;
                if (o != null)
                {
                    if ((bool)o)
                    {
                        debugging = true;
                    }
                }
            }
            catch (Exception e) {
                //Do nothing
                bool fireAgain = false;
                ComponentMetaData.FireInformation(0, ComponentMetaData.Name, "wk_debug variable cannot be found. I won't stop to let debug attachment.", null, 0, ref fireAgain);
            }
            finally
            {
                if (vars != null)
                {
                    vars.Unlock();
                }
            }

            if (debugging)
            {
                MessageBox.Show("Start Debugger");
            }

            TransformationModel m = GetModel();

            _opt = new ParallelOptions();
            _opt.MaxDegreeOfParallelism = 4;

            bool cancel = false;

            // Carico i dettagli dal model
            try{
                m = GetModel();
            }catch (ModelNotFoundException ex) {
                ComponentMetaData.FireError(RUNTIME_ERROR_MODEL_INVALID, ComponentMetaData.Name, "Invalid Metadata for this component.", null, 0, out cancel);
                return;
            }

            // Salva il mapping in un array locale
            _iomap = m.IoMap.ToArray <IOMapEntry>();

            // Salva una copia locale del percorso cui attingere l'array
            _pathToArray = m.JsonObjectRelativePath;

            // Genera un dizionario ad accesso veloce per il nome della colonna per i dati json: mappo nome colonna - Indice della colonna nella riga.
            // Questo dizionario è usato solo per il JSON, mentre per gli input standard non facciamo il lookup, ma usiamo l'indice del buffer.
            _startOfJsonColIndex = ComponentMetaData.InputCollection[0].InputColumnCollection.Count;
            _outColsMaps         = new Dictionary <string, int>();
            foreach (IOMapEntry e in _iomap)
            {
                bool found = false;
                for (var i = 0; i < _iomap.Count(); i++)
                {
                    var col = ComponentMetaData.OutputCollection[0].OutputColumnCollection[_startOfJsonColIndex + i];
                    if (col.Name == e.OutputColName)
                    {
                        found = true;
                        int colIndex = BufferManager.FindColumnByLineageID(ComponentMetaData.OutputCollection[0].Buffer, col.LineageID);
                        _outColsMaps.Add(e.OutputColName, colIndex);
                        break;
                    }
                }
                if (!found)
                {
                    // Una colonna del model non ha trovato il corrispettivo nel componente attuale
                    ComponentMetaData.FireError(RUNTIME_ERROR_MODEL_INVALID, ComponentMetaData.Name, "The component is unable to locate the column named " + e.OutputColName + " inside the component metadata. Please review the component.", null, 0, out cancel);
                    return;
                }
            }

            _inputColIndex = BufferManager.FindColumnByLineageID(ComponentMetaData.InputCollection[0].Buffer, ComponentMetaData.InputCollection[0].InputColumnCollection[GetModel().InputColumnName].LineageID);

            // Check if ww should take care of date parsing
            if (!m.ParseDates)
            {
                _dateParsePolicy = DateParseHandling.None;
            }
        }
Exemplo n.º 10
0
        /// <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;
        }