/// <summary>Displays a string to OData version representation.</summary> /// <returns>The OData version.</returns> /// <param name="version">The OData version.</param> public static ODataVersion StringToODataVersion(string version) { // don't want to edit the string later. string modifiedVersion = version; // version must not be null or empty ExceptionUtils.CheckArgumentStringNotNullOrEmpty(version, "version"); // removes the ";" and the user agent string from the version. int ix = modifiedVersion.IndexOf(';'); if (ix >= 0) { modifiedVersion = modifiedVersion.Substring(0, ix); } switch (modifiedVersion.Trim()) { case Version4NumberString: return(ODataVersion.V4); case Version401NumberString: return(ODataVersion.V401); default: // invalid version string throw new ODataException(Strings.ODataUtils_UnsupportedVersionHeader(version)); } }
/// <summary> Creates an <see cref="T:Microsoft.OData.ODataWriter" /> to write a resource set. </summary> /// <param name="parameterName">The name of the parameter to write.</param> /// <returns>The created writer.</returns> public sealed override ODataWriter CreateResourceSetWriter(string parameterName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference itemTypeReference = this.VerifyCanCreateResourceSetWriter(true /*synchronousCall*/, parameterName); return(this.InterceptException(() => this.CreateResourceSetWriterImplementation(parameterName, itemTypeReference))); }
/// <summary> /// Asynchronously start writing a value parameter. /// </summary> /// <param name="parameterName">The name of the parameter to write.</param> /// <param name="parameterValue">The value of the parameter to write.</param> /// <returns>A task instance that represents the asynchronous write operation.</returns> public sealed override Task WriteValueAsync(string parameterName, object parameterValue) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference expectedTypeReference = this.VerifyCanWriteValueParameter(false /*synchronousCall*/, parameterName, parameterValue); return(TaskUtils.GetTaskForSynchronousOperation(() => this.InterceptException(() => this.WriteValueImplementation(parameterName, parameterValue, expectedTypeReference)))); }
/// <summary> /// Start writing a value parameter. /// </summary> /// <param name="parameterName">The name of the parameter to write.</param> /// <param name="parameterValue">The value of the parameter to write (null/ODataEnumValue/primitiveClrValue).</param> public sealed override void WriteValue(string parameterName, object parameterValue) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference expectedTypeReference = this.VerifyCanWriteValueParameter(true /*synchronousCall*/, parameterName, parameterValue); this.InterceptException(() => this.WriteValueImplementation(parameterName, parameterValue, expectedTypeReference)); }
/// <summary>Asynchronously creates an <see cref="T:Microsoft.OData.ODataWriter" /> to write a resource.</summary> /// <param name="parameterName">The name of the parameter to write.</param> /// <returns>The asynchronously created <see cref="T:Microsoft.OData.ODataWriter" />.</returns> public sealed override Task <ODataWriter> CreateResourceWriterAsync(string parameterName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference itemTypeReference = this.VerifyCanCreateResourceWriter(false /*synchronousCall*/, parameterName); return(TaskUtils.GetTaskForSynchronousOperation( () => this.InterceptException(() => this.CreateResourceWriterImplementation(parameterName, itemTypeReference)))); }
/// <summary> /// Validates that the HTTP method string matches one of the supported HTTP methods. /// </summary> /// <param name="httpMethodString">The HTTP method string to validate.</param> internal static void ValidateHttpMethod(string httpMethodString) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(httpMethodString, "httpMethodString"); if (string.CompareOrdinal(httpMethodString, ODataConstants.MethodGet) != 0 && string.CompareOrdinal(httpMethodString, ODataConstants.MethodDelete) != 0 && string.CompareOrdinal(httpMethodString, ODataConstants.MethodPatch) != 0 && string.CompareOrdinal(httpMethodString, ODataConstants.MethodPost) != 0 && string.CompareOrdinal(httpMethodString, ODataConstants.MethodPut) != 0) { throw new ODataException(Strings.HttpUtils_InvalidHttpMethodString(httpMethodString)); } }
/// <summary> /// Constructs a new <see cref="ODataInstanceAnnotation"/> instance. /// </summary> /// <param name="annotationName">The name of the instance annotation.</param> /// <param name="annotationValue">The value of the instance annotation.</param> /// <param name="isCustomAnnotation">If the name is not for built-in OData annotation.</param> internal ODataInstanceAnnotation(string annotationName, ODataValue annotationValue, bool isCustomAnnotation) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(annotationName, "annotationName"); if (!isCustomAnnotation && ODataAnnotationNames.IsODataAnnotationName(annotationName)) { // isCustomAnnotation==true includes '@odata.<unknown name>', which won't cause the below exception. throw new ArgumentException(Strings.ODataInstanceAnnotation_ReservedNamesNotAllowed(annotationName, JsonLightConstants.ODataAnnotationNamespacePrefix)); } ValidateName(annotationName); ValidateValue(annotationValue); this.Name = annotationName; this.Value = annotationValue; }
/// <summary> /// Returns true to indicate that the annotation with the name <paramref name="annotationName"/> should be read, false otherwise. /// </summary> /// <param name="annotationName">The name of the annotation in question.</param> /// <returns>Returns true to indicate that the annotation with the name <paramref name="annotationName"/> should be read, false otherwise.</returns> internal virtual bool Matches(string annotationName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(annotationName, "annotationName"); // Find the highest priority pattern that maches and return true only if that pattern is not exclude. foreach (AnnotationFilterPattern pattern in this.prioritizedPatternsToMatch) { if (pattern.Matches(annotationName)) { return(!pattern.IsExclude); } } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="HttpHeaderValueElement"/> class. /// </summary> /// <param name="name">The name of the preference.</param> /// <param name="value">The value of the preference.</param> /// <param name="parameters">The enumeration of preference parameter key value pairs.</param> public HttpHeaderValueElement(string name, string value, IEnumerable <KeyValuePair <string, string> > parameters) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(name, "name"); ExceptionUtils.CheckArgumentNotNull(parameters, "parameters"); this.Name = name; this.Value = value; this.Parameters = parameters; #if DEBUG AssertToken(this.Name); AssertTokenOrQuotedString(this.Value); foreach (KeyValuePair <string, string> kvp in this.Parameters) { AssertToken(kvp.Key); AssertTokenOrQuotedString(kvp.Value); } #endif }
/// <summary> /// Validates the pattern. /// </summary> /// <param name="pattern">The pattern to validate.</param> private static void ValidatePattern(string pattern) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(pattern, "pattern"); string patternWithoutMinusSign = pattern; RemoveExcludeOperator(ref patternWithoutMinusSign); if (patternWithoutMinusSign == WildCard) { return; } string[] segments = patternWithoutMinusSign.Split(NamespaceSeparator); int segmentCount = segments.Length; if (segmentCount == 1) { throw new ArgumentException(Strings.AnnotationFilterPattern_InvalidPatternMissingDot(pattern)); } for (int idx = 0; idx < segmentCount; idx++) { string currentSegment = segments[idx]; if (string.IsNullOrEmpty(currentSegment)) { throw new ArgumentException(Strings.AnnotationFilterPattern_InvalidPatternEmptySegment(pattern)); } if (currentSegment != WildCard && currentSegment.Contains(WildCard)) { throw new ArgumentException(Strings.AnnotationFilterPattern_InvalidPatternWildCardInSegment(pattern)); } bool isLastSegment = idx + 1 == segmentCount; if (currentSegment == WildCard && !isLastSegment) { throw new ArgumentException(Strings.AnnotationFilterPattern_InvalidPatternWildCardMustBeInLastSegment(pattern)); } } }
/// <summary> /// Returns true to indicate that the annotation with the name <paramref name="annotationName"/> should be read, false otherwise. /// </summary> /// <param name="annotationName">The name of the annotation in question.</param> /// <returns>Returns true to indicate that the annotation with the name <paramref name="annotationName"/> should be read, false otherwise.</returns> internal override bool Matches(string annotationName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(annotationName, "annotationName"); return(false); }