本文整理汇总了C#中Microsoft.Data.OData.ODataEntry.SetAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# ODataEntry.SetAnnotation方法的具体用法?C# ODataEntry.SetAnnotation怎么用?C# ODataEntry.SetAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Data.OData.ODataEntry
的用法示例。
在下文中一共展示了ODataEntry.SetAnnotation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
};
}
}
示例2: 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;
}
示例3: 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
});
}
}
示例4: 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();
}
示例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: WriteEntry
internal void WriteEntry(EntityDescriptor entityDescriptor, IEnumerable<LinkDescriptor> relatedLinks, ODataRequestMessageWrapper requestMessage)
{
ClientEdmModel model = ClientEdmModel.GetModel(this.requestInfo.MaxProtocolVersion);
ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType()));
using (ODataMessageWriter writer = CreateMessageWriter(requestMessage, this.requestInfo))
{
ODataWriter odataWriter = writer.CreateODataEntryWriter();
ODataEntry entry = new ODataEntry();
if (this.requestInfo.HasWritingEventHandlers)
{
entry.SetAnnotation<WritingEntityInfo>(new WritingEntityInfo(entityDescriptor.Entity, this.requestInfo));
}
string serverTypeName = this.requestInfo.GetServerTypeName(entityDescriptor);
if (clientTypeAnnotation.ElementTypeName != serverTypeName)
{
SerializationTypeNameAnnotation annotation = new SerializationTypeNameAnnotation {
TypeName = serverTypeName
};
entry.SetAnnotation<SerializationTypeNameAnnotation>(annotation);
}
entry.TypeName = clientTypeAnnotation.ElementTypeName;
if (EntityStates.Modified == entityDescriptor.State)
{
entry.Id = entityDescriptor.GetLatestIdentity();
}
if (entityDescriptor.IsMediaLinkEntry || clientTypeAnnotation.IsMediaLinkEntry)
{
entry.MediaResource = new ODataStreamReferenceValue();
}
odataWriter.WriteStart(entry);
if (EntityStates.Added == entityDescriptor.State)
{
this.WriteNavigationLink(entityDescriptor, relatedLinks, odataWriter);
}
entry.Properties = this.PopulateProperties(clientTypeAnnotation, entityDescriptor.Entity, null);
odataWriter.WriteEnd();
}
}
示例7: EntryXmlCustomizer
private static XmlReader EntryXmlCustomizer(ODataEntry entry, XmlReader entryReader, Uri baseUri)
{
XElement payload = XElement.Load(entryReader.ReadSubtree(), LoadOptions.None);
entryReader.Read();
entry.SetAnnotation<ReadingEntityInfo>(new ReadingEntityInfo(payload, baseUri));
XmlReader reader = payload.CreateReader();
reader.Read();
return reader;
}
示例8: WriteEntry
private void WriteEntry(IExpandedResult expanded, object element, bool resourceInstanceInFeed, ResourceType expectedType)
{
Uri uri;
Func<ProjectionNode, bool> predicate = null;
base.IncrementSegmentResultCount();
ODataEntry entry = new ODataEntry();
AtomEntryMetadata annotation = new AtomEntryMetadata();
entry.SetAnnotation<AtomEntryMetadata>(annotation);
string name = expectedType.Name;
ResourceType actualResourceType = WebUtil.GetNonPrimitiveResourceType(base.Provider, element);
if (actualResourceType.ResourceTypeKind != ResourceTypeKind.EntityType)
{
throw new DataServiceException(500, System.Data.Services.Strings.BadProvider_InconsistentEntityOrComplexTypeUsage(actualResourceType.FullName));
}
Uri absoluteUri = Serializer.GetIdAndEditLink(element, actualResourceType, base.Provider, base.CurrentContainer, base.AbsoluteServiceUri, out uri);
Uri relativeUri = new Uri(absoluteUri.AbsoluteUri.Substring(base.AbsoluteServiceUri.AbsoluteUri.Length), UriKind.Relative);
entry.MediaResource = this.GetMediaResource(element, actualResourceType, name, relativeUri);
entry.TypeName = actualResourceType.FullName;
entry.Id = uri.AbsoluteUri;
entry.EditLink = relativeUri;
AtomLinkMetadata metadata2 = new AtomLinkMetadata {
Title = name
};
annotation.EditLink = metadata2;
string eTagValue = base.GetETagValue(element, actualResourceType);
if (eTagValue != null)
{
entry.ETag = eTagValue;
}
IEnumerable<ProjectionNode> projections = base.GetProjections();
if (projections != null)
{
if (predicate == null)
{
predicate = projectionNode => projectionNode.TargetResourceType.IsAssignableFrom(actualResourceType);
}
projections = projections.Where<ProjectionNode>(predicate);
entry.SetAnnotation<ProjectedPropertiesAnnotation>(new ProjectedPropertiesAnnotation(from p in projections select p.PropertyName));
}
entry.AssociationLinks = this.GetEntityAssociationLinks(actualResourceType, relativeUri, projections);
this.PopulateODataOperations(element, resourceInstanceInFeed, entry, actualResourceType);
this.odataWriter.WriteStart(entry);
this.WriteNavigationProperties(expanded, element, resourceInstanceInFeed, actualResourceType, absoluteUri, relativeUri, projections);
entry.Properties = this.GetEntityProperties(element, actualResourceType, relativeUri, projections);
this.odataWriter.WriteEnd();
}