Ejemplo n.º 1
0
 public void AddAttrParameter(RouteAttrInfo info)
 {
     Debug.Assert(info != null);
     _userParams.Add(info);
 }
Ejemplo n.º 2
0
        public void SetNetworkAttributeParameterValue(string attrName,
            string paramName,
            object paramValue)
        {
            Debug.Assert(attrName != null);
            Debug.Assert(paramName != null);

            // find parameter in network description
            NetworkAttributeParameter param = null;
            if (!_FindParamInNetworkDesc(attrName, paramName, out param))
            {
                // cannot find attribute
                throw new ArgumentException(
                    Properties.Messages.Error_InvalidNetworkAttr);
            }

            string serializedValue = String.Empty;

            if (paramValue != null)
            {
                // If new value is not empty string or if parameter doesnt accept empty string -
                // try to serialize current value.
                if (paramValue as string != string.Empty || !param.IsEmptyStringValid)
                {
                    object convertedValue = paramValue;

                    // check if value type is correct
                    if (!param.Type.Equals(paramValue.GetType()))
                    {
                        if (!_ConvertParamValue(paramValue, param.Type, out convertedValue))
                        {
                            // provided value cannot be converted to required type
                            throw new ArgumentException(
                                Properties.Messages.Error_InvalidNetworkParamType);
                        }
                    }

                    // serialize value for storing
                    serializedValue = _SerializeParamValue(convertedValue);
                }
            }

            // try to find attribute in settings
            RouteAttrInfo attrInfo = _settings.GetUserAttrParameter(attrName, paramName);
            if (attrInfo != null)
            {
                // update existing attribute entry
                attrInfo.Value = serializedValue;
            }
            else
            {
                // add new attribute entry
                attrInfo = new RouteAttrInfo();
                attrInfo.AttrName = attrName;
                attrInfo.ParamName = paramName;
                attrInfo.Value = serializedValue;
                _settings.AddAttrParameter(attrInfo);
            }
        }