/// <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> /// Creates an <see cref="ODataCollectionWriter"/> to write the value of a collection parameter. /// </summary> /// <param name="parameterName">The name of the collection parameter to write.</param> /// <returns>The newly created <see cref="ODataCollectionWriter"/>.</returns> public sealed override ODataCollectionWriter CreateCollectionWriter(string parameterName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference itemTypeReference = this.VerifyCanCreateCollectionWriter(true /*synchronousCall*/, parameterName); return(this.InterceptException(() => this.CreateCollectionWriterImplementation(parameterName, itemTypeReference))); }
/// <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); default: // invalid version string throw new ODataException(Strings.ODataUtils_UnsupportedVersionHeader(version)); } }
/// <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/ODataComplexValue/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.Core.ODataWriter" /> to write a feed.</summary> /// <param name="parameterName">The name of the parameter to write.</param> /// <returns>The asynchronously created <see cref="T:Microsoft.OData.Core.ODataWriter" />.</returns> public sealed override Task <ODataWriter> CreateFeedWriterAsync(string parameterName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference itemTypeReference = this.VerifyCanCreateFeedWriter(false /*synchronousCall*/, parameterName); return(TaskUtils.GetTaskForSynchronousOperation( () => this.InterceptException(() => this.CreateFeedWriterImplementation(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> /// 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> /// Internal constructor to create a new instance of <see cref="HttpHeaderValueElement"/>. /// </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> /// Validates that the given <paramref name="name"/> is a valid instance annotation name. /// </summary> /// <param name="name">Name to validate.</param> internal static void ValidateName(string name) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(name, "name"); if (name.IndexOf('.') < 0 || name[0] == '.' || name[name.Length - 1] == '.') { throw new ArgumentException(Strings.ODataInstanceAnnotation_NeedPeriodInName(name)); } if (ODataAnnotationNames.IsODataAnnotationName(name)) { throw new ArgumentException(Strings.ODataInstanceAnnotation_ReservedNamesNotAllowed(name, JsonLightConstants.ODataAnnotationNamespacePrefix)); } try { XmlConvert.VerifyNCName(name); } catch (XmlException e) { throw new ArgumentException(Strings.ODataInstanceAnnotation_BadTermName(name), e); } }
/// <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); }