/// <summary> /// Validate the version parameter value is valid. /// </summary> /// <param name="parameterValue">version parameter value as specified in the .svcmap file.</param> /// <returns>instance of DataServiceCodeVersion, which contains the value of the version parameter as specified in the svcmap file.</returns> private static void ValidateVersionParameter(ref DataServiceCodeVersion?version, string parameterValue) { if (version == null) { if (parameterValue == Version1Dot0) { version = DataServiceCodeVersion.V1; } else if (parameterValue == Version2Dot0) { version = DataServiceCodeVersion.V2; } else { throw new ArgumentException( Strings.InvalidVersionParameterValue( parameterValue, VersionParameterName, String.Format(CultureInfo.InvariantCulture, "'{0}', '{1}'", Version1Dot0, Version2Dot0))); } } else { throw new ArgumentException(Strings.ParameterSpecifiedMultipleTimes(VersionParameterName)); } }
static internal DataServiceCodeVersion CheckDataServiceCodeVersionArgument(DataServiceCodeVersion value, string paramName) { if (value == DataServiceCodeVersion.V1 || value == DataServiceCodeVersion.V2) { return(value); } throw Error.ArgumentOutOfRange(paramName); }
/// <summary> /// Validate the parameters list in the map file. Currently only EnableDataBinding parameter is supported. /// </summary> /// <param name="document">instance of xml documents which contains the map file.</param> /// <returns>returns true if the data binding parameter is specified and its value is true, otherwise returns false.</returns> private static void ValidateParametersInMapFile(XmlDocument document, out DataServiceCodeVersion version, out bool useDataServiceCollection) { bool isSentinalTypePresent = BuildManager.GetType("System.Data.Services.Client.DataServiceCollection`1", false /*throwOnError*/) != null; // Validate all the parameters specified in the map file XmlNodeList parameters = document.SelectNodes("/ds:ReferenceGroup/ds:Parameters/ds:Parameter", NamespaceManager); bool? useCollectionParamValue = null; DataServiceCodeVersion?versionParamValue = null; if (parameters != null && parameters.Count != 0) { // currently only one parameter can be specified. EnableDataBinding - whose valid values are 'true and 'false' foreach (XmlNode p in parameters) { // Name and value attributes must be present, since they are verified by the xsd XmlAttribute nameAttribute = p.Attributes["Name"]; XmlAttribute valueAttribute = p.Attributes["Value"]; if (nameAttribute.Value == VersionParameterName) { ValidateVersionParameter(ref versionParamValue, valueAttribute.Value); } else if (nameAttribute.Value == UseCollectionParameterName) { ValidateBooleanParameter(ref useCollectionParamValue, valueAttribute.Value, UseCollectionParameterName); } else { throw new ArgumentException( Strings.InvalidParameterName( nameAttribute.Value, String.Format(CultureInfo.InvariantCulture, "'{0}', '{1}'", VersionParameterName, UseCollectionParameterName))); } } } if (!isSentinalTypePresent && useCollectionParamValue.HasValue && useCollectionParamValue == true) { throw new ArgumentException(Strings.UseDataServiceCollectionCannotBeSetToTrue(UseCollectionParameterName)); } version = versionParamValue.HasValue ? versionParamValue.Value : DataServiceCodeVersion.V1; useDataServiceCollection = useCollectionParamValue.HasValue ? useCollectionParamValue.Value : false; }
private IList <EdmSchemaError> GenerateCode(XmlReader sourceReader, LazyTextWriterCreator target, string namespacePrefix) { List <XmlReader> readers = CreateReaders(sourceReader); List <EdmSchemaError> errors = new List <EdmSchemaError>(); EdmItemCollection itemCollection = new EdmItemCollection(readers); #if QFE_ENV _version = _versionExplicitlySet ? _version : GetDataServiceCodeVersionFromEnvironment(); _useDataServiceCollection = _useDataServiceCollectionExplicitlySet ? _useDataServiceCollection : GetUseDataServiceCollectionFromEnvironment(); #endif if (_useDataServiceCollection && _version == DataServiceCodeVersion.V1) { throw new InvalidOperationException(Strings.VersionV1RequiresUseDataServiceCollectionFalse); } // generate code using (ClientApiGenerator generator = new ClientApiGenerator(null, itemCollection, this, errors, namespacePrefix)) { generator.GenerateCode(target); } return(errors); }
/// <summary> /// Validate the version parameter value is valid. /// </summary> /// <param name="parameterValue">version parameter value as specified in the .svcmap file.</param> /// <returns>instance of DataServiceCodeVersion, which contains the value of the version parameter as specified in the svcmap file.</returns> private static void ValidateVersionParameter(ref DataServiceCodeVersion? version, string parameterValue) { if (version == null) { if (parameterValue == Version1Dot0) { version = DataServiceCodeVersion.V1; } else if (parameterValue == Version2Dot0) { version = DataServiceCodeVersion.V2; } else { throw new ArgumentException( Strings.InvalidVersionParameterValue( parameterValue, VersionParameterName, String.Format(CultureInfo.InvariantCulture, "'{0}', '{1}'", Version1Dot0, Version2Dot0))); } } else { throw new ArgumentException(Strings.ParameterSpecifiedMultipleTimes(VersionParameterName)); } }
/// <summary> /// Validate the parameters list in the map file. Currently only EnableDataBinding parameter is supported. /// </summary> /// <param name="document">instance of xml documents which contains the map file.</param> /// <returns>returns true if the data binding parameter is specified and its value is true, otherwise returns false.</returns> private static void ValidateParametersInMapFile(XmlDocument document, out DataServiceCodeVersion version, out bool useDataServiceCollection) { bool isSentinalTypePresent = BuildManager.GetType("System.Data.Services.Client.DataServiceCollection`1", false /*throwOnError*/) != null; // Validate all the parameters specified in the map file XmlNodeList parameters = document.SelectNodes("/ds:ReferenceGroup/ds:Parameters/ds:Parameter", NamespaceManager); bool? useCollectionParamValue = null; DataServiceCodeVersion? versionParamValue = null; if (parameters != null && parameters.Count != 0) { // currently only one parameter can be specified. EnableDataBinding - whose valid values are 'true and 'false' foreach (XmlNode p in parameters) { // Name and value attributes must be present, since they are verified by the xsd XmlAttribute nameAttribute = p.Attributes["Name"]; XmlAttribute valueAttribute = p.Attributes["Value"]; if (nameAttribute.Value == VersionParameterName) { ValidateVersionParameter(ref versionParamValue, valueAttribute.Value); } else if (nameAttribute.Value == UseCollectionParameterName) { ValidateBooleanParameter(ref useCollectionParamValue, valueAttribute.Value, UseCollectionParameterName); } else { throw new ArgumentException( Strings.InvalidParameterName( nameAttribute.Value, String.Format(CultureInfo.InvariantCulture, "'{0}', '{1}'", VersionParameterName, UseCollectionParameterName))); } } } if (!isSentinalTypePresent && useCollectionParamValue.HasValue && useCollectionParamValue == true) { throw new ArgumentException(Strings.UseDataServiceCollectionCannotBeSetToTrue(UseCollectionParameterName)); } version = versionParamValue.HasValue ? versionParamValue.Value : DataServiceCodeVersion.V1; useDataServiceCollection = useCollectionParamValue.HasValue ? useCollectionParamValue.Value : false; }