本文整理汇总了C#中Microsoft.Data.OData.ODataEntry类的典型用法代码示例。如果您正苦于以下问题:C# ODataEntry类的具体用法?C# ODataEntry怎么用?C# ODataEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataEntry类属于Microsoft.Data.OData命名空间,在下文中一共展示了ODataEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MaterializerEntry
private MaterializerEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion)
{
this.entry = entry;
this.entityDescriptor = new System.Data.Services.Client.EntityDescriptor(maxProtocolVersion);
SerializationTypeNameAnnotation annotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
this.entityDescriptor.ServerTypeName = (annotation != null) ? annotation.TypeName : (this.entityDescriptor.ServerTypeName = this.Entry.TypeName);
}
示例2: EntryPropertiesValueCache
internal EntryPropertiesValueCache(ODataEntry entry)
{
if (entry.Properties != null)
{
this.entryPropertiesCache = new List<ODataProperty>(entry.Properties);
}
}
示例3: TryAnnotateV2FeedPackage
private void TryAnnotateV2FeedPackage(ODataEntry entry, EntityInstanceContext entityInstanceContext)
{
var instance = entityInstanceContext.EntityInstance as V2FeedPackage;
if (instance != null)
{
// Set Atom entry metadata
var atomEntryMetadata = new AtomEntryMetadata();
atomEntryMetadata.Title = instance.Id;
if (!string.IsNullOrEmpty(instance.Authors))
{
atomEntryMetadata.Authors = new[] { new AtomPersonMetadata { Name = instance.Authors } };
}
if (instance.LastUpdated > DateTime.MinValue)
{
atomEntryMetadata.Updated = instance.LastUpdated;
}
if (!string.IsNullOrEmpty(instance.Summary))
{
atomEntryMetadata.Summary = instance.Summary;
}
entry.SetAnnotation(atomEntryMetadata);
// Add package download link
entry.MediaResource = new ODataStreamReferenceValue
{
ContentType = ContentType,
ReadLink = BuildLinkForStreamProperty("v2", instance.Id, instance.Version, entityInstanceContext.Request)
};
}
}
示例4: EndEntry
protected override void EndEntry(ODataEntry entry)
{
if (entry != null)
{
ProjectedPropertiesAnnotation projectedProperties = entry.GetAnnotation<ProjectedPropertiesAnnotation>();
this.jsonEntryAndFeedSerializer.WriteProperties(base.EntryEntityType, entry.Properties, false, base.DuplicatePropertyNamesChecker, projectedProperties);
this.jsonOutputContext.JsonWriter.EndObjectScope();
}
}
示例5: ConvertFeed
public void ConvertFeed(Uri relativeODataUri, Uri relativeSodaUri, JsonPayload jsonPayload,
DateTimeOffset feedUpdateTime)
{
var jsonObject = jsonPayload.JsonObject;
var entries = jsonObject.PropertyValue<JArray>("entries");
var meta = jsonObject.PropertyValue<JObject>("meta");
var view = meta.PropertyValue<JObject>("view");
IList<string> fieldsToIgnore;
var model = BuildModel(view, out fieldsToIgnore);
var entitySet = model.EntityContainers.Single().EntitySets().Single();
var settings = new ODataMessageWriterSettings
{
Indent = true,
};
using (var writer = new ODataMessageWriter(Message, settings, model))
{
var feedWriter = writer.CreateODataFeedWriter();
var feed = new ODataFeed();
feed.SetAnnotation(new AtomFeedMetadata
{
Updated = feedUpdateTime,
});
feed.Id = new Uri(ODataEndpointUri, relativeODataUri.OriginalString).OriginalString;
feedWriter.WriteStart(feed);
foreach (var entry in entries.Cast<JObject>())
{
var entryMetadata = new ODataEntry();
entryMetadata.Id = (string) ((JValue) entry.Property("id").Value).Value;
entryMetadata.TypeName = entitySet.ElementType.FullName();
entryMetadata.Properties = ConvertProperties(entry, fieldsToIgnore);
entryMetadata.SetAnnotation(new AtomEntryMetadata
{
Updated = ConvertDateTimeOffset(entry.PrimitivePropertyValue<long>("updated_at")),
Published = ConvertDateTimeOffset(entry.PrimitivePropertyValue<long>("created_at")),
});
feedWriter.WriteStart(entryMetadata);
feedWriter.WriteEnd();
}
feedWriter.WriteEnd();
}
}
示例6: StartEntry
protected override void StartEntry(ODataEntry entry)
{
if (entry == null)
{
this.jsonOutputContext.JsonWriter.WriteValue((string) null);
}
else
{
this.jsonOutputContext.JsonWriter.StartObjectScope();
ProjectedPropertiesAnnotation projectedProperties = entry.GetAnnotation<ProjectedPropertiesAnnotation>();
this.jsonEntryAndFeedSerializer.WriteEntryMetadata(entry, projectedProperties, base.EntryEntityType, base.DuplicatePropertyNamesChecker);
}
}
示例7: CreateEntry
public static MaterializerEntry CreateEntry(ODataEntry entry, DataServiceProtocolVersion maxProtocolVersion)
{
MaterializerEntry annotation = new MaterializerEntry(entry, maxProtocolVersion);
entry.SetAnnotation<MaterializerEntry>(annotation);
if (entry.Id == null)
{
throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Deserialize_MissingIdElement);
}
annotation.EntityDescriptor.Identity = entry.Id;
annotation.EntityDescriptor.EditLink = entry.EditLink;
annotation.EntityDescriptor.SelfLink = entry.ReadLink;
annotation.EntityDescriptor.ETag = entry.ETag;
return annotation;
}
示例8: ODataResponse
ODataResponse IODataView.CreateView()
{
var oDataResponse = new ODataResponse();
var messageWriter = new ODataMessageWriter(oDataResponse);
var entryWriter = messageWriter.CreateODataFeedWriter();
var feed = new ODataFeed() { Count = Videos.Count, Id = "Hypermedia-Learning" };
var atomFeed = feed.Atom();
atomFeed.Title = "Hypermedia API - " + PageTitle;
entryWriter.WriteStart(feed);
foreach (var video in Videos)
{
var oDataEntry = new ODataEntry() {};
var atom = oDataEntry.Atom();
atom.Title = "Video : " + video.Link.Title;
atom.Summary = video.Description;
entryWriter.WriteStart(oDataEntry);
entryWriter.WriteEnd();
}
foreach (var item in Community)
{
var oDataEntry = new ODataEntry() { };
var atom = oDataEntry.Atom();
atom.Title = "Community : " + item.Link.Title;
atom.Summary = item.Description;
entryWriter.WriteStart(oDataEntry);
entryWriter.WriteEnd();
}
entryWriter.WriteEnd();
entryWriter.Flush();
oDataResponse.GetStream().Position = 0;
return oDataResponse;
}
示例9: WriteEntry
private void WriteEntry(object graph, IEnumerable<ODataProperty> propertyBag, ODataWriter writer, ODataSerializerContext writeContext)
{
IEdmEntityType entityType = _edmEntityTypeReference.EntityDefinition();
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(SerializerProvider.EdmModel, writeContext.EntitySet, entityType, writeContext.UrlHelper, graph, writeContext.SkipExpensiveAvailabilityChecks);
ODataEntry entry = new ODataEntry
{
TypeName = _edmEntityTypeReference.FullName(),
Properties = propertyBag,
Actions = CreateActions(entityInstanceContext)
};
if (writeContext.EntitySet != null)
{
IEntitySetLinkBuilder linkBuilder = SerializerProvider.EdmModel.GetEntitySetLinkBuilder(writeContext.EntitySet);
string idLink = linkBuilder.BuildIdLink(entityInstanceContext);
if (idLink != null)
{
entry.Id = idLink;
}
Uri readLink = linkBuilder.BuildReadLink(entityInstanceContext);
if (readLink != null)
{
entry.ReadLink = readLink;
}
Uri editLink = linkBuilder.BuildEditLink(entityInstanceContext);
if (editLink != null)
{
entry.EditLink = editLink;
}
}
writer.WriteStart(entry);
WriteNavigationLinks(entityInstanceContext, writer, writeContext);
writer.WriteEnd();
}
示例10: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataEntry entry, IEdmEntitySet entitySet,
ODataMetadataLevel metadataLevel)
{
// ODataLib normally has the caller decide whether or not to serialize properties by leaving properties
// null when values should not be serialized. The TypeName property is different and should always be
// provided to ODataLib to enable model validation. A separate annotation is used to decide whether or not
// to serialize the type name (a null value prevents serialization).
// Note that this annotation should not be used for Atom or JSON verbose formats, as it will interfere with
// the correct default behavior for those formats.
Contract.Assert(entry != null);
// Only add an annotation if we want to override ODataLib's default type name serialization behavior.
if (ShouldAddTypeNameAnnotation(metadataLevel))
{
string typeName;
// Provide the type name to serialize (or null to force it not to serialize).
if (ShouldSuppressTypeNameSerialization(entry, entitySet, metadataLevel))
{
typeName = null;
}
else
{
typeName = entry.TypeName;
}
entry.SetAnnotation<SerializationTypeNameAnnotation>(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
}
示例11: WriteOdataEntity
private static void WriteOdataEntity(ITableEntity entity, TableOperationType operationType, OperationContext ctx, ODataWriter writer, TableRequestOptions options)
{
ODataEntry entry = new ODataEntry()
{
Properties = GetPropertiesWithKeys(entity, ctx, operationType, options),
TypeName = "account.sometype"
};
entry.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = null });
writer.WriteStart(entry);
writer.WriteEnd();
writer.Flush();
}
示例12: CreateEntry
/// <summary>
/// Creates the <see cref="ODataEntry"/> to be written while writing this entity.
/// </summary>
/// <param name="selectExpandNode">The <see cref="SelectExpandNode"/> describing the response graph.</param>
/// <param name="entityInstanceContext">The context for the entity instance being written.</param>
/// <returns>The created <see cref="ODataEntry"/>.</returns>
public virtual ODataEntry CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)
{
if (selectExpandNode == null)
{
throw Error.ArgumentNull("selectExpandNode");
}
if (entityInstanceContext == null)
{
throw Error.ArgumentNull("entityInstanceContext");
}
string typeName = EntityType.FullName();
ODataEntry entry = new ODataEntry
{
TypeName = typeName,
Properties = CreateStructuralPropertyBag(selectExpandNode.SelectedStructuralProperties, entityInstanceContext),
Actions = CreateODataActions(selectExpandNode.SelectedActions, entityInstanceContext)
};
AddTypeNameAnnotationAsNeeded(entry, entityInstanceContext.EntitySet, entityInstanceContext.SerializerContext.MetadataLevel);
if (entityInstanceContext.EntitySet != null)
{
IEdmModel model = entityInstanceContext.SerializerContext.Model;
EntitySetLinkBuilderAnnotation linkBuilder = model.GetEntitySetLinkBuilder(entityInstanceContext.EntitySet);
EntitySelfLinks selfLinks = linkBuilder.BuildEntitySelfLinks(entityInstanceContext, entityInstanceContext.SerializerContext.MetadataLevel);
if (selfLinks.IdLink != null)
{
entry.Id = selfLinks.IdLink;
}
if (selfLinks.ReadLink != null)
{
entry.ReadLink = selfLinks.ReadLink;
}
if (selfLinks.EditLink != null)
{
entry.EditLink = selfLinks.EditLink;
}
}
return entry;
}
示例13: AddTypeNameAnnotationAsNeeded_AddsAnnotation_InJsonLightMetadataMode
public void AddTypeNameAnnotationAsNeeded_AddsAnnotation_InJsonLightMetadataMode()
{
// Arrange
string expectedTypeName = "TypeName";
ODataEntry entry = new ODataEntry
{
TypeName = expectedTypeName
};
// Act
ODataEntityTypeSerializer.AddTypeNameAnnotationAsNeeded(entry, null, ODataMetadataLevel.MinimalMetadata);
// Assert
SerializationTypeNameAnnotation annotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
Assert.NotNull(annotation); // Guard
Assert.Equal(expectedTypeName, annotation.TypeName);
}
示例14: WriteObjectInline_WritesODataEntryFrom_CreateEntry
public void WriteObjectInline_WritesODataEntryFrom_CreateEntry()
{
// Arrange
ODataEntry entry = new ODataEntry();
Mock<ODataEntityTypeSerializer> serializer = new Mock<ODataEntityTypeSerializer>(_serializer.EdmType, _serializerProvider);
Mock<ODataWriter> writer = new Mock<ODataWriter>();
serializer.Setup(s => s.CreateEntry(It.IsAny<SelectExpandNode>(), It.IsAny<EntityInstanceContext>())).Returns(entry);
serializer.CallBase = true;
writer.Setup(s => s.WriteStart(entry)).Verifiable();
// Act
serializer.Object.WriteObjectInline(_customer, writer.Object, _writeContext);
// Assert
writer.Verify();
}
示例15: VerifyCanWriteStartEntry
/// <summary>
/// Verifies that calling WriteStart entry is valid.
/// </summary>
/// <param name="synchronousCall">true if the call is to be synchronous; false otherwise.</param>
/// <param name="entry">Entry/item to write.</param>
private void VerifyCanWriteStartEntry(bool synchronousCall, ODataEntry entry)
{
this.VerifyNotDisposed();
this.VerifyCallAllowed(synchronousCall);
if (this.State != WriterState.NavigationLink)
{
ExceptionUtils.CheckArgumentNotNull(entry, "entry");
}
}