1 //Copyright 2010 Microsoft Corporation 2 // 3 //Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 4 //You may obtain a copy of the License at 5 // 6 //http://www.apache.org/licenses/LICENSE-2.0 7 // 8 //Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 9 //"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 //See the License for the specific language governing permissions and limitations under the License. 11 12 13 namespace System.Data.Services.Client 14 { 15 using System; 16 17 internal static partial class Error 18 { Argument(string message, string parameterName)19 internal static ArgumentException Argument(string message, string parameterName) 20 { 21 return Trace(new ArgumentException(message, parameterName)); 22 } 23 InvalidOperation(string message)24 internal static InvalidOperationException InvalidOperation(string message) 25 { 26 return Trace(new InvalidOperationException(message)); 27 } 28 InvalidOperation(string message, Exception innerException)29 internal static InvalidOperationException InvalidOperation(string message, Exception innerException) 30 { 31 return Trace(new InvalidOperationException(message, innerException)); 32 } 33 NotSupported(string message)34 internal static NotSupportedException NotSupported(string message) 35 { 36 return Trace(new NotSupportedException(message)); 37 } 38 ThrowObjectDisposed(Type type)39 internal static void ThrowObjectDisposed(Type type) 40 { 41 throw Trace(new ObjectDisposedException(type.ToString())); 42 } 43 44 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801", Justification = "errorCode ignored for code sharing")] HttpHeaderFailure(int errorCode, string message)45 internal static InvalidOperationException HttpHeaderFailure(int errorCode, string message) 46 { 47 return Trace(new InvalidOperationException(message)); 48 } 49 BatchStreamMissingBoundary()50 internal static InvalidOperationException BatchStreamMissingBoundary() 51 { 52 return InvalidOperation(Strings.BatchStream_MissingBoundary); 53 } 54 BatchStreamContentExpected(BatchStreamState state)55 internal static InvalidOperationException BatchStreamContentExpected(BatchStreamState state) 56 { 57 return InvalidOperation(Strings.BatchStream_ContentExpected(state.ToString())); 58 } 59 BatchStreamContentUnexpected(BatchStreamState state)60 internal static InvalidOperationException BatchStreamContentUnexpected(BatchStreamState state) 61 { 62 return InvalidOperation(Strings.BatchStream_ContentUnexpected(state.ToString())); 63 } 64 BatchStreamGetMethodNotSupportInChangeset()65 internal static InvalidOperationException BatchStreamGetMethodNotSupportInChangeset() 66 { 67 return InvalidOperation(Strings.BatchStream_GetMethodNotSupportedInChangeset); 68 } 69 BatchStreamInvalidBatchFormat()70 internal static InvalidOperationException BatchStreamInvalidBatchFormat() 71 { 72 return InvalidOperation(Strings.BatchStream_InvalidBatchFormat); 73 } 74 BatchStreamInvalidDelimiter(string delimiter)75 internal static InvalidOperationException BatchStreamInvalidDelimiter(string delimiter) 76 { 77 return InvalidOperation(Strings.BatchStream_InvalidDelimiter(delimiter)); 78 } 79 BatchStreamMissingEndChangesetDelimiter()80 internal static InvalidOperationException BatchStreamMissingEndChangesetDelimiter() 81 { 82 return InvalidOperation(Strings.BatchStream_MissingEndChangesetDelimiter); 83 } 84 BatchStreamInvalidHeaderValueSpecified(string headerValue)85 internal static InvalidOperationException BatchStreamInvalidHeaderValueSpecified(string headerValue) 86 { 87 return InvalidOperation(Strings.BatchStream_InvalidHeaderValueSpecified(headerValue)); 88 } 89 BatchStreamInvalidContentLengthSpecified(string contentLength)90 internal static InvalidOperationException BatchStreamInvalidContentLengthSpecified(string contentLength) 91 { 92 return InvalidOperation(Strings.BatchStream_InvalidContentLengthSpecified(contentLength)); 93 } 94 BatchStreamOnlyGETOperationsCanBeSpecifiedInBatch()95 internal static InvalidOperationException BatchStreamOnlyGETOperationsCanBeSpecifiedInBatch() 96 { 97 return InvalidOperation(Strings.BatchStream_OnlyGETOperationsCanBeSpecifiedInBatch); 98 } 99 BatchStreamInvalidOperationHeaderSpecified()100 internal static InvalidOperationException BatchStreamInvalidOperationHeaderSpecified() 101 { 102 return InvalidOperation(Strings.BatchStream_InvalidOperationHeaderSpecified); 103 } 104 BatchStreamInvalidHttpMethodName(string methodName)105 internal static InvalidOperationException BatchStreamInvalidHttpMethodName(string methodName) 106 { 107 return InvalidOperation(Strings.BatchStream_InvalidHttpMethodName(methodName)); 108 } 109 BatchStreamMoreDataAfterEndOfBatch()110 internal static InvalidOperationException BatchStreamMoreDataAfterEndOfBatch() 111 { 112 return InvalidOperation(Strings.BatchStream_MoreDataAfterEndOfBatch); 113 } 114 BatchStreamInternalBufferRequestTooSmall()115 internal static InvalidOperationException BatchStreamInternalBufferRequestTooSmall() 116 { 117 return InvalidOperation(Strings.BatchStream_InternalBufferRequestTooSmall); 118 } 119 MethodNotSupported(System.Linq.Expressions.MethodCallExpression m)120 internal static NotSupportedException MethodNotSupported(System.Linq.Expressions.MethodCallExpression m) 121 { 122 return Error.NotSupported(Strings.ALinq_MethodNotSupported(m.Method.Name)); 123 } 124 ThrowBatchUnexpectedContent(InternalError value)125 internal static void ThrowBatchUnexpectedContent(InternalError value) 126 { 127 throw InvalidOperation(Strings.Batch_UnexpectedContent((int)value)); 128 } 129 ThrowBatchExpectedResponse(InternalError value)130 internal static void ThrowBatchExpectedResponse(InternalError value) 131 { 132 throw InvalidOperation(Strings.Batch_ExpectedResponse((int)value)); 133 } 134 BatchStreamInvalidMethodHeaderSpecified(string header)135 internal static InvalidOperationException BatchStreamInvalidMethodHeaderSpecified(string header) 136 { 137 return InvalidOperation(Strings.BatchStream_InvalidMethodHeaderSpecified(header)); 138 } 139 BatchStreamInvalidHttpVersionSpecified(string actualVersion, string expectedVersion)140 internal static InvalidOperationException BatchStreamInvalidHttpVersionSpecified(string actualVersion, string expectedVersion) 141 { 142 return InvalidOperation(Strings.BatchStream_InvalidHttpVersionSpecified(actualVersion, expectedVersion)); 143 } 144 BatchStreamInvalidNumberOfHeadersAtOperationStart(string header1, string header2)145 internal static InvalidOperationException BatchStreamInvalidNumberOfHeadersAtOperationStart(string header1, string header2) 146 { 147 return InvalidOperation(Strings.BatchStream_InvalidNumberOfHeadersAtOperationStart(header1, header2)); 148 } 149 BatchStreamMissingOrInvalidContentEncodingHeader(string headerName, string headerValue)150 internal static InvalidOperationException BatchStreamMissingOrInvalidContentEncodingHeader(string headerName, string headerValue) 151 { 152 return InvalidOperation(Strings.BatchStream_MissingOrInvalidContentEncodingHeader(headerName, headerValue)); 153 } 154 BatchStreamInvalidNumberOfHeadersAtChangeSetStart(string header1, string header2)155 internal static InvalidOperationException BatchStreamInvalidNumberOfHeadersAtChangeSetStart(string header1, string header2) 156 { 157 return InvalidOperation(Strings.BatchStream_InvalidNumberOfHeadersAtChangeSetStart(header1, header2)); 158 } 159 BatchStreamMissingContentTypeHeader(string headerName)160 internal static InvalidOperationException BatchStreamMissingContentTypeHeader(string headerName) 161 { 162 return InvalidOperation(Strings.BatchStream_MissingContentTypeHeader(headerName)); 163 } 164 BatchStreamInvalidContentTypeSpecified(string headerName, string headerValue, string mime1, string mime2)165 internal static InvalidOperationException BatchStreamInvalidContentTypeSpecified(string headerName, string headerValue, string mime1, string mime2) 166 { 167 return InvalidOperation(Strings.BatchStream_InvalidContentTypeSpecified(headerName, headerValue, mime1, mime2)); 168 } 169 InternalError(InternalError value)170 internal static InvalidOperationException InternalError(InternalError value) 171 { 172 return InvalidOperation(Strings.Context_InternalError((int)value)); 173 } 174 ThrowInternalError(InternalError value)175 internal static void ThrowInternalError(InternalError value) 176 { 177 throw InternalError(value); 178 } 179 180 private static T Trace<T>(T exception) where T : Exception 181 { 182 return exception; 183 } 184 } 185 186 internal enum InternalError 187 { 188 UnexpectedXmlNodeTypeWhenReading = 1, 189 UnexpectedXmlNodeTypeWhenSkipping = 2, 190 UnexpectedEndWhenSkipping = 3, 191 UnexpectedReadState = 4, 192 UnexpectedRequestBufferSizeTooSmall = 5, 193 UnvalidatedEntityState = 6, 194 NullResponseStream = 7, 195 EntityNotDeleted = 8, 196 EntityNotAddedState = 9, 197 LinkNotAddedState = 10, 198 EntryNotModified = 11, 199 LinkBadState = 12, 200 UnexpectedBeginChangeSet = 13, 201 UnexpectedBatchState = 14, 202 ChangeResponseMissingContentID = 15, 203 ChangeResponseUnknownContentID = 16, 204 TooManyBatchResponse = 17, 205 206 InvalidEndGetRequestStream = 20, 207 InvalidEndGetRequestCompleted = 21, 208 InvalidEndGetRequestStreamRequest = 22, 209 InvalidEndGetRequestStreamStream = 23, 210 InvalidEndGetRequestStreamContent = 24, 211 InvalidEndGetRequestStreamContentLength = 25, 212 213 InvalidEndWrite = 30, 214 InvalidEndWriteCompleted = 31, 215 InvalidEndWriteRequest = 32, 216 InvalidEndWriteStream = 33, 217 218 InvalidEndGetResponse = 40, 219 InvalidEndGetResponseCompleted = 41, 220 InvalidEndGetResponseRequest = 42, 221 InvalidEndGetResponseResponse = 43, 222 InvalidAsyncResponseStreamCopy = 44, 223 InvalidAsyncResponseStreamCopyBuffer = 45, 224 225 InvalidEndRead = 50, 226 InvalidEndReadCompleted = 51, 227 InvalidEndReadStream = 52, 228 InvalidEndReadCopy = 53, 229 InvalidEndReadBuffer = 54, 230 231 InvalidSaveNextChange = 60, 232 InvalidBeginNextChange = 61, 233 SaveNextChangeIncomplete = 62, 234 235 InvalidGetRequestStream = 70, 236 InvalidGetResponse = 71, 237 } 238 } 239