コード例 #1
0
        private bool _FindParamInNetworkDesc(string attrName, string paramName,
                                             out NetworkAttributeParameter attrParameter)
        {
            Debug.Assert(attrName != null);
            Debug.Assert(paramName != null);

            attrParameter = null;

            bool found = false;

            foreach (NetworkAttribute attr in _netDesc.NetworkAttributes)
            {
                if (attr.Name.Equals(attrName, StringComparison.InvariantCultureIgnoreCase))
                {
                    foreach (NetworkAttributeParameter param in attr.Parameters)
                    {
                        if (param.Name.Equals(paramName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            attrParameter = param;
                            found         = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }
            }

            return(found);
        }
コード例 #2
0
        private void _InitAttrParameters(SolveInfoWrap settings)
        {
            Debug.Assert(settings != null);

            foreach (RouteAttrInfo attr in settings.AttrParameters)
            {
                bool isValid = false;

                // check if attribute settings are valid
                if (!String.IsNullOrEmpty(attr.AttrName) &&
                    !String.IsNullOrEmpty(attr.ParamName) &&
                    attr.Value != null)
                {
                    // find parameter in network description
                    NetworkAttributeParameter param = null;
                    if (_FindParamInNetworkDesc(attr.AttrName, attr.ParamName, out param))
                    {
                        // check if parameter value is valid
                        if (_IsParamValueValid(attr.Value, param.Type))
                        {
                            isValid = true;
                        }
                    }
                }

                if (!isValid)
                {
                    Logger.Warning(String.Format(LOG_INVALID_NETWORK_ATTR,
                                                 attr.AttrName,
                                                 attr.ParamName));
                }
            }
        }
コード例 #3
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public bool GetNetworkAttributeParameterValue(string attrName,
                                                      string paramName,
                                                      out object paramValue)
        {
            Debug.Assert(attrName != null);
            Debug.Assert(paramName != null);

            paramValue = null;
            bool res = false;

            // find parameter in network description
            NetworkAttributeParameter param = null;

            if (_FindParamInNetworkDesc(attrName, paramName, out param))
            {
                // try to get value from attribute settings
                RouteAttrInfo attrInfo = _settings.GetAttrParameter(attrName, paramName);
                if (attrInfo != null)
                {
                    if (_DeserializeParamValue(attrInfo.Value, param.Type, out paramValue))
                    {
                        res = true;
                    }
                }
                else
                {
                    // get default value from network description
                    paramValue = param.DefaultValue;
                    res        = true;
                }
            }

            return(res);
        }
コード例 #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="vrpAttributeName">VRP attribute name.</param>
 /// <param name="routingAttributeName">Routing attribute name.</param>
 /// <param name="unit">Network attribute unit.</param>
 /// <param name="usageType">Network attribute usage type.</param>
 /// <param name="parameters">Collection of network attribute parameters.</param>
 public NetworkAttribute(string vrpAttributeName, string routingAttributeName,
                         NetworkAttributeUnits unit, NetworkAttributeUsageType usageType,
                         ICollection <NetworkAttributeParameter> parameters,
                         NetworkAttributeParameter usageParameter)
 {
     _name                      = vrpAttributeName;
     this.RoutingName           = routingAttributeName;
     _unit                      = unit;
     _usageType                 = usageType;
     _parameters                = parameters;
     _restrictionUsageParameter = usageParameter;
 }
コード例 #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="vrpAttributeName">VRP attribute name.</param>
 /// <param name="routingAttributeName">Routing attribute name.</param>
 /// <param name="unit">Network attribute unit.</param>
 /// <param name="usageType">Network attribute usage type.</param>
 /// <param name="parameters">Collection of network attribute parameters.</param>
 public NetworkAttribute(string vrpAttributeName, string routingAttributeName,
     NetworkAttributeUnits unit, NetworkAttributeUsageType usageType,
     ICollection<NetworkAttributeParameter> parameters,
     NetworkAttributeParameter usageParameter)
 {
     _name = vrpAttributeName;
     this.RoutingName = routingAttributeName;
     _unit = unit;
     _usageType = usageType;
     _parameters = parameters;
     _restrictionUsageParameter = usageParameter;
 }
コード例 #6
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);
            }
        }
コード例 #7
0
        private bool _FindParamInNetworkDesc(string attrName, string paramName,
            out NetworkAttributeParameter attrParameter)
        {
            Debug.Assert(attrName != null);
            Debug.Assert(paramName != null);

            attrParameter = null;

            bool found = false;
            foreach (NetworkAttribute attr in _netDesc.NetworkAttributes)
            {
                if (attr.Name.Equals(attrName, StringComparison.InvariantCultureIgnoreCase))
                {
                    foreach (NetworkAttributeParameter param in attr.Parameters)
                    {
                        if (param.Name.Equals(paramName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            attrParameter = param;
                            found = true;
                            break;
                        }
                    }

                    if (found)
                        break;
                }
            }

            return found;
        }