本文整理汇总了C#中Microsoft.OData.Core.ODataWriter类的典型用法代码示例。如果您正苦于以下问题:C# ODataWriter类的具体用法?C# ODataWriter怎么用?C# ODataWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataWriter类属于Microsoft.OData.Core命名空间,在下文中一共展示了ODataWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteObjectInline
/// <inheritdoc />
public override void WriteObjectInline(object graph, IEdmTypeReference expectedType, ODataWriter writer,
ODataSerializerContext writeContext)
{
if (writer == null)
{
throw Error.ArgumentNull("writer");
}
if (writeContext == null)
{
throw Error.ArgumentNull("writeContext");
}
if (expectedType == null)
{
throw Error.ArgumentNull("expectedType");
}
if (graph == null)
{
throw new SerializationException(Error.Format(SRResources.CannotSerializerNull, Feed));
}
IEnumerable enumerable = graph as IEnumerable; // Data to serialize
if (enumerable == null)
{
throw new SerializationException(
Error.Format(SRResources.CannotWriteType, GetType().Name, graph.GetType().FullName));
}
WriteFeed(enumerable, expectedType, writer, writeContext);
}
示例2: WriteObjectInline
public override void WriteObjectInline(object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
{
if (graph != null)
{
base.WriteObjectInline(graph, expectedType, writer, writeContext);
}
}
示例3: StartRead
private void StartRead(ODataReader reader, ODataWriter writer)
{
ExceptionUtilities.Assert(reader.State == ODataReaderState.Start, "Reader is expected to be in state Start at StartRead.");
while (reader.Read())
{
switch(reader.State)
{
case ODataReaderState.EntryStart:
writer.WriteStart((ODataEntry)reader.Item);
break;
case ODataReaderState.FeedStart:
writer.WriteStart((ODataFeed)reader.Item);
break;
case ODataReaderState.NavigationLinkStart:
writer.WriteStart((ODataNavigationLink)reader.Item);
break;
case ODataReaderState.EntryEnd:
case ODataReaderState.FeedEnd:
case ODataReaderState.NavigationLinkEnd:
writer.WriteEnd();
break;
default:
throw new NotSupportedException();
};
}
}
示例4: 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();
}
示例5: ODataWriterWrapper
/// <summary>
/// Prevents a default instance of the <see cref="ODataWriterWrapper"/> class from being created.
/// </summary>
/// <param name="odataWriter">The odata writer.</param>
/// <param name="requestPipeline">The request pipeline configuration.</param>
private ODataWriterWrapper(ODataWriter odataWriter, DataServiceClientRequestPipelineConfiguration requestPipeline)
{
Debug.Assert(odataWriter != null, "odataWriter != null");
Debug.Assert(requestPipeline != null, "DataServiceClientRequestPipelineConfiguration != null");
this.odataWriter = odataWriter;
this.requestPipeline = requestPipeline;
}
示例6: ODataWriterTestWrapper
/// <summary>
/// Constructor.
/// </summary>
/// <param name="writer">The writer to wrap.</param>
/// <param name="testConfiguration">The test configuration to use.</param>
public ODataWriterTestWrapper(ODataWriter writer, WriterTestConfiguration testConfiguration)
{
ExceptionUtilities.CheckArgumentNotNull(writer, "writer");
ExceptionUtilities.CheckArgumentNotNull(testConfiguration, "testConfiguration");
this.writer = writer;
this.testConfiguration = testConfiguration;
}
示例7: 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="entitySet">The entity set 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="expandedNavigationProperties">A list of navigation property names to expand.</param>
public static void WriteEntry(ODataWriter writer, object element, IEdmEntitySet entitySet, IEdmModel model, ODataVersion targetVersion, IEnumerable<string> expandedNavigationProperties)
{
var entry = ODataObjectModelConverter.ConvertToODataEntry(element, entitySet, targetVersion);
writer.WriteStart(entry);
// Here, we write out the links for the navigation properties off of the entity type
WriteNavigationLinks(writer, element, entry.ReadLink, entitySet.EntityType(), model, targetVersion, expandedNavigationProperties);
writer.WriteEnd();
}
示例8: WriteFeed
/// <summary>
/// Writes an OData feed.
/// </summary>
/// <param name="writer">The ODataWriter that will write the feed.</param>
/// <param name="entries">The items from the data store to write to the feed.</param>
/// <param name="entitySet">The entity set in the model that the feed belongs to.</param>
/// <param name="model">The data store model.</param>
/// <param name="targetVersion">The OData version this segment is targeting.</param>
/// <param name="expandedNavigationProperties">A list of navigation property names to expand.</param>
public static void WriteFeed(ODataWriter writer, IEnumerable entries, IEdmEntitySet entitySet, IEdmModel model, ODataVersion targetVersion, IEnumerable<string> expandedNavigationProperties)
{
var feed = new ODataFeed {Id = new Uri(ServiceConstants.ServiceBaseUri, entitySet.Name)};
writer.WriteStart(feed);
foreach (var element in entries)
{
WriteEntry(writer, element, entitySet, model, targetVersion, expandedNavigationProperties);
}
writer.WriteEnd();
}
示例9: WritePayload
/// <summary>
/// Write the <paramref name="element"/> payload element to the <paramref name="writer"/> OData writer.
/// </summary>
/// <param name="writer">The OData writer to write to.</param>
/// <param name="element">The element to write.</param>
public void WritePayload(ODataWriter writer, ODataPayloadElement element)
{
this.writer = writer;
try
{
base.Recurse(element);
this.writer.Flush();
}
finally
{
this.writer = null;
}
}
示例10: WriteEntry
private static void WriteEntry(ODataWriter writer, object entity, IEnumerable<string> projectedProperties)
{
var entry = new ODataEntry()
{
Id = new Uri("http://temp.org/" + Guid.NewGuid()),
SerializationInfo = MySerializationInfo
};
if (projectedProperties != null)
{
entry.SetAnnotation<ProjectedPropertiesAnnotation>(new ProjectedPropertiesAnnotation(projectedProperties));
}
entry.Properties = entity.GetType().GetProperties().Select(p => new ODataProperty() { Name = p.Name, Value = p.GetValue(entity, null) });
writer.WriteStart(entry);
writer.WriteEnd();
}
示例11: WriteEntry
private void WriteEntry(object graph, ODataWriter writer, ODataSerializerContext writeContext)
{
Contract.Assert(writeContext != null);
IEdmEntityTypeReference entityType = GetEntityType(graph, writeContext);
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(writeContext, entityType, graph);
SelectExpandNode selectExpandNode = CreateSelectExpandNode(entityInstanceContext);
if (selectExpandNode != null)
{
ODataEntry entry = CreateEntry(selectExpandNode, entityInstanceContext);
if (entry != null)
{
writer.WriteStart(entry);
WriteNavigationLinks(selectExpandNode.SelectedNavigationProperties, entityInstanceContext, writer);
WriteExpandedNavigationProperties(selectExpandNode.ExpandedNavigationProperties, entityInstanceContext, writer);
writer.WriteEnd();
}
}
}
示例12: WriteNavigationLinks
private static void WriteNavigationLinks(ODataWriter writer, object element, Uri parentEntryUri, IEdmEntityType parentEntityType, IEdmModel model, ODataVersion targetVersion, IEnumerable<string> expandedNavigationProperties)
{
foreach (var navigationProperty in parentEntityType.NavigationProperties())
{
IEdmTypeReference propertyTypeReference = navigationProperty.Type;
bool isCollection = navigationProperty.Type.IsCollection();
var navigationLink = new ODataNavigationLink
{
Url = new Uri(parentEntryUri, navigationProperty.Name),
IsCollection = isCollection,
Name = navigationProperty.Name,
};
writer.WriteStart(navigationLink);
if (expandedNavigationProperties.Contains(navigationProperty.Name))
{
var propertyValue = DataContext.GetPropertyValue(element, navigationProperty.Name);
if (propertyValue != null)
{
var propertyEntityType = propertyTypeReference.Definition as IEdmEntityType;
IEdmEntitySet targetEntitySet = model.EntityContainer.EntitySets().Single(s => s.EntityType() == propertyEntityType);
if (isCollection)
{
WriteFeed(writer, propertyValue as IEnumerable, targetEntitySet, model, targetVersion, Enumerable.Empty<string>());
}
else
{
WriteEntry(writer, propertyValue, targetEntitySet, model, targetVersion, Enumerable.Empty<string>());
}
}
}
writer.WriteEnd();
}
}
示例13: WriteObjectInline
/// <inheritdoc />
public override void WriteObjectInline(object graph, IEdmTypeReference expectedType, ODataWriter writer,
ODataSerializerContext writeContext)
{
if (writer == null)
{
throw Error.ArgumentNull("writer");
}
if (writeContext == null)
{
throw Error.ArgumentNull("writeContext");
}
if (graph == null)
{
throw new SerializationException(Error.Format(Properties.SRResources.CannotSerializerNull, Entry));
}
else
{
WriteEntry(graph, writer, writeContext);
}
}
示例14: WriteNavigationLinks
private void WriteNavigationLinks(
IEnumerable<IEdmNavigationProperty> navigationProperties, EntityInstanceContext entityInstanceContext, ODataWriter writer)
{
Contract.Assert(entityInstanceContext != null);
IEnumerable<ODataNavigationLink> navigationLinks = CreateNavigationLinks(navigationProperties, entityInstanceContext);
foreach (ODataNavigationLink navigationLink in navigationLinks)
{
writer.WriteStart(navigationLink);
writer.WriteEnd();
}
}
示例15: WriteLinkAsync
private async Task WriteLinkAsync(ODataWriter entryWriter, Microsoft.OData.Core.ODataEntry entry, string linkName, IEnumerable<ReferenceLink> links)
{
var navigationProperty = (_model.FindDeclaredType(entry.TypeName) as IEdmEntityType).NavigationProperties()
.BestMatch(x => x.Name, linkName, _session.Pluralizer);
bool isCollection = navigationProperty.Type.Definition.TypeKind == EdmTypeKind.Collection;
var linkType = GetNavigationPropertyEntityType(navigationProperty);
var linkTypeWithKey = linkType;
while (linkTypeWithKey.DeclaredKey == null && linkTypeWithKey.BaseEntityType() != null)
{
linkTypeWithKey = linkTypeWithKey.BaseEntityType();
}
await entryWriter.WriteStartAsync(new ODataNavigationLink()
{
Name = linkName,
IsCollection = isCollection,
Url = new Uri(ODataNamespace.Related + linkType, UriKind.Absolute),
});
foreach (var referenceLink in links)
{
var linkKey = linkTypeWithKey.DeclaredKey;
var linkEntry = referenceLink.LinkData.ToDictionary();
var contentId = GetContentId(referenceLink);
string linkUri;
if (contentId != null)
{
linkUri = "$" + contentId;
}
else
{
bool isSingleton;
var formattedKey = _session.Adapter.GetCommandFormatter().ConvertKeyValuesToUriLiteral(
linkKey.ToDictionary(x => x.Name, x => linkEntry[x.Name]), true);
var linkedCollectionName = _session.Metadata.GetLinkedCollectionName(
referenceLink.LinkData.GetType().Name, linkTypeWithKey.Name, out isSingleton);
linkUri = linkedCollectionName + (isSingleton ? string.Empty : formattedKey);
}
var link = new ODataEntityReferenceLink
{
Url = Utils.CreateAbsoluteUri(_session.Settings.BaseUri.AbsoluteUri, linkUri)
};
await entryWriter.WriteEntityReferenceLinkAsync(link);
}
await entryWriter.WriteEndAsync();
}