本文整理汇总了C#中IODataResponseMessage.PreferenceAppliedHeader方法的典型用法代码示例。如果您正苦于以下问题:C# IODataResponseMessage.PreferenceAppliedHeader方法的具体用法?C# IODataResponseMessage.PreferenceAppliedHeader怎么用?C# IODataResponseMessage.PreferenceAppliedHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IODataResponseMessage
的用法示例。
在下文中一共展示了IODataResponseMessage.PreferenceAppliedHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override void Process(IODataRequestMessage requestMessage, IODataResponseMessage responseMessage)
{
if (this.TryDispatch(requestMessage, responseMessage))
{
return;
}
this.QueryContext.InitializeServerDrivenPaging(this.PreferenceContext);
this.QueryContext.InitializeTrackingChanges(this.PreferenceContext);
object queryResults = this.QueryContext.ResolveQuery(this.DataSource);
if (queryResults == null)
{
// For individual property or $value
if (this.QueryContext.Target.Property != null)
{
// Protocol 9.1.4 Response Code 204 No Content
// A request returns 204 No Content if the requested resource has the null value,
// or if the service applies a return=minimal preference. In this case, the response body MUST be empty.
ResponseWriter.WriteEmptyResponse(responseMessage);
return;
}
else
{
throw Utility.BuildException(HttpStatusCode.NotFound);
}
}
// Handle the prefer of "odata.include-annotations", including it in response header
if (!string.IsNullOrEmpty(this.PreferenceContext.IncludeAnnotations))
{
responseMessage.AddPreferenceApplied(string.Format("{0}={1}",
ServiceConstants.Preference_IncludeAnnotations, this.PreferenceContext.IncludeAnnotations));
}
if (this.PreferenceContext.MaxPageSize.HasValue)
{
responseMessage.AddPreferenceApplied(string.Format("{0}={1}", ServiceConstants.Preference_MaxPageSize, this.QueryContext.appliedPageSize.Value));
}
if (this.PreferenceContext.TrackingChanges)
{
responseMessage.AddPreferenceApplied(ServiceConstants.Preference_TrackChanging);
}
responseMessage.PreferenceAppliedHeader().AnnotationFilter = "*";
responseMessage.SetStatusCode(HttpStatusCode.OK);
using (var messageWriter = this.CreateMessageWriter(responseMessage))
{
IEdmNavigationSource navigationSource = this.QueryContext.Target.NavigationSource;
IEnumerable iEnumerableResults = queryResults as IEnumerable;
if (this.QueryContext.Target.IsReference && this.QueryContext.Target.TypeKind == EdmTypeKind.Collection)
{
// Query a $ref collection
IList<ODataEntityReferenceLink> links = new List<ODataEntityReferenceLink>();
foreach (var iEnumerableResult in iEnumerableResults)
{
var link = new ODataEntityReferenceLink
{
Url = Utility.BuildLocationUri(this.QueryContext, iEnumerableResult),
};
links.Add(link);
}
ODataEntityReferenceLinks linksCollection = new ODataEntityReferenceLinks() { Links = links, NextPageLink = this.QueryContext.NextLink };
linksCollection.InstanceAnnotations.Add(new ODataInstanceAnnotation ("Links.Annotation" , new ODataPrimitiveValue(true)));
messageWriter.WriteEntityReferenceLinks(linksCollection);
}
else if (this.QueryContext.Target.IsReference && this.QueryContext.Target.TypeKind == EdmTypeKind.Entity)
{
// Query a $ref
var link = new ODataEntityReferenceLink
{
Url = Utility.BuildLocationUri(this.QueryContext, queryResults),
};
link.InstanceAnnotations.Add(new ODataInstanceAnnotation("Link.Annotation", new ODataPrimitiveValue(true)));
messageWriter.WriteEntityReferenceLink(link);
}
else if (this.QueryContext.Target.NavigationSource != null && this.QueryContext.Target.TypeKind == EdmTypeKind.Collection)
{
// Query a feed
IEdmEntitySetBase entitySet = navigationSource as IEdmEntitySetBase;
IEdmEntityType entityType = this.QueryContext.Target.ElementType as IEdmEntityType;
if (entitySet == null || entityType == null)
{
throw new InvalidOperationException("Invalid target when query feed.");
}
ODataWriter resultWriter = messageWriter.CreateODataFeedWriter(entitySet, entityType);
ResponseWriter.WriteFeed(resultWriter, iEnumerableResults, entitySet, ODataVersion.V4, this.QueryContext.QuerySelectExpandClause, this.QueryContext.TotalCount, this.QueryContext.DeltaLink, this.QueryContext.NextLink, this.RequestHeaders);
resultWriter.Flush();
}
//.........这里部分代码省略.........