Esempio n. 1
0
        public string GetValueTest(IDTSVariableDispenser100 variableDispenser)
        {
            switch (Binding)
            {
            case HTTPParamBinding.CustomValue:
                return(CustomValue);

            case HTTPParamBinding.Variable:
                DataType type;
                string   defaultValue = null;
                try
                {
                    defaultValue = Utils.GetVariable(variableDispenser, VariableName, out type).ToString();
                }
                catch (VariableNotFoundException ex) {}

                var p = new UserPrompter("Variable " + VariableName, defaultValue);
                p.ShowDialog();

                return(p.GetValue());

            case HTTPParamBinding.InputField:
                p = new UserPrompter("Variable " + VariableName);
                p.ShowDialog();

                return(p.GetValue());

            default:
                throw new ApplicationException("Unhandled HTTPBinding type.");
            }
        }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="isagCustomProperties">custom properties for the component</param>
 /// <param name="events">Isag events</param>
 /// <param name="componentMetaData">SSIS metadata for the component</param>
 /// <param name="variableDispenser">SSIS variable dispenser</param>
 public TlDbCommand(IsagCustomProperties isagCustomProperties, IsagEvents events,
                    IDTSComponentMetaData100 componentMetaData, IDTSVariableDispenser100 variableDispenser)
 {
     _IsagCustomProperties = isagCustomProperties;
     _events            = events;
     _componentMetaData = componentMetaData;
     _variableDispenser = variableDispenser;
 }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="componentMetaData">SSIS component metadata</param>
 /// <param name="variableDispenser">SSIS variable dispenser</param>
 /// <param name="destinationTableName">destination table name</param>
 /// <param name="customEventTemplate">template for the custom event</param>
 /// <param name="logLEvel">log level</param>
 public IsagEvents(IDTSComponentMetaData100 componentMetaData, IDTSVariableDispenser100 variableDispenser, string destinationTableName, string customEventTemplate, int logLEvel)
 {
     ComponentMetaData    = componentMetaData;
     VariableDispenser    = variableDispenser;
     DestinationTableName = destinationTableName;
     CustomEventValue     = GetCustomEventValue(customEventTemplate);
     _logLevel            = logLEvel;
 }
        /*private static string DownloadJson(Microsoft.SqlServer.Dts.Runtime.VariableDispenser vd, Uri url, string method, IEnumerable<HTTPParameter> pars, string cookievar)
         * {
         *  // Recupera la variabie di cookiecontainer, se specificata
         *  if (String.IsNullOrEmpty(method))
         *      throw new ArgumentException("Invalid method specified.");
         *
         *  method = method.ToUpper();
         *  UriBuilder b = new UriBuilder(url);
         *
         *  List<KeyValuePair<string, string>> postParams = new List<KeyValuePair<string, string>>();
         *
         *  // Componi l'url se sono stati specificati parametri
         *  if ((method == "GET" || method == "DELETE") && pars != null)
         *  {
         *
         *      StringBuilder queryToAppend = new StringBuilder();
         *
         *      // Per ogni parametro, recupera il valore e codificalo se richiesto.
         *      foreach (var param in pars)
         *      {
         *          // Name
         *          if (param.Encode)
         *              queryToAppend.Append(Uri.EscapeUriString(param.Name));
         *          else
         *              queryToAppend.Append(param.Name);
         *          // =
         *          queryToAppend.Append("=");
         *          // Value
         *          string val = null;
         *          if (param.Binding == HTTPParamBinding.CustomValue)
         *              val = param.Value;
         *          else if (param.Binding == HTTPParamBinding.Variable)
         *          {
         *              DataType type;
         *              val = GetVariable(vd, param.Value, out type).ToString();
         *          }
         *
         *          if (param.Encode)
         *              val = Uri.EscapeUriString(val);
         *
         *          queryToAppend.Append(val);
         *
         *          // Next
         *          queryToAppend.Append("&");
         *      }
         *
         *      // L'ultimo carattere va scartatao
         *      if (pars.Count() > 0)
         *          queryToAppend.Remove(queryToAppend.Length - 1, 1);
         *
         *
         *      if (b.Query != null && b.Query.Length > 1)
         *          b.Query = b.Query.Substring(1) + "&" + queryToAppend.ToString();
         *      else
         *          b.Query = queryToAppend.ToString();
         *  }
         *  else if (pars != null)
         *  {
         *      // Costruisci la lista key-value
         *      foreach (var param in pars)
         *      {
         *          // Name
         *          string key = null;
         *          string value = null;
         *
         *          if (param.Encode)
         *              key = Uri.EscapeUriString(param.Name);
         *          else
         *              key = param.Name;
         *
         *          // Value
         *          if (param.Binding == HTTPParamBinding.CustomValue)
         *              value = param.Value;
         *          else if (param.Binding == HTTPParamBinding.Variable)
         *          {
         *              DataType type;
         *              value = GetVariable(vd, param.Value, out type).ToString();
         *          }
         *
         *          if (param.Encode)
         *              value = Uri.EscapeUriString(value);
         *          KeyValuePair<string, string> pair = new KeyValuePair<string, string>(key, value);
         *          postParams.Add(pair);
         *      }
         *  }
         *
         *  CookieContainer cc = null;
         *  if (!String.IsNullOrEmpty(cookievar))
         *  {
         *      DataType type;
         *      cc = GetVariable(vd, cookievar, out type) as CookieContainer;
         *  }
         *  if (cc == null)
         *      cc = new CookieContainer();
         *
         *  string res = DownloadJsonFile(b.Uri, method, postParams, ref cc, null);
         *
         *  // If the cookie container parameter was not null, assign the container to the variable
         *  if (!String.IsNullOrEmpty(cookievar))
         *  {
         *      Microsoft.SqlServer.Dts.Runtime.Variables vars = null;
         *      try
         *      {
         *          vd.LockOneForWrite(cookievar, ref vars);
         *          vars[cookievar].Value = cc;
         *      }
         *      finally
         *      {
         *          if (vars != null)
         *              vars.Unlock();
         *      }
         *
         *  }
         *
         *  return res;
         * }*/

        public static string DownloadJson(IDTSVariableDispenser100 vd, Uri url, string method, Dictionary <string, string> parameters, Dictionary <string, string> headers, CookieContainer cookies, out string computed_url, string customLocalTempDir = null)
        {
            method = method.ToUpper();
            UriBuilder b = new UriBuilder(url);

            // Build the Request URL.
            // GET and DELETE require parameters to be encoded directly into the URL.
            if ((method == "GET" || method == "DELETE") && parameters != null)
            {
                StringBuilder queryToAppend = new StringBuilder();
                foreach (var param in parameters)
                {
                    // Name
                    queryToAppend.Append(param.Key);
                    // =
                    queryToAppend.Append("=");
                    // Value
                    queryToAppend.Append(param.Value);
                    // Next
                    queryToAppend.Append("&");
                }

                // Discard last character
                if (queryToAppend.Length > 0)
                {
                    queryToAppend.Remove(queryToAppend.Length - 1, 1);
                }

                // Handle the case in which query params are mixed: some typed directly into the box and others given by the ad-hoc GUI.
                if (b.Query != null && b.Query.Length > 1)
                {
                    b.Query = b.Query.Substring(1);
                    if (!String.IsNullOrEmpty(queryToAppend.ToString()))
                    {
                        b.Query += "&" + queryToAppend.ToString();
                    }
                }
                else
                {
                    b.Query = queryToAppend.ToString();
                }
            }


            CookieContainer cc = null;

            if (cc == null)
            {
                cc = new CookieContainer();
            }

            string res = DownloadJsonFile(b.Uri, method, parameters, headers, ref cc, customLocalTempDir, out computed_url);

            return(res);
        }
        /// <summary>
        /// Return value of SSIS variable
        /// </summary>
        /// <param name="variableDispenser">SSIS variable dispenser</param>
        /// <param name="variableName">variable name</param>
        /// <returns>variable value</returns>
        public static string GetValueFromVariable(IDTSVariableDispenser100 variableDispenser, string variableName)
        {
            string result;

            IDTSVariables100 var = null;

            variableDispenser.LockOneForRead(variableName, ref var);
            result = var[variableName].Value.ToString();
            var.Unlock();

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// This method should be called at runtime, so that correct value is returned.
        /// </summary>
        /// <param name="variableDispenser"></param>
        /// <param name="inputBuffer"></param>
        /// <param name="inputLane"></param>
        /// <param name="bufferManager"></param>
        /// <returns></returns>
        public string GetValue(IDTSVariableDispenser100 variableDispenser, PipelineBuffer inputBuffer, IDTSInput100 inputLane, IDTSBufferManager100 bufferManager)
        {
            switch (Binding)
            {
            case HTTPParamBinding.CustomValue:
                return(CustomValue);

            case HTTPParamBinding.Variable:
                DataType type;
                return(Utils.GetVariable(variableDispenser, VariableName, out type).ToString());

            case HTTPParamBinding.InputField:
                int colIndex = bufferManager.FindColumnByLineageID(inputLane.Buffer, inputLane.InputColumnCollection[InputColumnName].LineageID);
                return(inputBuffer[colIndex].ToString());

            default:
                throw new ApplicationException("Unhandled HTTPBinding type.");
            }
        }
        public static object GetVariable(IDTSVariableDispenser100 vd, string varname, out DataType vartype)
        {
            object           o    = null;
            IDTSVariables100 vars = null;

            try
            {
                vd.LockOneForRead(varname, ref vars);
                o       = vars[varname].Value;
                vartype = (DataType)vars[varname].DataType;
                return(o);
            }
            finally
            {
                if (vars != null)
                {
                    vars.Unlock();
                }
            }
        }
Esempio n. 8
0
 public void Parse(String bstrExpression, IDTSVariableDispenser100 pVariableDispenser,
     IDTSInputColumnCollection100 pColumnCollection)
 {
     _innerObject.Parse(bstrExpression, pVariableDispenser, pColumnCollection);
 }
Esempio n. 9
0
 public void Instantiate(String bstrUserComponentTypeName, IDTSComponentMetaData100 pComponentMetaData,
     IDTSVariableDispenser100 pVariableDispenser, IDTSBufferManager100 pBufferManager,
     IDTSEventInfos100 pEventInfos, IDTSObjectReferenceTracker100 pRefTracker,
     IDTSLogEntryInfos100 pLogEntryInfos, out DTSProductLevel peProductLevel)
 {
     _innerObject.Instantiate(bstrUserComponentTypeName, pComponentMetaData, pVariableDispenser, pBufferManager,
         pEventInfos, pRefTracker, pLogEntryInfos, out peProductLevel);
 }
        /// <summary>
        /// Replace placeholders in sql statments with variable values
        /// </summary>
        /// <param name="templateTableName">sql statement template</param>
        /// <returnsexecutable sql statementtatement</returns>
        public static string GetTableExpressionFromTemplate(string templateTableName, IDTSVariableDispenser100 variableDispenser, IDTSComponentMetaData100 componentMetaData)
        {
            if (templateTableName == "")
            {
                return("");
            }

            string result = templateTableName;


            try
            {
                if (result != "")
                {
                    while (result.Contains("@("))
                    {
                        string           varName = "";
                        IDTSVariables100 var     = null;
                        int start = result.IndexOf("@(", 0);
                        int end   = result.IndexOf(")", start);

                        varName = result.Substring(start + 2, end - start - 2);

                        variableDispenser.LockOneForRead(varName, ref var);

                        result = result.Replace("@(" + varName + ")", var[varName].Value.ToString());
                        var.Unlock();
                    }
                }
            }
            catch (Exception ex)
            {
                Events.Fire(componentMetaData, Events.Type.Error, string.Format("[{0}]: Variable not found: {1}", "Pre-/PostSql", ex.Message));
            }

            return(result);
        }
Esempio n. 11
0
        public bool Validate(IDTSComponentMetaData100 metadata, IDTSVariableDispenser100 variableDispenser, out string msg)
        {
            msg = null;

            // General checks
            if (FieldName == null)
            {
                msg = "Invalid parameter name. It cannot be null.";
                return(false);
            }

            // Perform binding-dependent checks first.
            switch (Binding)
            {
            // In case it is mapped to an input field, check if that is available.
            case HTTPParamBinding.InputField:

                if (InputColumnName == null)
                {
                    msg = "Unspecified binding column name for http parameter " + FieldName;
                    return(false);
                }

                bool found = false;
                foreach (IDTSInputColumn100 inputcol in metadata.InputCollection[ComponentConstants.NAME_INPUT_LANE_PARAMS].InputColumnCollection)
                {
                    if (inputcol.Name == InputColumnName)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    msg = "Invalid HTTP parameter binding. Column " + InputColumnName + " is not available.";
                    return(false);
                }
                break;

            // When depending on a variable, check the variable exists
            case HTTPParamBinding.Variable:
                DataType type;

                if (VariableName == null)
                {
                    msg = "Unspecified binding variable name for http parameter " + FieldName;
                    return(false);
                }

                try
                {
                    Utils.GetVariable(variableDispenser, VariableName, out type).ToString();
                }
                catch (VariableNotFoundException ex) {
                    msg = "Invalid HTTP parameter binding. Variable " + VariableName + " is not defined.";
                    return(false);
                }

                break;

            case HTTPParamBinding.CustomValue:
                if (CustomValue == null)
                {
                    msg = "Unspecified Custom vlue binding for http parameter " + FieldName + ".";
                    return(false);
                }
                break;

            default:
                // This should bever happen.
                throw new ApplicationException("Invalid/unhandled HTTP binding type. Contact the developer.");
            }

            msg = null;
            return(true);
        }