本文整理汇总了C#中ODataVersion类的典型用法代码示例。如果您正苦于以下问题:C# ODataVersion类的具体用法?C# ODataVersion怎么用?C# ODataVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataVersion类属于命名空间,在下文中一共展示了ODataVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRandomPayload
/// <summary>
/// Generates an arbitrary top load payload based on the maximum version supplied.
/// </summary>
/// <param name="random">Random generator for generating arbitrary payloads</param>
/// <param name="model">The model to add any new types to</param>
/// <param name="version">Maximum version for generated payloads.</param>
/// <returns>A top level payload.</returns>
public static ODataPayloadElement GetRandomPayload(IRandomNumberGenerator random, EdmModel model, ODataVersion version = ODataVersion.V4)
{
ExceptionUtilities.CheckArgumentNotNull(random, "random");
ExceptionUtilities.CheckArgumentNotNull(model, "model");
Func<ODataPayloadElement>[] payloadCalls = new Func<ODataPayloadElement>[]
{
() => { return GetComplexInstanceCollection(random, model, version); },
() => { return GetComplexProperty(random, model, version); },
() => { return GetDeferredLink(); },
() => { return GetLinkCollection(); },
() => { return GetEntityInstance(random, model, version); },
() => { return GetEntitySetInstance(random, model); },
() => { return GetODataErrorPayload(random); },
() => { return GetPrimitiveCollection(random); },
() => { return GetPrimitiveProperty(random, model); },
() => { return GetPrimitiveValue(random, model); },
};
payloadCalls.Concat(new Func<ODataPayloadElement>[]
{
() => { return GetComplexMultiValueProperty(random, model, version); },
() => { return GetPrimitiveMultiValueProperty(random); },
});
var payloadCall = random.ChooseFrom(payloadCalls);
return payloadCall();
}
示例2: WriteJson
internal void WriteJson(object instance, JsonWriter jsonWriter, string typeName, ODataVersion odataVersion)
{
IPrimitiveTypeConverter converter;
Type type = instance.GetType();
this.TryGetConverter(type, out converter);
converter.WriteJson(instance, jsonWriter, typeName, odataVersion);
}
示例3: ConvertToUriLiteral
public static string ConvertToUriLiteral(object value, ODataVersion version, IEdmModel model)
{
if (value == null)
{
value = new ODataUriNullValue();
}
if (model == null)
{
model = EdmCoreModel.Instance;
}
ODataUriNullValue nullValue = value as ODataUriNullValue;
if (nullValue != null)
{
return ODataUriConversionUtils.ConvertToUriNullValue(nullValue, model);
}
ODataCollectionValue collectionValue = value as ODataCollectionValue;
if (collectionValue != null)
{
return ODataUriConversionUtils.ConvertToUriCollectionLiteral(collectionValue, model, version);
}
ODataComplexValue complexValue = value as ODataComplexValue;
if (complexValue != null)
{
return ODataUriConversionUtils.ConvertToUriComplexLiteral(complexValue, model, version);
}
return ODataUriConversionUtils.ConvertToUriPrimitiveLiteral(value, version);
}
示例4: TestConfiguration
/// <summary>
/// Constructor.
/// </summary>
/// <param name="format">The format used for the test.</param>
/// <param name="version">The OData protocol version to be used for the payload.</param>
/// <param name="request">True if the test is reading a request. Otherwise false if it's reading a response.</param>
public TestConfiguration(ODataFormat format, ODataVersion version, bool request, TestODataBehaviorKind behaviorKind)
{
this.Format = format;
this.Version = version;
this.IsRequest = request;
this.RunBehaviorKind = behaviorKind;
}
示例5: ConvertToODataEntry
/// <summary>
/// Converts an item from the data store into an ODataEntry.
/// </summary>
/// <param name="element">The item to convert.</param>
/// <param name="entitySet">The entity set that the item belongs to.</param>
/// <param name="targetVersion">The OData version this segment is targeting.</param>
/// <returns>The converted ODataEntry.</returns>
public static ODataEntry ConvertToODataEntry(object element, IEdmEntitySet entitySet, ODataVersion targetVersion)
{
IEdmEntityType entityType = entitySet.EntityType();
Uri entryUri = BuildEntryUri(element, entitySet, targetVersion);
var entry = new ODataEntry
{
// writes out the edit link including the service base uri , e.g.: http://<serviceBase>/Customers('ALFKI')
EditLink = entryUri,
// writes out the self link including the service base uri , e.g.: http://<serviceBase>/Customers('ALFKI')
ReadLink = entryUri,
// we use the EditLink as the Id for this entity to maintain convention,
Id = entryUri,
// writes out the <category term='Customer'/> element
TypeName = element.GetType().Namespace + "." + entityType.Name,
Properties = entityType.StructuralProperties().Select(p => ConvertToODataProperty(element, p.Name)),
};
return entry;
}
示例6: ResolveAndValidateNonPrimitiveTargetType
internal static IEdmTypeReference ResolveAndValidateNonPrimitiveTargetType(EdmTypeKind expectedTypeKind, IEdmTypeReference expectedTypeReference, EdmTypeKind payloadTypeKind, IEdmType payloadType, string payloadTypeName, IEdmModel model, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, out SerializationTypeNameAnnotation serializationTypeNameAnnotation)
{
bool flag = (messageReaderSettings.ReaderBehavior.TypeResolver != null) && (payloadType != null);
if (!flag)
{
ValidateTypeSupported(expectedTypeReference, version);
if (model.IsUserModel() && ((expectedTypeReference == null) || !messageReaderSettings.DisableStrictMetadataValidation))
{
VerifyPayloadTypeDefined(payloadTypeName, payloadType);
}
}
else
{
ValidateTypeSupported((payloadType == null) ? null : payloadType.ToTypeReference(true), version);
}
if ((payloadTypeKind != EdmTypeKind.None) && (!messageReaderSettings.DisableStrictMetadataValidation || (expectedTypeReference == null)))
{
ValidationUtils.ValidateTypeKind(payloadTypeKind, expectedTypeKind, payloadTypeName);
}
serializationTypeNameAnnotation = null;
if (!model.IsUserModel())
{
return null;
}
if ((expectedTypeReference == null) || flag)
{
return ResolveAndValidateTargetTypeWithNoExpectedType(expectedTypeKind, payloadType, payloadTypeName, out serializationTypeNameAnnotation);
}
if (messageReaderSettings.DisableStrictMetadataValidation)
{
return ResolveAndValidateTargetTypeStrictValidationDisabled(expectedTypeKind, expectedTypeReference, payloadType, payloadTypeName, out serializationTypeNameAnnotation);
}
return ResolveAndValidateTargetTypeStrictValidationEnabled(expectedTypeKind, expectedTypeReference, payloadType, payloadTypeName, out serializationTypeNameAnnotation);
}
示例7: CheckNextLink
internal static void CheckNextLink(ODataVersion version)
{
if (version < ODataVersion.V2)
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataVersionChecker_NextLinkNotSupported(ODataUtils.ODataVersionToString(version)));
}
}
示例8: CheckCustomTypeScheme
internal static void CheckCustomTypeScheme(ODataVersion version)
{
if (version > ODataVersion.V2)
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataVersionChecker_PropertyNotSupportedForODataVersionGreaterThanX("TypeScheme", ODataUtils.ODataVersionToString(ODataVersion.V2)));
}
}
示例9: CheckCollectionValue
internal static void CheckCollectionValue(ODataVersion version)
{
if (version < ODataVersion.V3)
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataVersionChecker_CollectionNotSupported(ODataUtils.ODataVersionToString(version)));
}
}
示例10: CheckCollectionValueProperties
internal static void CheckCollectionValueProperties(ODataVersion version, string propertyName)
{
if (version < ODataVersion.V3)
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataVersionChecker_CollectionPropertiesNotSupported(propertyName, ODataUtils.ODataVersionToString(version)));
}
}
示例11: ExtraRequestChangesetOperations
/// <summary>
/// Generates extra operations to go into a request changeset
/// </summary>
/// <param name="random">For generating the payloads to go in the extra operations</param>
/// <param name="requestManager">For building the operations</param>
/// <param name="model">To add any new types to.</param>
/// <param name="baseUri">Base uri for the extra operations.</param>
/// <param name="version">Maximum version for </param>
/// <returns>An array of extra request operations.</returns>
public static IHttpRequest[] ExtraRequestChangesetOperations(
IRandomNumberGenerator random,
IODataRequestManager requestManager,
EdmModel model,
ODataUri baseUri,
ODataVersion version = ODataVersion.V4)
{
ExceptionUtilities.CheckArgumentNotNull(random, "random");
ExceptionUtilities.CheckArgumentNotNull(requestManager, "requestManager");
ExceptionUtilities.CheckArgumentNotNull(baseUri, "baseUri");
var headers = new Dictionary<string, string> { { "RequestHeader", "RequestHeaderValue" } };
string mergeContentType = HttpUtilities.BuildContentType(MimeTypes.ApplicationXml, Encoding.UTF8.WebName, null);
List<IHttpRequest> requests = new List<IHttpRequest>();
ODataRequest request = null;
for (int i = 0; i < 4; i++)
{
request = requestManager.BuildRequest(baseUri, HttpVerb.Post, headers);
request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
requests.Add(request);
request = requestManager.BuildRequest(baseUri, HttpVerb.Put, headers);
request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
requests.Add(request);
request = requestManager.BuildRequest(baseUri, HttpVerb.Patch, headers);
request.Body = requestManager.BuildBody(mergeContentType, baseUri, RandomPayloadBuilder.GetRandomPayload(random, model, version));
requests.Add(request);
request = requestManager.BuildRequest(baseUri, HttpVerb.Delete, headers);
requests.Add(request);
}
return requests.ToArray();
}
示例12: WriteJsonObjectValue
/// <summary>
/// Writes the json object value to the <paramref name="jsonWriter"/>.
/// </summary>
/// <param name="jsonWriter">The <see cref="JsonWriter"/> to write to.</param>
/// <param name="jsonObjectValue">Writes the given json object value to the underlying json writer.</param>
/// <param name="typeName">Type name of the json object to write. If type name is null, no type name is written.</param>
/// <param name="odataVersion">The OData protocol version to be used for writing payloads.</param>
internal static void WriteJsonObjectValue(this JsonWriter jsonWriter, IDictionary<string, object> jsonObjectValue, string typeName, ODataVersion odataVersion)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(jsonWriter != null, "jsonWriter != null");
Debug.Assert(jsonObjectValue != null, "jsonObjectValue != null");
jsonWriter.StartObjectScope();
if (typeName != null)
{
Debug.Assert(!jsonObjectValue.ContainsKey(JsonConstants.ODataMetadataName), "__metadata should not be present in jsonObjectValue");
jsonWriter.WriteName(JsonConstants.ODataMetadataName);
jsonWriter.StartObjectScope();
jsonWriter.WriteName(JsonConstants.ODataMetadataTypeName);
jsonWriter.WriteValue(typeName);
jsonWriter.EndObjectScope();
}
foreach (KeyValuePair<string, object> property in jsonObjectValue)
{
jsonWriter.WriteName(property.Key);
jsonWriter.WriteJsonValue(property.Value, odataVersion);
}
jsonWriter.EndObjectScope();
}
示例13: RaiseMinPayloadVersion
/// <summary>
/// Sets the configuration limit to require minimum payload version.
/// </summary>
/// <param name="version">The minimum payload version required.</param>
public void RaiseMinPayloadVersion(ODataVersion version)
{
if (this.minPayloadVersion < version)
{
this.minPayloadVersion = version;
}
}
示例14: ConvertFromUriLiteral
public static object ConvertFromUriLiteral(string value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference)
{
Exception exception;
ExpressionToken token;
ExceptionUtils.CheckArgumentNotNull<string>(value, "value");
if ((typeReference != null) && (model == null))
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataUriUtils_ConvertFromUriLiteralTypeRefWithoutModel);
}
if (model == null)
{
model = EdmCoreModel.Instance;
}
ExpressionLexer lexer = new ExpressionLexer(value, false);
if (!lexer.TryPeekNextToken(out token, out exception))
{
return ODataUriConversionUtils.ConvertFromComplexOrCollectionValue(value, version, model, typeReference);
}
object primitiveValue = lexer.ReadLiteralToken();
if (typeReference != null)
{
primitiveValue = ODataUriConversionUtils.VerifyAndCoerceUriPrimitiveLiteral(primitiveValue, model, typeReference, version);
}
if (primitiveValue is ISpatial)
{
ODataVersionChecker.CheckSpatialValue(version);
}
return primitiveValue;
}
示例15: WriteEntry
/// <summary>
/// Writes an OData entry.
/// </summary>
/// <param name="writer">The ODataWriter that will write the entry.</param>
/// <param name="element">The item from the data store to write.</param>
/// <param name="navigationSource">The navigation source in the model that the entry belongs to.</param>
/// <param name="model">The data store model.</param>
/// <param name="targetVersion">The OData version this segment is targeting.</param>
/// <param name="selectExpandClause">The SelectExpandClause.</param>
public static void WriteEntry(ODataWriter writer, object element, IEdmNavigationSource entitySource, ODataVersion targetVersion, SelectExpandClause selectExpandClause, Dictionary<string, string> incomingHeaders = null)
{
var entry = ODataObjectModelConverter.ConvertToODataEntry(element, entitySource, targetVersion);
entry.ETag = Utility.GetETagValue(element);
if (selectExpandClause != null && selectExpandClause.SelectedItems.OfType<PathSelectItem>().Any())
{
ExpandSelectItemHandler selectItemHandler = new ExpandSelectItemHandler(entry);
foreach (var item in selectExpandClause.SelectedItems.OfType<PathSelectItem>())
{
item.HandleWith(selectItemHandler);
}
entry = selectItemHandler.ProjectedEntry;
}
CustomizeEntry(incomingHeaders, entry);
writer.WriteStart(entry);
// gets all of the expandedItems, including ExpandedRefernceSelectItem and ExpandedNavigationItem
var expandedItems = selectExpandClause == null ? null : selectExpandClause.SelectedItems.OfType<ExpandedReferenceSelectItem>();
WriteNavigationLinks(writer, element, entry.ReadLink, entitySource, targetVersion, expandedItems);
writer.WriteEnd();
}