本文整理汇总了C#中ODataPayloadKind类的典型用法代码示例。如果您正苦于以下问题:C# ODataPayloadKind类的具体用法?C# ODataPayloadKind怎么用?C# ODataPayloadKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataPayloadKind类属于命名空间,在下文中一共展示了ODataPayloadKind类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
/// <summary>
/// Creates a context URI parser and parses the context URI read from the payload.
/// </summary>
/// <param name="model">The model to use when resolving the target of the URI.</param>
/// <param name="contextUriFromPayload">The string value of the odata.metadata annotation read from the payload.</param>
/// <param name="payloadKind">The payload kind we expect the context URI to conform to.</param>
/// <param name="readerBehavior">Reader behavior if the caller is a reader, null if no reader behavior is available.</param>
/// <param name="needParseFragment">Whether the fragment after $metadata should be parsed, if set to false, only MetadataDocumentUri is parsed.</param>
/// <returns>The result from parsing the context URI.</returns>
internal static ODataJsonLightContextUriParseResult Parse(
IEdmModel model,
string contextUriFromPayload,
ODataPayloadKind payloadKind,
ODataReaderBehavior readerBehavior,
bool needParseFragment)
{
if (contextUriFromPayload == null)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightContextUriParser_NullMetadataDocumentUri);
}
// Create an absolute URI from the payload string
// TODO: Support relative context uri and resolving other relative uris
Uri contextUri;
if (!Uri.TryCreate(contextUriFromPayload, UriKind.Absolute, out contextUri))
{
throw new ODataException(ODataErrorStrings.ODataJsonLightContextUriParser_TopLevelContextUrlShouldBeAbsolute(contextUriFromPayload));
}
ODataJsonLightContextUriParser parser = new ODataJsonLightContextUriParser(model, contextUri);
parser.TokenizeContextUri();
if (needParseFragment)
{
parser.ParseContextUri(payloadKind, readerBehavior);
}
return parser.parseResult;
}
示例2: IsPayloadKindSupported
internal static bool IsPayloadKindSupported(ODataPayloadKind payloadKind, bool inRequest)
{
switch (payloadKind)
{
case ODataPayloadKind.Feed:
case ODataPayloadKind.EntityReferenceLinks:
case ODataPayloadKind.Collection:
case ODataPayloadKind.ServiceDocument:
case ODataPayloadKind.MetadataDocument:
case ODataPayloadKind.Error:
return !inRequest;
case ODataPayloadKind.Entry:
case ODataPayloadKind.Property:
case ODataPayloadKind.EntityReferenceLink:
case ODataPayloadKind.Value:
case ODataPayloadKind.BinaryValue:
case ODataPayloadKind.Batch:
return true;
case ODataPayloadKind.Parameter:
return inRequest;
}
throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ODataUtilsInternal_IsPayloadKindSupported_UnreachableCodePath));
}
示例3: Validate
public static void Validate(ODataPayloadKind payloadKind, string parameterName)
{
if (!IsDefined(payloadKind))
{
throw Error.InvalidEnumArgument(parameterName, (int)payloadKind, typeof(ODataPayloadKind));
}
}
示例4: BuildContextUri
/// <summary>
/// Create context URL from ODataPayloadKind and ODataContextUrlInfo.
/// should make the context uri correct for null primitive / null enum value / normal enum value
/// ODataEnumValue is allowed to have null or arbitrary TypeName, but the output ContextUri must have correct type name.
/// </summary>
/// <param name="payloadKind">The ODataPayloadKind for the context URI.</param>
/// <param name="contextInfo">The ODataContextUrlInfo to be used.</param>
/// <returns>The generated context url.</returns>
internal Uri BuildContextUri(ODataPayloadKind payloadKind, ODataContextUrlInfo contextInfo = null)
{
if (this.baseContextUrl == null)
{
return null;
}
Action<ODataContextUrlInfo> verifyAction;
if (ValidationDictionary.TryGetValue(payloadKind, out verifyAction))
{
if (verifyAction != null && throwIfMissingInfo)
{
Debug.Assert(contextInfo != null, "contextInfo != null");
verifyAction(contextInfo);
}
}
else
{
throw new ODataException(Strings.ODataContextUriBuilder_UnsupportedPayloadKind(payloadKind.ToString()));
}
switch (payloadKind)
{
case ODataPayloadKind.ServiceDocument:
return this.baseContextUrl;
case ODataPayloadKind.EntityReferenceLink:
return new Uri(this.baseContextUrl, ODataConstants.SingleEntityReferencesContextUrlSegment);
case ODataPayloadKind.EntityReferenceLinks:
return new Uri(this.baseContextUrl, ODataConstants.CollectionOfEntityReferencesContextUrlSegment);
}
return CreateFromContextUrlInfo(contextInfo);
}
示例5: ODataRawInputContext
internal ODataRawInputContext(
ODataFormat format,
Stream messageStream,
Encoding encoding,
ODataMessageReaderSettings messageReaderSettings,
bool readingResponse,
bool synchronous,
IEdmModel model,
IODataUrlResolver urlResolver,
ODataPayloadKind readerPayloadKind)
: base(format, messageReaderSettings, readingResponse, synchronous, model, urlResolver)
{
Debug.Assert(messageStream != null, "stream != null");
Debug.Assert(readerPayloadKind != ODataPayloadKind.Unsupported, "readerPayloadKind != ODataPayloadKind.Unsupported");
ExceptionUtils.CheckArgumentNotNull(format, "format");
ExceptionUtils.CheckArgumentNotNull(messageReaderSettings, "messageReaderSettings");
try
{
this.stream = messageStream;
this.encoding = encoding;
this.readerPayloadKind = readerPayloadKind;
}
catch (Exception e)
{
// Dispose the message stream if we failed to create the input context.
if (ExceptionUtils.IsCatchableExceptionType(e) && messageStream != null)
{
messageStream.Dispose();
}
throw;
}
}
示例6: DetermineResponseFormat
/// <summary>
/// Determines the response format based on the results of content negotiation.
/// </summary>
/// <param name="payloadKind">The payload kind of the response.</param>
/// <param name="acceptableMediaTypes">
/// The acceptable media types used to determine the content type of the message.
/// This is a comma separated list of content types as specified in RFC 2616, Section 14.1
/// </param>
/// <param name="acceptableCharSets">
/// The acceptable charsets to use to the determine the encoding of the message.
/// This is a comma separated list of charsets as specified in RFC 2616, Section 14.2
/// </param>
/// <returns>The format the response should use. </returns>
internal ODataFormatWithParameters DetermineResponseFormat(ODataPayloadKind payloadKind, string acceptableMediaTypes, string acceptableCharSets)
{
Debug.Assert(payloadKind != ODataPayloadKind.Unsupported, "kind != ODataPayloadKind.Unsupported");
ContentNegotiationResponseMessage responseMessage = new ContentNegotiationResponseMessage();
ODataMessageWriterSettings settings = new ODataMessageWriterSettings { Version = this.responseVersion };
settings.EnableAtomSupport();
settings.SetContentType(acceptableMediaTypes, acceptableCharSets);
try
{
using (ODataMessageWriter writer = new ODataMessageWriter(responseMessage, settings))
{
ODataFormat format = ODataUtils.SetHeadersForPayload(writer, payloadKind);
return new ODataFormatWithParameters(format, responseMessage.ContentType);
}
}
catch (ODataContentTypeException exception)
{
if (this.throwIfNoMatch)
{
throw new DataServiceException(415, null, Microsoft.OData.Service.Strings.DataServiceException_UnsupportedMediaType, null, exception);
}
return null;
}
}
示例7: GetMediaTypeFormats
public override IEnumerable<ODataMediaTypeFormat> GetMediaTypeFormats(ODataPayloadKind payloadKind)
{
if (payloadKind == ODataPayloadKind.Property)
{
return mediaTypeFormats.Concat(base.GetMediaTypeFormats(payloadKind));
}
return base.GetMediaTypeFormats(payloadKind);
}
示例8: ResponseBodyWriter
internal ResponseBodyWriter(bool hasMoved, IDataService service, IEnumerator queryResults, RequestDescription requestDescription, IODataResponseMessage responseMessage, ODataPayloadKind payloadKind)
{
this.hasMoved = hasMoved;
this.service = service;
this.queryResults = queryResults;
this.requestDescription = requestDescription;
this.responseMessage = responseMessage;
this.payloadKind = payloadKind;
this.encoding = HttpProcessUtility.EncodingFromAcceptCharset(this.service.OperationContext.Host.RequestAcceptCharSet);
if ((((payloadKind == ODataPayloadKind.Entry) || (payloadKind == ODataPayloadKind.Feed)) || ((payloadKind == ODataPayloadKind.Property) || (payloadKind == ODataPayloadKind.Collection))) || (((payloadKind == ODataPayloadKind.EntityReferenceLink) || (payloadKind == ODataPayloadKind.EntityReferenceLinks)) || (((payloadKind == ODataPayloadKind.Error) || (payloadKind == ODataPayloadKind.ServiceDocument)) || (payloadKind == ODataPayloadKind.Parameter))))
{
DataServiceHostWrapper host = service.OperationContext.Host;
if (WebUtil.GetEffectiveMaxResponseVersion(service.Configuration.DataServiceBehavior.MaxProtocolVersion, host.RequestMaxVersion) > RequestDescription.Version2Dot0)
{
bool isEntityOrFeed = (payloadKind == ODataPayloadKind.Entry) || (payloadKind == ODataPayloadKind.Feed);
if (WebUtil.ResponseMediaTypeWouldBeJsonLight(host.RequestAccept, isEntityOrFeed))
{
requestDescription.VerifyAndRaiseResponseVersion(RequestDescription.Version3Dot0, service);
host.ResponseVersion = RequestDescription.Version3Dot0.ToString() + ";";
}
}
}
if (this.requestDescription.TargetKind == RequestTargetKind.MediaResource)
{
this.mediaResourceStream = service.StreamProvider.GetReadStream(this.queryResults.Current, RequestDescription.GetStreamProperty(this.requestDescription), this.service.OperationContext);
}
else if (payloadKind != ODataPayloadKind.BinaryValue)
{
string requestAcceptCharSet = this.service.OperationContext.Host.RequestAcceptCharSet;
if (string.IsNullOrEmpty(requestAcceptCharSet) || (requestAcceptCharSet == "*"))
{
requestAcceptCharSet = "UTF-8";
}
if ((payloadKind == ODataPayloadKind.Value) && !string.IsNullOrEmpty(this.requestDescription.MimeType))
{
this.messageWriter = CreateMessageWriter(this.AbsoluteServiceUri, this.service, this.requestDescription.ActualResponseVersion, responseMessage, ODataFormat.RawValue);
}
else
{
this.messageWriter = CreateMessageWriter(this.AbsoluteServiceUri, this.service, this.requestDescription.ActualResponseVersion, responseMessage, this.service.OperationContext.Host.RequestAccept, requestAcceptCharSet);
}
try
{
this.contentFormat = ODataUtils.SetHeadersForPayload(this.messageWriter, payloadKind);
if ((payloadKind == ODataPayloadKind.Value) && !string.IsNullOrEmpty(this.requestDescription.MimeType))
{
responseMessage.SetHeader("Content-Type", this.requestDescription.MimeType);
}
}
catch (ODataContentTypeException exception)
{
throw new DataServiceException(0x19f, null, System.Data.Services.Strings.DataServiceException_UnsupportedMediaType, null, exception);
}
string headerValue = this.requestDescription.ResponseVersion.ToString() + ";";
responseMessage.SetHeader("DataServiceVersion", headerValue);
}
}
示例9: ODataEntryDeserializer
/// <summary>
/// Initializes a new instance of the <see cref="ODataEntryDeserializer"/> class.
/// </summary>
/// <param name="edmType">The EDM type.</param>
/// <param name="payloadKind">The kind of OData payload that this deserializer reads.</param>
protected ODataEntryDeserializer(IEdmTypeReference edmType, ODataPayloadKind payloadKind)
: base(payloadKind)
{
if (edmType == null)
{
throw Error.ArgumentNull("edmType");
}
EdmType = edmType;
}
示例10: ODataEntrySerializer
protected ODataEntrySerializer(IEdmTypeReference edmType, ODataPayloadKind odataPayloadKind, ODataSerializerProvider serializerProvider)
: this(edmType, odataPayloadKind)
{
if (serializerProvider == null)
{
throw Error.ArgumentNull("serializerProvider");
}
SerializerProvider = serializerProvider;
}
示例11: MaterializeAtom
internal MaterializeAtom(ResponseInfo responseInfo, QueryComponents queryComponents, ProjectionPlan plan, IODataResponseMessage responseMessage, ODataPayloadKind payloadKind)
{
Type type;
this.responseInfo = responseInfo;
this.elementType = queryComponents.LastSegmentType;
this.MergeOptionValue = responseInfo.MergeOption;
this.expectingPrimitiveValue = PrimitiveType.IsKnownNullableType(this.elementType);
Type materializerType = GetTypeForMaterializer(this.expectingPrimitiveValue, this.elementType, responseInfo.MaxProtocolVersion, out type);
this.materializer = ODataMaterializer.CreateMaterializerForMessage(responseMessage, responseInfo, materializerType, queryComponents, plan, payloadKind);
}
示例12: ODataEdmTypeSerializer
/// <summary>
/// Initializes a new instance of the <see cref="ODataEdmTypeSerializer"/> class.
/// </summary>
/// <param name="payloadKind">The kind of OData payload that this serializer generates.</param>
/// <param name="serializerProvider">The <see cref="ODataSerializerProvider"/> to use to write inner objects.</param>
protected ODataEdmTypeSerializer(ODataPayloadKind payloadKind, ODataSerializerProvider serializerProvider)
: this(payloadKind)
{
if (serializerProvider == null)
{
throw Error.ArgumentNull("serializerProvider");
}
SerializerProvider = serializerProvider;
}
示例13: ODataEdmTypeDeserializer
/// <summary>
/// Initializes a new instance of the <see cref="ODataEdmTypeDeserializer"/> class.
/// </summary>
/// <param name="payloadKind">The kind of OData payload this deserializer handles.</param>
/// <param name="deserializerProvider">The <see cref="ODataDeserializerProvider"/>.</param>
protected ODataEdmTypeDeserializer(ODataPayloadKind payloadKind, ODataDeserializerProvider deserializerProvider)
: this(payloadKind)
{
if (deserializerProvider == null)
{
throw Error.ArgumentNull("deserializerProvider");
}
DeserializerProvider = deserializerProvider;
}
示例14: SetHeadersForPayload
/// <summary>Sets the content-type and OData-Version headers on the message used by the message writer.</summary>
/// <returns>The content-type and OData-Version headers on the message used by the message writer.</returns>
/// <param name="messageWriter">The message writer to set the headers for.</param>
/// <param name="payloadKind">The kind of payload to be written with the message writer.</param>
/// <remarks>
/// This method can be called if it is important to set all the message headers before calling any of the
/// write methods on the <paramref name="messageWriter"/>.
/// If it is sufficient to set the headers when the write methods on the <paramref name="messageWriter"/>
/// are called, you don't have to call this method and setting the headers will happen automatically.
/// </remarks>
public static ODataFormat SetHeadersForPayload(ODataMessageWriter messageWriter, ODataPayloadKind payloadKind)
{
ExceptionUtils.CheckArgumentNotNull(messageWriter, "messageWriter");
if (payloadKind == ODataPayloadKind.Unsupported)
{
throw new ArgumentException(Strings.ODataMessageWriter_CannotSetHeadersWithInvalidPayloadKind(payloadKind), "payloadKind");
}
return messageWriter.SetHeaders(payloadKind);
}
示例15: VerifyResult
/// <summary>
/// Verifies that the result of the test (the message reader) is what the test expected.
/// </summary>
/// <param name="messageReader">The message reader which is the result of the test. This method should use it to read the results
/// of the parsing and verify those.</param>
/// <param name="payloadKind">The payload kind specified in the test descriptor.</param>
/// <param name="testConfiguration">The test configuration to use.</param>
public override void VerifyResult(
ODataMessageReaderTestWrapper messageReader,
ODataPayloadKind payloadKind,
ReaderTestConfiguration testConfiguration)
{
// First compare the payload kind detection results.
IEnumerable<ODataPayloadKindDetectionResult> actualDetectionResults = messageReader.DetectPayloadKind();
this.VerifyPayloadKindDetectionResult(actualDetectionResults);
// Then try to read the message as the detected kind if requested
if (this.ReadDetectedPayloads)
{
bool firstResult = true;
foreach (PayloadKindDetectionResult result in this.ExpectedDetectionResults)
{
if (firstResult)
{
// For the first result use the existing message reader
firstResult = false;
}
else
{
// For all subsequent results we need to reset the test stream and create a new message reader
// over it.
this.TestMessage.Reset();
messageReader = TestReaderUtils.CreateMessageReader(this.TestMessage, result.Model, testConfiguration);
// Detect the payload kinds again and make sure we can also read the subsequent payload kinds
// immediately after detection.
actualDetectionResults = messageReader.DetectPayloadKind();
this.VerifyPayloadKindDetectionResult(actualDetectionResults);
}
TestExceptionUtils.ExpectedException(
this.settings.Assert,
() =>
{
using (messageReader)
{
this.settings.MessageToObjectModelReader.ReadMessage(
messageReader,
result.PayloadKind,
result.Model,
new PayloadReaderTestDescriptor.ReaderMetadata(result.ExpectedType),
/*expectedBatchPayload*/ null,
testConfiguration);
}
},
result.ExpectedException,
this.settings.ExceptionVerifier);
}
}
}