本文整理汇总了C#中ODataFeed类的典型用法代码示例。如果您正苦于以下问题:C# ODataFeed类的具体用法?C# ODataFeed怎么用?C# ODataFeed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataFeed类属于命名空间,在下文中一共展示了ODataFeed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBeAbleToSetTheFeedSerializationInfo
public void ShouldBeAbleToSetTheFeedSerializationInfo()
{
ODataFeed feed = new ODataFeed();
ODataFeedAndEntrySerializationInfo serializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.base", ExpectedTypeName = "ns.expected" };
feed.SetSerializationInfo(serializationInfo);
feed.SerializationInfo.Should().BeSameAs(serializationInfo);
}
示例2: WriteStartShouldIgnoreDeltaLinkWhenWritingResponseTopLevelFeed
public void WriteStartShouldIgnoreDeltaLinkWhenWritingResponseTopLevelFeed()
{
string expectedPayload =
@"<?xml version=""1.0"" encoding=""utf-8""?>"
+ @"<feed xmlns=""http://www.w3.org/2005/Atom"" xmlns:d=""http://docs.oasis-open.org/odata/ns/data"" xmlns:m=""http://docs.oasis-open.org/odata/ns/metadata"" xmlns:georss=""http://www.georss.org/georss"" xmlns:gml=""http://www.opengis.net/gml"" m:context=""http://www.example.com/$metadata#TestEntitySet"">"
+ "<id>http://host/TestEntitySet</id>"
+ "<title />";
Action<ODataWriter> deltaLinkAtWriteStart = (odataWriter) =>
{
var feedToWrite = new ODataFeed { Id = new Uri("http://host/TestEntitySet", UriKind.Absolute), DeltaLink = new Uri("http://host/deltaLink", UriKind.Absolute) };
odataWriter.WriteStart(feedToWrite);
};
WriteAnnotationsAndValidatePayload(deltaLinkAtWriteStart, ODataFormat.Atom, expectedPayload, request: false, createFeedWriter: true);
}
示例3: WriteStartShouldIgnoreDeltaLinkWhenWritingRequestTopLevelFeed
public void WriteStartShouldIgnoreDeltaLinkWhenWritingRequestTopLevelFeed()
{
string expectedPayload =
"{" +
"\"@odata.context\":\"http://www.example.com/$metadata#TestEntitySet\"," +
"\"value\":[]" +
"}";
Action<ODataWriter> deltaLinkAtWriteStart = (odataWriter) =>
{
var feedToWrite = new ODataFeed { DeltaLink = new Uri("http://host/deltaLink", UriKind.Absolute) };
odataWriter.WriteStart(feedToWrite);
odataWriter.WriteEnd();
};
WriteAnnotationsAndValidatePayload(deltaLinkAtWriteStart, ODataFormat.Json, expectedPayload, request: true, createFeedWriter: true);
}
示例4: CreateFeed_NoMetadata
public void CreateFeed_NoMetadata()
{
var feed = new ODataFeed<Item>();
feed.Feed = new List<Folder>()
{
GetFolder()
};
(feed.Feed.First()).MetadataUrl =
"https://labs.sf-api.com/sf/v3/$metadata#ShareFile.Api.Models.Folder";
((feed.Feed.First() as Folder).Children.First()).MetadataUrl =
"https://labs.sf-api.com/sf/v3/$metadata#ShareFile.Api.Models.File";
feed.MetadataUrl = "";
var serializer = GetSerializer();
StringWriter writer = new StringWriter();
serializer.Serialize(writer, feed);
var jsonReader = new JsonTextReader(new StringReader(writer.ToString()));
var item = serializer.Deserialize<ODataFeed<Item>>(jsonReader);
item.Should().NotBeNull();
item.Feed.First().GetType().Should().Be(typeof(Folder));
}
示例5: EndFeed
protected override void EndFeed(ODataFeed feed)
{
throw new NotImplementedException();
}
示例6: WriteFeedMetadata
/// <summary>
/// Write the given feed metadata in atom format
/// </summary>
/// <param name="feed">The feed for which to write the meadata or null if it is the metadata of an atom:source element.</param>
/// <param name="updatedTime">Value for the atom:updated element.</param>
/// <param name="authorWritten">Set to true if the author element was written, false otherwise.</param>
internal void WriteFeedMetadata(ODataFeed feed, string updatedTime, out bool authorWritten)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(feed != null, "feed != null");
Debug.Assert(!string.IsNullOrEmpty(updatedTime), "!string.IsNullOrEmpty(updatedTime)");
#if DEBUG
DateTimeOffset tempDateTimeOffset;
Debug.Assert(DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset), "DateTimeOffset.TryParse(updatedTime, out tempDateTimeOffset)");
#endif
AtomFeedMetadata feedMetadata = feed.GetAnnotation<AtomFeedMetadata>();
if (feedMetadata == null)
{
// create the required metadata elements with default values.
// <atom:id>idValue</atom:id>
Debug.Assert(!string.IsNullOrEmpty(feed.Id), "The feed Id should have been validated by now.");
this.WriteElementWithTextContent(
AtomConstants.AtomNamespacePrefix,
AtomConstants.AtomIdElementName,
AtomConstants.AtomNamespace,
feed.Id);
// <atom:title></atom:title>
this.WriteEmptyElement(
AtomConstants.AtomNamespacePrefix,
AtomConstants.AtomTitleElementName,
AtomConstants.AtomNamespace);
// <atom:updated>dateTimeOffset</atom:updated>
this.WriteElementWithTextContent(
AtomConstants.AtomNamespacePrefix,
AtomConstants.AtomUpdatedElementName,
AtomConstants.AtomNamespace,
updatedTime);
authorWritten = false;
}
else
{
this.atomFeedMetadataSerializer.WriteFeedMetadata(feedMetadata, feed, updatedTime, out authorWritten);
}
}
示例7: ReadMetadataReferencePropertyValue
/// <summary>
/// Read the metadata reference property value for the feed being read.
/// </summary>
/// <param name="feed">The feed to read.</param>
/// <param name="metadataReferencePropertyName">The name of the metadata reference property being read.</param>
private void ReadMetadataReferencePropertyValue(ODataFeed feed, string metadataReferencePropertyName)
{
Debug.Assert(feed != null, "feed != null");
Debug.Assert(!string.IsNullOrEmpty(metadataReferencePropertyName), "!string.IsNullOrEmpty(metadataReferencePropertyName)");
Debug.Assert(metadataReferencePropertyName.IndexOf(ODataConstants.ContextUriFragmentIndicator) > -1, "metadataReferencePropertyName.IndexOf(JsonLightConstants.ContextUriFragmentIndicator) > -1");
this.JsonReader.AssertNotBuffering();
this.ValidateCanReadMetadataReferenceProperty();
// Validate that the property name is a valid absolute URI or a valid URI fragment.
ODataJsonLightValidationUtils.ValidateMetadataReferencePropertyName(this.ContextUriParseResult.MetadataDocumentUri, metadataReferencePropertyName);
bool insideArray = false;
if (this.JsonReader.NodeType == JsonNodeType.StartArray)
{
this.JsonReader.ReadStartArray();
insideArray = true;
}
do
{
this.ReadSingleOperationValue(feed, metadataReferencePropertyName, insideArray);
}
while (insideArray && this.JsonReader.NodeType != JsonNodeType.EndArray);
if (insideArray)
{
this.JsonReader.ReadEndArray();
}
this.JsonReader.AssertNotBuffering();
this.AssertJsonCondition(JsonNodeType.Property, JsonNodeType.EndObject);
}
示例8: ReadSingleOperationValue
/// <summary>
/// Reads one operation for the feed being read.
/// </summary>
/// <param name="feed">The feed to read.</param>
/// <param name="metadataReferencePropertyName">The name of the metadata reference property being read.</param>
/// <param name="insideArray">true if the operation value is inside an array, i.e. multiple targets for the operation; false otherwise.</param>
private void ReadSingleOperationValue(ODataFeed feed, string metadataReferencePropertyName, bool insideArray)
{
Debug.Assert(feed != null, "feed != null");
Debug.Assert(!string.IsNullOrEmpty(metadataReferencePropertyName), "!string.IsNullOrEmpty(metadataReferencePropertyName)");
Debug.Assert(ODataJsonLightUtils.IsMetadataReferenceProperty(metadataReferencePropertyName), "ODataJsonLightReaderUtils.IsMetadataReferenceProperty(metadataReferencePropertyName)");
if (this.JsonReader.NodeType != JsonNodeType.StartObject)
{
throw new ODataException(ODataErrorStrings.ODataJsonOperationsDeserializerUtils_OperationsPropertyMustHaveObjectValue(metadataReferencePropertyName, this.JsonReader.NodeType));
}
// read over the start-object node of the metadata object for the operations
this.JsonReader.ReadStartObject();
var operation = this.CreateODataOperationAndAddToFeed(feed, metadataReferencePropertyName);
// Ignore the unrecognized operation.
if (operation == null)
{
while (this.JsonReader.NodeType == JsonNodeType.Property)
{
this.JsonReader.ReadPropertyName();
this.JsonReader.SkipValue();
}
this.JsonReader.ReadEndObject();
return;
}
Debug.Assert(operation.Metadata != null, "operation.Metadata != null");
while (this.JsonReader.NodeType == JsonNodeType.Property)
{
string operationPropertyName = ODataAnnotationNames.RemoveAnnotationPrefix(this.JsonReader.ReadPropertyName());
switch (operationPropertyName)
{
case JsonConstants.ODataOperationTitleName:
if (operation.Title != null)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightEntryAndFeedDeserializer_MultipleOptionalPropertiesInOperation(operationPropertyName, metadataReferencePropertyName));
}
string titleString = this.JsonReader.ReadStringValue(JsonConstants.ODataOperationTitleName);
ODataJsonLightValidationUtils.ValidateOperationPropertyValueIsNotNull(titleString, operationPropertyName, metadataReferencePropertyName);
operation.Title = titleString;
break;
case JsonConstants.ODataOperationTargetName:
if (operation.Target != null)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightEntryAndFeedDeserializer_MultipleOptionalPropertiesInOperation(operationPropertyName, metadataReferencePropertyName));
}
string targetString = this.JsonReader.ReadStringValue(JsonConstants.ODataOperationTargetName);
ODataJsonLightValidationUtils.ValidateOperationPropertyValueIsNotNull(targetString, operationPropertyName, metadataReferencePropertyName);
operation.Target = this.ProcessUriFromPayload(targetString);
break;
default:
// skip over all unknown properties and read the next property or
// the end of the metadata for the current propertyName
this.JsonReader.SkipValue();
break;
}
}
if (operation.Target == null && insideArray)
{
throw new ODataException(ODataErrorStrings.ODataJsonLightEntryAndFeedDeserializer_OperationMissingTargetProperty(metadataReferencePropertyName));
}
// read the end-object node of the target / title pair
this.JsonReader.ReadEndObject();
}
示例9: 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);
}
示例10: JsonLightFeedScope
/// <summary>
/// Constructor to create a new feed scope.
/// </summary>
/// <param name="feed">The feed for the new scope.</param>
/// <param name="navigationSource">The navigation source we are going to write entities for.</param>
/// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param>
/// <param name="skipWriting">true if the content of the scope to create should not be written.</param>
/// <param name="selectedProperties">The selected properties of this scope.</param>
/// <param name="odataUri">The ODataUri info of this scope.</param>
internal JsonLightFeedScope(ODataFeed feed, IEdmNavigationSource navigationSource, IEdmEntityType entityType, bool skipWriting, SelectedPropertiesNode selectedProperties, ODataUri odataUri)
: base(feed, navigationSource, entityType, skipWriting, selectedProperties, odataUri)
{
}
示例11: WriteFeedDeltaLink
/// <summary>
/// Writes the delta link for a feed.
/// </summary>
/// <param name="feed">The feed to write the delta link for.</param>
internal void WriteFeedDeltaLink(ODataFeed feed)
{
Debug.Assert(feed != null, "feed != null");
Uri deltaLink = feed.DeltaLink;
if (deltaLink != null)
{
// <atom:link rel="http://docs.oasis-open.org/odata/ns/delta" href="delta-link" />
this.WriteFeedLink(
feed,
AtomConstants.AtomDeltaRelationAttributeValue,
deltaLink,
(feedMetadata) => feedMetadata == null ? null : feedMetadata.Links.FirstOrDefault(link => link.Relation == AtomConstants.AtomDeltaRelationAttributeValue));
}
}
示例12: WriteFeedNextPageLink
/// <summary>
/// Writes the next page link for a feed.
/// </summary>
/// <param name="feed">The feed to write the next page link for.</param>
internal void WriteFeedNextPageLink(ODataFeed feed)
{
Debug.Assert(feed != null, "feed != null");
Uri nextPageLink = feed.NextPageLink;
if (nextPageLink != null)
{
// <atom:link rel="next" href="next-page-link" />
this.WriteFeedLink(
feed,
AtomConstants.AtomNextRelationAttributeValue,
nextPageLink,
(feedMetadata) => feedMetadata == null ? null : feedMetadata.NextPageLink);
}
}
示例13: WriteFeedInstanceAnnotations
/// <summary>
/// Writes the collection of <see cref="ODataInstanceAnnotation"/> for the given <paramref name="feed"/> to the ATOM payload.
/// </summary>
/// <param name="feed">The feed to write the <see cref="ODataInstanceAnnotation"/> for.</param>
/// <param name="currentFeedScope">The current feed scope.</param>
private void WriteFeedInstanceAnnotations(ODataFeed feed, AtomFeedScope currentFeedScope)
{
if (this.IsTopLevel)
{
this.WriteInstanceAnnotations(feed.InstanceAnnotations, currentFeedScope.InstanceAnnotationWriteTracker);
}
else
{
if (feed.InstanceAnnotations.Count > 0)
{
throw new ODataException(OData.Core.Strings.ODataJsonLightWriter_InstanceAnnotationNotSupportedOnExpandedFeed);
}
}
}
示例14: EndFeed
/// <summary>
/// Finish writing a feed.
/// </summary>
/// <param name="feed">The feed to write.</param>
protected override void EndFeed(ODataFeed feed)
{
Debug.Assert(feed != null, "feed != null");
Debug.Assert(
this.ParentNavigationLink == null || this.ParentNavigationLink.IsCollection.Value,
"We should have already verified that the IsCollection matches the actual content of the link (feed/entry).");
AtomFeedScope currentFeedScope = this.CurrentFeedScope;
if (!currentFeedScope.AuthorWritten && currentFeedScope.EntryCount == 0)
{
// Write an empty author if there were no entries, since the feed must have an author if the entries don't have one as per ATOM spec
this.atomEntryAndFeedSerializer.WriteFeedDefaultAuthor();
}
this.WriteFeedInstanceAnnotations(feed, currentFeedScope);
this.atomEntryAndFeedSerializer.WriteFeedNextPageLink(feed);
// Write delta link only in case of writing response for a top level feed.
if (this.IsTopLevel)
{
if (this.atomOutputContext.WritingResponse)
{
this.atomEntryAndFeedSerializer.WriteFeedDeltaLink(feed);
}
}
else
{
this.ValidateNoDeltaLinkForExpandedFeed(feed);
}
// </atom:feed>
this.atomOutputContext.XmlWriter.WriteEndElement();
this.CheckAndWriteParentNavigationLinkEndForInlineElement();
}
示例15: StartFeed
/// <summary>
/// Start writing a feed.
/// </summary>
/// <param name="feed">The feed to write.</param>
protected override void StartFeed(ODataFeed feed)
{
Debug.Assert(feed != null, "feed != null");
Debug.Assert(
this.ParentNavigationLink == null || !this.ParentNavigationLink.IsCollection.HasValue || this.ParentNavigationLink.IsCollection.Value,
"We should have already verified that the IsCollection matches the actual content of the link (feed/entry).");
// Verify non-empty ID
// We require non-null, non-empty IDs on feeds since it is required by ATOM.
if (feed.Id == null)
{
throw new ODataException(OData.Core.Strings.ODataAtomWriter_FeedsMustHaveNonEmptyId);
}
this.CheckAndWriteParentNavigationLinkStartForInlineElement();
// <atom:feed>
this.atomOutputContext.XmlWriter.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomFeedElementName, AtomConstants.AtomNamespace);
if (this.IsTopLevel)
{
this.atomEntryAndFeedSerializer.WriteBaseUriAndDefaultNamespaceAttributes();
// metadata:context
this.atomEntryAndFeedSerializer.TryWriteFeedContextUri(this.CurrentFeedScope.GetOrCreateTypeContext(this.atomOutputContext.Model, this.atomOutputContext.WritingResponse));
if (feed.Count.HasValue)
{
this.atomEntryAndFeedSerializer.WriteCount(feed.Count.Value);
}
}
bool authorWritten;
this.atomEntryAndFeedSerializer.WriteFeedMetadata(feed, this.updatedTime, out authorWritten);
this.CurrentFeedScope.AuthorWritten = authorWritten;
this.WriteFeedInstanceAnnotations(feed, this.CurrentFeedScope);
}