/// <summary>
        /// Prepares method's parameters that will be executed
        /// It will recuperate the direct values
        /// It will make the interpretation of the expressions
        /// It will pass NULL value for REF Or OUT params
        /// </summary>
        /// <param name="vars">The vars.</param>
        /// <param name="variableDispenser">The variable dispenser.</param>
        /// <returns></returns>
        private List <object> GetValuedParamsWithoutMethodInfo(Variables vars, VariableDispenser variableDispenser)
        {
            var objects = new List <object>();

            try
            {
                string[] mappedParams = MappingParams.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                objects.AddRange(from mappedParam in mappedParams
                                 let paramInfo = mappedParam.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[1]
                                                 let paramType = mappedParam.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[0].Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries)[1]
                                                                 let paramDirection = mappedParam.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2]
                                                                                      select Convert.ChangeType(EvaluateExpression(paramInfo.Trim(), variableDispenser)
                                                                                                                //select Convert.ChangeType(((paramInfo.Contains("@"))
                                                                                                                //                           ? EvaluateExpression(paramInfo.Trim(), variableDispenser)
                                                                                                                //                           : (paramDirection == ParameterDirection.IN)
                                                                                                                //                                   ? vars[paramInfo.Trim()].Value
                                                                                                                //                                   : vars["@" + paramInfo.Trim()].Value)
                                                                                                                , Type.GetType(paramType)));
            }
            catch (Exception exception)
            {
                throw new Exception("Check StackTrace " + exception.Message + " :: " + exception.StackTrace);
            }

            return(objects);
        }
Пример #2
0
        private void btSave_Click(object sender, EventArgs e)
        {
            var mappingParams = new MappingParams();

            mappingParams.AddRange(from DataGridViewRow mappingParam in grdParameters.Rows
                                   select new MappingParam
            {
                Name  = mappingParam.Cells[0].Value.ToString(),
                Type  = mappingParam.Cells[1].Value.ToString(),
                Value = mappingParam.Cells[2].Value.ToString()
            });

            var mappingHeaders = new MappingHeaders();

            mappingHeaders.AddRange(from DataGridViewRow mappingRow in grdHeaders.Rows
                                    where !mappingRow.IsNewRow
                                    select new MappingParam
            {
                Name  = mappingRow.Cells[0].Value.ToString(),
                Type  = "System.String",
                Value = mappingRow.Cells[1].Value.ToString()
            });

            //Save the values
            _taskHost.Properties[Keys.SERVICE_URL].SetValue(_taskHost, cmbURL.Text);
            _taskHost.Properties[Keys.SERVICE_CONTRACT].SetValue(_taskHost, cmbServices.Text);
            _taskHost.Properties[Keys.OPERATION_CONTRACT].SetValue(_taskHost, cmbMethods.Text);
            _taskHost.Properties[Keys.MAPPING_PARAMS].SetValue(_taskHost, mappingParams);
            _taskHost.Properties[Keys.MAPPING_HEADERS].SetValue(_taskHost, mappingHeaders);
            _taskHost.Properties[Keys.RETURNED_VALUE].SetValue(_taskHost, cmbReturnVariable.Text);
            _taskHost.Properties[Keys.IS_VALUE_RETURNED].SetValue(_taskHost, _withReturnValue);

            DialogResult = DialogResult.OK;
            Close();
        }
        private void btOk_Click(object sender, EventArgs e)
        {
            if (cmbFileType.SelectedItem == null || string.IsNullOrEmpty(cmbFileType.SelectedItem.ToString().Trim()))
            {
                MessageBox.Show("Please choose exported file type");
                cmbFileType.Focus();
                return;
            }

            if (cmbConfigurationFile.SelectedItem == null && string.IsNullOrEmpty(cmbConfigurationFile.Text))
            {
                MessageBox.Show("Please choose the destination of the exported file");
                cmbConfigurationFile.Focus();
                return;
            }

            //Save the values
            _taskHost.Properties[Keys.REPORTSERVER].SetValue(_taskHost, cmbSourceVariables.Text);
            _taskHost.Properties[Keys.REPORTNAME].SetValue(_taskHost, tvReportServerSource.SelectedNode.Text);
            _taskHost.Properties[Keys.REPORTNAME_EXPRESSION].SetValue(_taskHost, cmbReportName.Text);
            _taskHost.Properties[Keys.REPORTPATH].SetValue(_taskHost, tvReportServerSource.SelectedNode.Parent.FullPath.Replace(tvReportServerSource.Nodes[0].Text, string.Empty).Replace(@"\", "/"));
            _taskHost.Properties[Keys.OUTPUT_TYPE].SetValue(_taskHost, cmbFileType.SelectedItem);
            _taskHost.Properties[Keys.DESTINATION_FILE].SetValue(_taskHost, cmbConfigurationFile.Text);
            _taskHost.Properties[Keys.CONFIGURATION_TYPE].SetValue(_taskHost, optChooseVariable.Checked
                                                                                                ? ConfigurationType.TASK_VARIABLE
                                                                                                : ConfigurationType.FILE_CONNECTOR);


            _taskHost.Properties[Keys.SEND_FILE_BY_EMAIL].SetValue(_taskHost, chkEmail.Checked
                                                                                    ? Keys.TRUE
                                                                                    : Keys.FALSE);



            var mappingParams = new MappingParams();

            mappingParams.AddRange(from DataGridViewRow row in grdParameters.Rows
                                   select new MappingParam
            {
                Name  = row.Cells[0].Value.ToString(),
                Type  = row.Cells[1].Value.ToString(),
                Value = row.Cells[5].Value.ToString()
            });

            _taskHost.Properties[Keys.MAPPING_PARAMS].SetValue(_taskHost, mappingParams);
            Close();
        }
        /// <summary>
        /// Get REF or OUT values obtained after the execution of the method
        /// </summary>
        /// <param name="paramObject">The param object.</param>
        private void GetRefValueParamsWithoutMethodInfo(object[] paramObject)
        {
            int paramIndex = 0;

            string[] mappedParams = MappingParams.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var mappedParam in mappedParams)
            {
                var paramDirection = mappedParam.Split('|')[2];

                if (paramDirection == ParameterDirection.OUT)
                {
                    _vars[mappedParam.Split('|')[1].Trim()].Value = paramObject[paramIndex];
                }

                paramIndex++;
            }
        }
        /// <summary>
        /// Get REF or OUT values obtained after the execution of the method
        /// </summary>
        /// <param name="methodInfo">The method info.</param>
        /// <param name="paramObject">The param object.</param>
        private void GetRefValueParams(MethodInfo methodInfo, object[] paramObject)
        {
            int paramIndex = 0;

            foreach (ParameterInfo parameterInfo in methodInfo.GetParameters())
            {
                var mappedParams = MappingParams.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                foreach (var param in from param in mappedParams
                         where param.Length > 0
                         where param.Split('|')[0].Split('=')[0].Trim() == parameterInfo.Name
                         where param.Split('|')[0].Split('=')[1].Trim().Contains("&")
                         select param)
                {
                    _vars[param.Split('|')[1].Trim()].Value = paramObject[paramIndex];
                    break;
                }

                paramIndex++;
            }
        }
Пример #6
0
        private void FillGridWithParams(MappingParams mappingParams)
        {
            if (mappingParams != null)
            {
                foreach (var mappingParam in mappingParams)
                {
                    int index = grdParameters.Rows.Add();

                    DataGridViewRow row = grdParameters.Rows[index];

                    row.Cells["grdColParams"] = new DataGridViewTextBoxCell
                    {
                        Value = mappingParam.Name,
                        Tag   = mappingParam.Name,
                    };

                    row.Cells["grdColDirection"] = new DataGridViewTextBoxCell
                    {
                        Value = mappingParam.Type
                    };

                    row.Cells["grdColVars"]       = LoadVariables(mappingParam);
                    row.Cells["grdColExpression"] = new DataGridViewButtonCell();


                    if (_withReturnValue == 0)
                    {
                        lbOutputValue.Visible = cmbReturnVariable.Visible = false;
                        _withReturnValue      = 0;
                    }
                    else
                    {
                        lbOutputValue.Visible = cmbReturnVariable.Visible = true;
                        _withReturnValue      = 1;
                    }
                }
            }
        }
Пример #7
0
        private void btSave_Click(object sender, EventArgs e)
        {
            //Save the values
            _taskHost.Properties[NamedStringMembers.SERVICE_URL].SetValue(_taskHost, cmbURL.Text);
            _taskHost.Properties[NamedStringMembers.SERVICE].SetValue(_taskHost, cmbServices.Text);
            _taskHost.Properties[NamedStringMembers.WEBMETHOD].SetValue(_taskHost, cmbMethods.Text);

            var mappingParams = new MappingParams();

            mappingParams.AddRange(from DataGridViewRow mappingParam in grdParameters.Rows
                                   select new MappingParam
            {
                Name  = mappingParam.Cells[0].Value.ToString(),
                Type  = mappingParam.Cells[1].Value.ToString(),
                Value = mappingParam.Cells[2].Value.ToString()
            });

            _taskHost.Properties[NamedStringMembers.MAPPING_PARAMS].SetValue(_taskHost, mappingParams);
            _taskHost.Properties[NamedStringMembers.RETURNED_VALUE].SetValue(_taskHost, cmbReturnVariable.Text);
            _taskHost.Properties[NamedStringMembers.IS_VALUE_RETURNED].SetValue(_taskHost, _withReturnValue.ToString());
            DialogResult = DialogResult.OK;
            Close();
        }
        /// <summary>
        /// Prepares method's parameters that will be executed
        /// It will recuperate the direct values
        /// It will make the interpretation of the expressions
        /// It will pass NULL value for REF Or OUT params
        /// </summary>
        /// <param name="vars">The vars.</param>
        /// <param name="variableDispenser">The variable dispenser.</param>
        /// <param name="methodInfo">The method info.</param>
        /// <returns></returns>
        private object[] GetValuedParams(Variables vars, VariableDispenser variableDispenser, MethodInfo methodInfo)
        {
            object[] objects;

            try
            {
                ParameterInfo[] parameterInfos = methodInfo.GetParameters();

                objects = new object[parameterInfos.Length];

                int paramIndex = 0;

                foreach (ParameterInfo parameterInfo in parameterInfos)
                {
                    var mappedParams = MappingParams.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    foreach (string param in mappedParams.Where(param => param.Length > 0).Where(param => param.Split('|')[0].Split('=')[0].Trim() == parameterInfo.Name))
                    {
                        objects[paramIndex] = EvaluateExpression(param.Split('|')[1], variableDispenser);
                        //param.Split('|')[1].Contains("@")
                        //                           ? EvaluateExpression(param.Split('|')[1], variableDispenser)
                        //                           : (!(parameterInfo.ParameterType.IsByRef || parameterInfo.IsOut))
                        //                                 ? vars[param.Split('|')[1].Trim()].Value
                        //                                 : null;

                        paramIndex++;

                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.StackTrace);
            }

            return(objects);
        }
Пример #9
0
        private void btPreview_Click(object sender, EventArgs e)
        {
            var stringBuilder = new StringBuilder();

            string val = (_connections[cmbSQLServer.Text].ConnectionString.Split(';').Where(delegate(string db)
            {
                return(db.Contains("Initial Catalog"));
            })).FirstOrDefault().Split('=')[1];

            switch (tabControl.SelectedTab.Text)
            {
            case Keys.TAB_SQL:

                var sql   = txSQL.Text.Trim();
                var sqlEx = sql;

                if (!Regex.Match(sql.Replace(" ", string.Empty), "selecttop", RegexOptions.IgnoreCase).Success)
                {
                    const string select = "select";
                    const string top    = " top 100 ";

                    if (Regex.Match(sql, select, RegexOptions.IgnoreCase).Success)
                    {
                        sqlEx = sqlEx.Insert(select.Length + 1, top);
                    }
                }

                stringBuilder.Append(string.Format(@"{0}", Regex.Replace(sqlEx, "(\n|\r)+", string.Empty)));
                break;

            case Keys.TAB_SP:
                StringBuilder storedProcParams = new StringBuilder();

                int index = 0;

                var mappingParams = new MappingParams();
                mappingParams.AddRange(from DataGridViewRow row in grdParameters.Rows
                                       select new MappingParam
                {
                    Name  = row.Cells[0].Value.ToString(),
                    Type  = row.Cells[1].Value.ToString(),
                    Value = row.Cells[2].Value.ToString()
                });

                foreach (var param in mappingParams)
                {
                    storedProcParams.Append(string.Format("{0} {1}",
                                                          (index > 0)
                                                                    ? ","
                                                                    : string.Empty,
                                                          (param.Type.ToLower().Contains("char") ||
                                                           param.Type.ToLower().Contains("date") ||
                                                           param.Type.ToLower().Contains("text"))
                                                                     ? string.Format("'{0}'", EvaluateExpression(param.Value, _taskHost.VariableDispenser))
                                                                     : EvaluateExpression(param.Value, _taskHost.VariableDispenser)));
                    index++;
                }

                stringBuilder.Append(string.Format(@"SELECT TOP 100 * FROM OPENROWSET ('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','set fmtonly off exec [{0}].{1} {2}')", val.Trim(), cmbStoredProcedures.Text.Trim(), storedProcParams));
                break;

            case Keys.TAB_VIEW:
                stringBuilder.Append(string.Format(@"SELECT TOP 100 * FROM {0}", cmbViews.Text.Trim()));
                break;

            case Keys.TAB_TABLES:
                stringBuilder.Append(string.Format(@"SELECT TOP 100 * FROM {0}", cmbTables.Text));
                break;
            }

            using (var frmPreview = new frmPreview(EvaluateExpression(_connections[cmbSQLServer.Text].ConnectionString, _taskHost.VariableDispenser).ToString(),
                                                   tabControl.SelectedTab.Text,
                                                   stringBuilder.ToString()))
            {
                frmPreview.ShowDialog();
            }
        }
Пример #10
0
        private void btSave_Click(object sender, EventArgs e)
        {
            if (txMaxErrors.Text.Trim().Length > 0)
            {
                if (!IsNumeric(txMaxErrors.Text))
                {
                    txMaxErrors.Focus();
                    MessageBox.Show("Max. Errors field must be an integer value!");
                    DialogResult = DialogResult.Cancel;
                    return;
                }
            }

            if (txMaxErrors.Text.Trim().Length > 0)
            {
                if (!IsNumeric(txMaxErrors.Text))
                {
                    txPacketSize.Focus();
                    MessageBox.Show("Network packet size field must be an integer value!");
                    DialogResult = DialogResult.Cancel;
                    return;
                }
            }

            if (cmbDestination.Text.Trim().Length == 0)
            {
                cmbDestination.Focus();
                MessageBox.Show("You have to specify a destination!");
                DialogResult = DialogResult.Cancel;
                return;
            }

            _taskHost.Properties[Keys.SQL_SERVER].SetValue(_taskHost, cmbSQLServer.Text);

            _taskHost.Properties[Keys.FORMAT_FILE_CONNECTION].SetValue(_taskHost, optFileFormatConnection.Checked ? Keys.TRUE : Keys.FALSE);
            _taskHost.Properties[Keys.FORMAT_FILE].SetValue(_taskHost, cmbFormatFile.Text);

            _taskHost.Properties[Keys.DESTINATION_FILE_CONNECTION].SetValue(_taskHost, optFileConnection.Checked ? Keys.TRUE : Keys.FALSE);
            _taskHost.Properties[Keys.DESTINATION].SetValue(_taskHost, cmbDestination.Text);

            _taskHost.Properties[Keys.TRUSTED_CONNECTION].SetValue(_taskHost, chkTrustedConnection.Checked ? Keys.TRUE : Keys.FALSE);
            _taskHost.Properties[Keys.SRV_LOGIN].SetValue(_taskHost, !chkTrustedConnection.Checked ? cmbLogin.Text : string.Empty);
            _taskHost.Properties[Keys.SRV_PASSWORD].SetValue(_taskHost, !chkTrustedConnection.Checked ? cmbPassword.Text : string.Empty);

            _taskHost.Properties[Keys.NATIVE_DB_DATATYPE].SetValue(_taskHost, chkNativeDatabase.Checked ? Keys.TRUE : Keys.FALSE);

            _taskHost.Properties[Keys.FIRSTROW].SetValue(_taskHost, txFirstRow.Text.Trim());
            _taskHost.Properties[Keys.LASTROW].SetValue(_taskHost, txLastRow.Text.Trim());

            _taskHost.Properties[Keys.FIELD_TERMINATOR].SetValue(_taskHost, txFieldTerminator.Text.Trim());
            _taskHost.Properties[Keys.ROW_TERMINATOR].SetValue(_taskHost, txRowTerminator.Text.Trim());

            _taskHost.Properties[Keys.ACTIVATE_CMDSHELL].SetValue(_taskHost, chkRightsCMDSHELL.Checked ? Keys.TRUE : Keys.FALSE);

            _taskHost.Properties[Keys.SQL_STATEMENT].SetValue(_taskHost, txSQL.Text.Trim());
            _taskHost.Properties[Keys.SQL_VIEW].SetValue(_taskHost, cmbViews.Text);
            _taskHost.Properties[Keys.SQL_StoredProcedure].SetValue(_taskHost, cmbStoredProcedures.Text);
            _taskHost.Properties[Keys.SQL_TABLE].SetValue(_taskHost, cmbTables.Text);

            _taskHost.Properties[Keys.CODE_PAGE].SetValue(_taskHost, cmbCodePage.Text.Trim());
            _taskHost.Properties[Keys.DATA_SOURCE].SetValue(_taskHost, tabControl.SelectedTab.Text);
            _taskHost.Properties[Keys.NETWORK_PACKET_SIZE].SetValue(_taskHost, txPacketSize.Text.Trim());
            _taskHost.Properties[Keys.USE_REGIONAL_SETTINGS].SetValue(_taskHost, chkRegionalSettings.Checked ? Keys.TRUE : Keys.FALSE);
            _taskHost.Properties[Keys.MAX_ERRORS].SetValue(_taskHost, txMaxErrors.Text.Trim());

            _taskHost.Properties[Keys.SET_QUOTED_IDENTIFIERS_ON].SetValue(_taskHost, chkQuotes.Checked ? Keys.TRUE : Keys.FALSE);
            _taskHost.Properties[Keys.CHARACTER_DATA_TYPE].SetValue(_taskHost, chkChDataType.Checked ? Keys.TRUE : Keys.FALSE);
            _taskHost.Properties[Keys.UNICODE_CHR].SetValue(_taskHost, chkUnicode.Checked ? Keys.TRUE : Keys.FALSE);

            var mappingParams = new MappingParams();

            mappingParams.AddRange(from DataGridViewRow row in grdParameters.Rows
                                   select new MappingParam
            {
                Name  = row.Cells[0].Value.ToString(),
                Type  = row.Cells[1].Value.ToString(),
                Value = row.Cells[2].Value.ToString()
            });

            _taskHost.Properties[Keys.SQL_STORED_PROCEDURE_PARAMS].SetValue(_taskHost, mappingParams);

            _taskHost.Properties[Keys.SEND_FILE_BY_EMAIL].SetValue(_taskHost, chkEmail.Checked
                                                                                    ? Keys.TRUE
                                                                                    : Keys.FALSE);

            string val = (from db in _connections[cmbSQLServer.Text].ConnectionString.Split(';')
                          where db.Contains("Initial Catalog")
                          select db).FirstOrDefault();

            if (val != null)
            {
                _taskHost.Properties[Keys.SQL_DATABASE].SetValue(_taskHost, string.Format("[{0}]", val.Split('=')[1]));
            }

            if (DialogResult == DialogResult.OK)
            {
                Close();
            }
        }
        /// <summary>
        /// This method recupers all needed variable saved in the component property 'MappingParams'
        /// </summary>
        /// <param name="variableDispenser">The variable dispenser.</param>
        private void GetNeededVariables(VariableDispenser variableDispenser)
        {
            List <string> lockForRead = new List <string>();

            try
            {
                //Get variables for Method parameter
                var mappedParams = MappingParams.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string mappedParam in mappedParams)
                {
                    var param = mappedParam.Split('|')[1];
                    try
                    {
                        if (param.Contains("@"))
                        {
                            var regexStr = param.Split('@');

                            foreach (var nexSplitedVal in
                                     regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)))
                            {
                                if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))))
                                {
                                    variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')));
                                }
                            }
                        }
                        //else
                        //    variableDispenser.LockForRead(param);
                    }
                    catch
                    {
                    }
                }

                //Get variables for Configuration File
                if (ConfigurationType == SSISExecuteAssemblyTask100.ConfigurationType.TASK_VARIABLE)
                {
                    var param = ConfigurationFile;

                    if (param.Contains("@"))
                    {
                        var regexStr = param.Split('@');

                        foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)))
                        {
                            if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))))
                            {
                                variableDispenser.LockForRead(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')));
                            }
                        }
                    }
                    else
                    {
                        variableDispenser.LockForRead(param);
                    }
                }

                //Get variable for out put variable // Lock it for "write"
                if (!string.IsNullOrEmpty(OutPutVariable))
                {
                    if (OutPutVariable.Contains("@"))
                    {
                        var regexStr = OutPutVariable.Split('@');

                        foreach (var nexSplitedVal in regexStr.Where(val => val.Trim().Length != 0).Select(strVal => strVal.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries)))
                        {
                            if (!IsVariableInLockForReadOrWrite(lockForRead, nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']'))))
                            {
                                variableDispenser.LockForWrite(nexSplitedVal[1].Remove(nexSplitedVal[1].IndexOf(']')));
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //We will continue...
            }

            variableDispenser.GetVariables(ref _vars);
        }