本文整理汇总了C#中Microsoft.OData.Core.ODataFeed.AddAction方法的典型用法代码示例。如果您正苦于以下问题:C# ODataFeed.AddAction方法的具体用法?C# ODataFeed.AddAction怎么用?C# ODataFeed.AddAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Core.ODataFeed
的用法示例。
在下文中一共展示了ODataFeed.AddAction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritingFeedWithFunctionAndAction
public void WritingFeedWithFunctionAndAction()
{
ODataFeed feed = new ODataFeed();
feed.AddAction(new ODataAction { Metadata = new Uri("http://example.org/odata.svc/$metadata#Action"), Target = new Uri("http://example.org/odata.svc/DoAction"), Title = "ActionTitle" });
feed.AddFunction(new ODataFunction() { Metadata = new Uri("http://example.org/odata.svc/$metadata#Function"), Target = new Uri("http://example.org/odata.svc/DoFunction"), Title = "FunctionTitle" });
ODataItem[] itemsToWrite = new ODataItem[]
{
feed,
this.entryWithOnlyData1,
};
string result = this.GetWriterOutputForContentTypeAndKnobValue("application/json;odata.metadata=minimal", true, itemsToWrite, Model, EntitySet, EntityType);
const string expectedPayload = "{\"" +
"@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet\"," +
"\"#Action\":{" +
"\"title\":\"ActionTitle\"," +
"\"target\":\"http://example.org/odata.svc/DoAction\"" +
"}," +
"\"#Function\":{" +
"\"title\":\"FunctionTitle\"," +
"\"target\":\"http://example.org/odata.svc/DoFunction\"" +
"}," +
"\"value\":[" +
"{" +
"\"ID\":101,\"Name\":\"Alice\"" +
"}" +
"]" +
"}";
result.Should().Be(expectedPayload);
}
示例2: CreateODataFeed
/// <summary>
/// Create the <see cref="ODataFeed"/> to be written for the given feed instance.
/// </summary>
/// <param name="feedInstance">The instance representing the feed being written.</param>
/// <param name="feedType">The EDM type of the feed being written.</param>
/// <param name="writeContext">The serializer context.</param>
/// <returns>The created <see cref="ODataFeed"/> object.</returns>
public virtual ODataFeed CreateODataFeed(IEnumerable feedInstance, IEdmCollectionTypeReference feedType,
ODataSerializerContext writeContext)
{
ODataFeed feed = new ODataFeed();
if (writeContext.NavigationSource != null)
{
FeedContext feedContext = new FeedContext
{
Request = writeContext.Request,
RequestContext = writeContext.RequestContext,
EntitySetBase = writeContext.NavigationSource as IEdmEntitySetBase,
Url = writeContext.Url,
FeedInstance = feedInstance
};
IEdmEntityType entityType = GetEntityType(feedType).Definition as IEdmEntityType;
var operations = writeContext.Model.GetAvailableOperationsBoundToCollection(entityType);
var odataOperations = CreateODataOperations(operations, feedContext, writeContext);
foreach (var odataOperation in odataOperations)
{
ODataAction action = odataOperation as ODataAction;
if (action != null)
{
feed.AddAction(action);
}
else
{
feed.AddFunction((ODataFunction)odataOperation);
}
}
}
if (writeContext.ExpandedEntity == null)
{
// If we have more OData format specific information apply it now, only if we are the root feed.
PageResult odataFeedAnnotations = feedInstance as PageResult;
if (odataFeedAnnotations != null)
{
feed.Count = odataFeedAnnotations.Count;
feed.NextPageLink = odataFeedAnnotations.NextPageLink;
}
else if (writeContext.Request != null)
{
feed.NextPageLink = writeContext.Request.ODataProperties().NextLink;
long? countValue = writeContext.Request.ODataProperties().TotalCount;
if (countValue.HasValue)
{
feed.Count = countValue.Value;
}
}
}
else
{
// nested feed
ITruncatedCollection truncatedCollection = feedInstance as ITruncatedCollection;
if (truncatedCollection != null && truncatedCollection.IsTruncated)
{
feed.NextPageLink = GetNestedNextPageLink(writeContext, truncatedCollection.PageSize);
}
ICountOptionCollection countOptionCollection = feedInstance as ICountOptionCollection;
if (countOptionCollection != null && countOptionCollection.TotalCount != null)
{
feed.Count = countOptionCollection.TotalCount;
}
}
return feed;
}
示例3: AddActionShouldAddActionToFeed
public void AddActionShouldAddActionToFeed()
{
ODataFeed feed = new ODataFeed();
feed.Actions.Count().Should().Be(0);
feed.AddAction(new ODataAction());
feed.Actions.Count().Should().Be(1);
feed.AddAction(new ODataAction());
feed.Actions.Count().Should().Be(2);
}