示例#1
0
文件: Adapters.cs 项目: sotaria/gsf
        /// <summary>
        /// Handles PropertyChanged event on <see cref="SelectedParameter"/>.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">Event arguments.</param>
        protected virtual void ConnectionStringParameter_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            AdapterConnectionStringParameter parameter = sender as AdapterConnectionStringParameter;
            Dictionary <string, string>      settings;

            if (!m_suppressConnectionStringUpdates && (object)parameter != null && (object)parameter.Value != null && e.PropertyName == "Value")
            {
                try
                {
                    m_suppressParameterValueUpdates = true;

                    // The easiest way to update is to break the connection string into key
                    // value pairs, update the value of the pair corresponding to the parameter
                    // that fired the event, and then rejoin the key value pairs.
                    settings = CurrentItem.ConnectionString.ToNonNullString().ParseKeyValuePairs();
                    settings[parameter.Name] = parameter.Value.ToString();

                    // Build the new connection string and validate that it can still be parsed
                    string connectionString = settings.JoinKeyValuePairs();
                    connectionString.ParseKeyValuePairs();

                    CurrentItem.ConnectionString = connectionString;
                }
                finally
                {
                    m_suppressParameterValueUpdates = false;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Retrieves an existing parameter from the <see cref="ParameterList"/>. If no
        /// parameter exists with a name that matches the given <see cref="MemberInfo.Name"/>,
        /// then a new one is created. There is also a special case in which the parameter is
        /// already defined, but no <see cref="PropertyInfo"/> exists for it. In that case,
        /// the property info is added, as well as any other new information, and the parameter
        /// is returned.
        /// </summary>
        /// <param name="info">The property info that defines the connection string parameter.</param>
        /// <returns>The parameter defined by the given property info.</returns>
        private AdapterConnectionStringParameter GetParameter(PropertyInfo info)
        {
            DefaultValueAttribute            defaultValueAttribute;
            DescriptionAttribute             descriptionAttribute;
            AdapterConnectionStringParameter parameter = null;

            bool   isRequired   = false;
            object defaultValue = null;
            string description  = null;

            if (m_parameterList != null)
            {
                parameter = m_parameterList.SingleOrDefault(param => param.Name.Equals(info.Name, StringComparison.CurrentCultureIgnoreCase));
            }

            // These are different cases, but we need to extract the description
            // and default value in both. In cases where we already know this
            // information, we can skip this step.
            if (parameter == null || parameter.Info == null)
            {
                isRequired   = !info.TryGetAttribute(out defaultValueAttribute);
                defaultValue = isRequired ? null : defaultValueAttribute.Value;
                description  = info.TryGetAttribute(out descriptionAttribute) ? descriptionAttribute.Description : string.Empty;
            }

            if (parameter == null)
            {
                // Create a brand new parameter to be returned.
                parameter = new AdapterConnectionStringParameter
                {
                    Info         = info,
                    Name         = info.Name,
                    Description  = description,
                    Value        = null,
                    DefaultValue = defaultValue,
                    IsRequired   = isRequired
                };
            }
            else if (parameter.Info == null)
            {
                // Update the existing parameter with newly obtained information.
                parameter.Info         = info;
                parameter.Description  = description;
                parameter.DefaultValue = defaultValue;
            }

            return(parameter);
        }
示例#3
0
        /// <summary>
        /// Retrieves an existing parameter from the <see cref="ParameterList"/>. If no
        /// parameter exists with a name that matches the one given, then a new one is created.
        /// </summary>
        /// <param name="name">The name of the parameter to be retrieved or created.</param>
        /// <returns>The parameter with the given name.</returns>
        private AdapterConnectionStringParameter GetParameter(string name)
        {
            AdapterConnectionStringParameter parameter = null;

            if (m_parameterList != null)
            {
                parameter = m_parameterList.SingleOrDefault(param => param.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
            }

            if ((object)parameter == null)
            {
                parameter = new AdapterConnectionStringParameter()
                {
                    Name         = name,
                    DefaultValue = string.Empty,
                    IsRequired   = false
                };
            }

            return(parameter);
        }