public sealed override void WriteValue(string parameterName, object parameterValue) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference expectedTypeReference = this.VerifyCanWriteValueParameter(true, parameterName, parameterValue); this.InterceptException(() => this.WriteValueImplementation(parameterName, parameterValue, expectedTypeReference)); }
public sealed override ODataCollectionWriter CreateCollectionWriter(string parameterName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference itemTypeReference = this.VerifyCanCreateCollectionWriter(true, parameterName); return(this.InterceptException <ODataCollectionWriter>(() => this.CreateCollectionWriterImplementation(parameterName, itemTypeReference))); }
public sealed override Task <ODataCollectionWriter> CreateCollectionWriterAsync(string parameterName) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(parameterName, "parameterName"); IEdmTypeReference itemTypeReference = this.VerifyCanCreateCollectionWriter(false, parameterName); return(TaskUtils.GetTaskForSynchronousOperation <ODataCollectionWriter>(() => this.InterceptException <ODataCollectionWriter>(() => this.CreateCollectionWriterImplementation(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> /// Converts the version string into the internal enum. /// </summary> /// <param name="version"> The string to convert into a <see cref="ODataVersion"/>.</param> /// <returns>A <see cref="ODataVersion"/> representation of the version string.</returns> 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 Version1NumberString: return(ODataVersion.V1); case Version2NumberString: return(ODataVersion.V2); case Version3NumberString: return(ODataVersion.V3); default: // invalid version string throw new ODataException(Strings.ODataUtils_UnsupportedVersionHeader(version)); } }
internal static void ValidateHttpMethod(string httpMethodString) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(httpMethodString, "httpMethodString"); if ((((string.CompareOrdinal(httpMethodString, "GET") != 0) && (string.CompareOrdinal(httpMethodString, "DELETE") != 0)) && ((string.CompareOrdinal(httpMethodString, "MERGE") != 0) && (string.CompareOrdinal(httpMethodString, "PATCH") != 0))) && ((string.CompareOrdinal(httpMethodString, "POST") != 0) && (string.CompareOrdinal(httpMethodString, "PUT") != 0))) { throw new ODataException(Strings.HttpUtils_InvalidHttpMethodString(httpMethodString)); } }
/// <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) { DebugUtils.CheckNoExternalCallers(); ExceptionUtils.CheckArgumentStringNotNullOrEmpty(httpMethodString, "httpMethodString"); if (string.CompareOrdinal(httpMethodString, ODataConstants.MethodGet) != 0 && string.CompareOrdinal(httpMethodString, ODataConstants.MethodDelete) != 0 && string.CompareOrdinal(httpMethodString, ODataConstants.MethodMerge) != 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) { DebugUtils.CheckNoExternalCallers(); 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) { DebugUtils.CheckNoExternalCallers(); 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)); } } }
private void VerifyCanCreateOperationRequestMessage(bool synchronousCall, string method, Uri uri) { this.ValidateWriterReady(); this.VerifyCallAllowed(synchronousCall); if (this.rawOutputContext.WritingResponse) { this.ThrowODataException(Strings.ODataBatchWriter_CannotCreateRequestOperationWhenWritingResponse); } ExceptionUtils.CheckArgumentStringNotNullOrEmpty(method, "method"); if (this.changeSetBoundary == null) { if (string.CompareOrdinal(method, "GET") != 0) { this.ThrowODataException(Strings.ODataBatch_InvalidHttpMethodForQueryOperation(method)); } } else if (string.CompareOrdinal(method, "GET") == 0) { this.ThrowODataException(Strings.ODataBatch_InvalidHttpMethodForChangeSetRequest(method)); } ExceptionUtils.CheckArgumentNotNull <Uri>(uri, "uri"); }
/// <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) { DebugUtils.CheckNoExternalCallers(); 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); } }
public static ODataVersion StringToODataVersion(string version) { string str = version; ExceptionUtils.CheckArgumentStringNotNullOrEmpty(version, "version"); int index = str.IndexOf(';'); if (index >= 0) { str = str.Substring(0, index); } switch (str.Trim()) { case "1.0": return(ODataVersion.V1); case "2.0": return(ODataVersion.V2); case "3.0": return(ODataVersion.V3); } throw new ODataException(Microsoft.Data.OData.Strings.ODataUtils_UnsupportedVersionHeader(version)); }
/// <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) { DebugUtils.CheckNoExternalCallers(); ExceptionUtils.CheckArgumentStringNotNullOrEmpty(annotationName, "annotationName"); return(false); }