/// <summary> /// Creates a text ATOM value. /// </summary> /// <param name="textValue">The text value to use.</param> /// <param name="contentKind">The content kind of the value.</param> /// <returns>The Atom text value.</returns> private static AtomTextConstruct CreateAtomTextConstruct(string textValue, SyndicationTextContentKind contentKind) { AtomTextConstructKind kind; switch (contentKind) { case SyndicationTextContentKind.Plaintext: kind = AtomTextConstructKind.Text; break; case SyndicationTextContentKind.Html: kind = AtomTextConstructKind.Html; break; case SyndicationTextContentKind.Xhtml: kind = AtomTextConstructKind.Xhtml; break; default: throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_CreateAtomTextConstruct)); } return(new AtomTextConstruct { Kind = kind, Text = textValue, }); }
private static AtomTextConstruct CreateAtomTextConstruct(string textValue, SyndicationTextContentKind contentKind, ODataVersion version) { // If V3 serialization is enabled write null values by adding the m:null="true" attribute. if (textValue == null && version >= ODataVersion.V3) { // Add the m:null attribute on the value } AtomTextConstructKind kind; switch (contentKind) { case SyndicationTextContentKind.Plaintext: kind = AtomTextConstructKind.Text; break; case SyndicationTextContentKind.Html: kind = AtomTextConstructKind.Html; break; case SyndicationTextContentKind.Xhtml: kind = AtomTextConstructKind.Xhtml; break; default: throw new ODataException(Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_CreateAtomTextConstruct)); } return(new AtomTextConstruct() { Kind = kind, Text = textValue }); }
/// <summary> /// Given the string representation in <paramref name="strContentKind"/> gets back the corresponding enumerated value /// </summary> /// <param name="strContentKind">String representation of syndication content kind e.g. plaintext, html or xhtml</param> /// <param name="typeName">Type to which the property belongs</param> /// <param name="memberName">Name of the member whose extended properties we are searching from</param> /// <returns>Enumerated value of SyndicationTextContentKind</returns> private static SyndicationTextContentKind MapEpmContentKindToSyndicationTextContentKind(String strContentKind, String typeName, String memberName) { SyndicationTextContentKind contentKind = SyndicationTextContentKind.Plaintext; switch (strContentKind) { case System.Data.Services.XmlConstants.SyndContentKindPlaintext: contentKind = SyndicationTextContentKind.Plaintext; break; case System.Data.Services.XmlConstants.SyndContentKindHtml: contentKind = SyndicationTextContentKind.Html; break; case System.Data.Services.XmlConstants.SyndContentKindXHtml: contentKind = SyndicationTextContentKind.Xhtml; break; default: throw new InvalidOperationException(memberName == null ? Strings.ObjectContext_InvalidValueForTargetTextContentKindPropertyType(strContentKind, typeName) : Strings.ObjectContext_InvalidValueForTargetTextContentKindPropertyMember(strContentKind, memberName, typeName)); } return(contentKind); }
public EntityPropertyMappingAttribute(string sourcePath, string targetPath, string targetNamespacePrefix, string targetNamespaceUri, bool keepInContent) { Uri uri; if (string.IsNullOrEmpty(sourcePath)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("sourcePath")); } this.sourcePath = sourcePath; if (string.IsNullOrEmpty(targetPath)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("targetPath")); } if (targetPath[0] == '@') { throw new ArgumentException(Strings.EntityPropertyMapping_InvalidTargetPath(targetPath)); } this.targetPath = targetPath; this.targetSyndicationItem = SyndicationItemProperty.CustomProperty; this.targetTextContentKind = SyndicationTextContentKind.Plaintext; this.targetNamespacePrefix = targetNamespacePrefix; if (string.IsNullOrEmpty(targetNamespaceUri)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("targetNamespaceUri")); } this.targetNamespaceUri = targetNamespaceUri; if (!Uri.TryCreate(targetNamespaceUri, UriKind.Absolute, out uri)) { throw new ArgumentException(Strings.EntityPropertyMapping_TargetNamespaceUriNotValid(targetNamespaceUri)); } this.keepInContent = keepInContent; }
private static string ToAttributeValue(this SyndicationTextContentKind contentKind) { switch (contentKind) { case SyndicationTextContentKind.Html: return("html"); case SyndicationTextContentKind.Xhtml: return("xhtml"); } return("text"); }
internal static string MapSyndicationTextContentKindToEpmContentKind(SyndicationTextContentKind contentKind) { switch (contentKind) { case SyndicationTextContentKind.Plaintext: return "text"; case SyndicationTextContentKind.Html: return "html"; } return "xhtml"; }
internal static string MapSyndicationTextContentKindToEpmContentKind(SyndicationTextContentKind contentKind) { switch (contentKind) { case SyndicationTextContentKind.Plaintext: return("text"); case SyndicationTextContentKind.Html: return("html"); } return("xhtml"); }
public EntityPropertyMappingAttribute(string sourcePath, SyndicationItemProperty targetSyndicationItem, SyndicationTextContentKind targetTextContentKind, bool keepInContent) { if (string.IsNullOrEmpty(sourcePath)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("sourcePath")); } this.sourcePath = sourcePath; this.targetPath = targetSyndicationItem.ToTargetPath(); this.targetSyndicationItem = targetSyndicationItem; this.targetTextContentKind = targetTextContentKind; this.targetNamespacePrefix = "atom"; this.targetNamespaceUri = "http://www.w3.org/2005/Atom"; this.keepInContent = keepInContent; }
/// <summary> /// Creates a Syndication EPM annotation on the <paramref name="annotatable"/>. /// </summary> /// <typeparam name="T">The type of the annotatable being passed in.</typeparam> /// <param name="annotatable">The annotatable to add the EPM annotation to.</param> /// <param name="sourcePath">The source path to be used in the mapping.</param> /// <param name="targetSyndicationItem">The syndication item to be used in the mapping (defaults to AuthorName).</param> /// <param name="targetTextContentKind">The target content kind (defaults to plain text).</param> /// <param name="keepInContent">true to keep the mapped value in content; otherwise false (defaults to true).</param> /// <returns>The <paramref name="annotatable"/> being passed in for composability.</returns> public static T EntityPropertyMapping <T>( this T annotatable, string sourcePath, SyndicationItemProperty targetSyndicationItem = SyndicationItemProperty.AuthorName, SyndicationTextContentKind targetTextContentKind = SyndicationTextContentKind.Plaintext, bool keepInContent = true) where T : AnnotatedItem { ExceptionUtilities.CheckArgumentNotNull(annotatable, "annotatable"); ExceptionUtilities.CheckArgumentNotNull(sourcePath, "sourcePath"); ExceptionUtilities.Assert(annotatable is EntityType, "Entity Property Mappings should only be applied to entity types"); annotatable.Add(new PropertyMappingAnnotation(sourcePath, targetSyndicationItem, targetTextContentKind, keepInContent)); return(annotatable); }
public EntityPropertyMappingAttribute(String sourcePath, SyndicationItemProperty targetSyndicationItem, SyndicationTextContentKind targetTextContentKind, bool keepInContent) { if (String.IsNullOrEmpty(sourcePath)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("sourcePath")); } this.sourcePath = sourcePath; this.targetPath = SyndicationItemPropertyToPath(targetSyndicationItem); this.targetSyndicationItem = targetSyndicationItem; this.targetTextContentKind = targetTextContentKind; this.targetNamespacePrefix = EntityPropertyMappingAttribute.AtomNamespacePrefix; this.targetNamespaceUri = XmlConstants.AtomNamespace; this.keepInContent = keepInContent; }
/// <summary> /// Used for mapping a resource property to syndication content /// </summary> /// <param name="sourcePath">Source property path</param> /// <param name="targetSyndicationItem">Syndication item to which the <see cref="sourcePath"/> is mapped</param> /// <param name="targetTextContentKind">Syndication content kind for <see cref="targetSyndicationItem"/></param> /// <param name="keepInContent">If true the property value is kept in the content section as before, /// when false the property value is only placed at the mapped location</param> public EntityPropertyMappingAttribute(String sourcePath, SyndicationItemProperty targetSyndicationItem, SyndicationTextContentKind targetTextContentKind, bool keepInContent) { if (String.IsNullOrEmpty(sourcePath)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("sourcePath")); } this.sourcePath = sourcePath; this.targetPath = SyndicationItemPropertyToPath(targetSyndicationItem); this.targetSyndicationItem = targetSyndicationItem; this.targetTextContentKind = targetTextContentKind; this.targetNamespacePrefix = EntityPropertyMappingAttribute.AtomNamespacePrefix; this.targetNamespaceUri = XmlConstants.AtomNamespace; this.keepInContent = keepInContent; }
/// <summary> /// Returns the value of the attribute for the given text content kind /// </summary> /// <param name="textKind">the text content kind</param> /// <returns>The value of the attribute</returns> public static string ToAttributeString(this SyndicationTextContentKind textKind) { if (textKind == SyndicationTextContentKind.Plaintext) { return("text"); } else if (textKind == SyndicationTextContentKind.Html) { return("html"); } else { ExceptionUtilities.Assert(textKind == SyndicationTextContentKind.Xhtml, "Unrecognized syndication text content kind: '{0}'", textKind); return("xhtml"); } }
private static EntityPropertyMappingAttribute ValidateAnnotationValues(EpmAnnotationValues annotationValues, string typeName, IEdmProperty property) { if (annotationValues.TargetPath == null) { string str = "FC_TargetPath" + annotationValues.AttributeSuffix; string message = (property == null) ? Microsoft.Data.OData.Strings.EpmExtensionMethods_MissingAttributeOnType(str, typeName) : Microsoft.Data.OData.Strings.EpmExtensionMethods_MissingAttributeOnProperty(str, property.Name, typeName); throw new ODataException(message); } bool result = true; if ((annotationValues.KeepInContent != null) && !bool.TryParse(annotationValues.KeepInContent, out result)) { string str3 = "FC_KeepInContent" + annotationValues.AttributeSuffix; throw new InvalidOperationException((property == null) ? Microsoft.Data.OData.Strings.EpmExtensionMethods_InvalidKeepInContentOnType(str3, typeName) : Microsoft.Data.OData.Strings.EpmExtensionMethods_InvalidKeepInContentOnProperty(str3, property.Name, typeName)); } SyndicationItemProperty targetSyndicationItem = MapTargetPathToSyndicationProperty(annotationValues.TargetPath); if (targetSyndicationItem == SyndicationItemProperty.CustomProperty) { if (annotationValues.ContentKind != null) { string str4 = "FC_ContentKind" + annotationValues.AttributeSuffix; string str5 = (property == null) ? Microsoft.Data.OData.Strings.EpmExtensionMethods_AttributeNotAllowedForCustomMappingOnType(str4, typeName) : Microsoft.Data.OData.Strings.EpmExtensionMethods_AttributeNotAllowedForCustomMappingOnProperty(str4, property.Name, typeName); throw new ODataException(str5); } return(new EntityPropertyMappingAttribute(annotationValues.SourcePath, annotationValues.TargetPath, annotationValues.NamespacePrefix, annotationValues.NamespaceUri, result)); } if (annotationValues.NamespaceUri != null) { string str6 = "FC_NsUri" + annotationValues.AttributeSuffix; string str7 = (property == null) ? Microsoft.Data.OData.Strings.EpmExtensionMethods_AttributeNotAllowedForAtomPubMappingOnType(str6, typeName) : Microsoft.Data.OData.Strings.EpmExtensionMethods_AttributeNotAllowedForAtomPubMappingOnProperty(str6, property.Name, typeName); throw new ODataException(str7); } if (annotationValues.NamespacePrefix != null) { string str8 = "FC_NsPrefix" + annotationValues.AttributeSuffix; string str9 = (property == null) ? Microsoft.Data.OData.Strings.EpmExtensionMethods_AttributeNotAllowedForAtomPubMappingOnType(str8, typeName) : Microsoft.Data.OData.Strings.EpmExtensionMethods_AttributeNotAllowedForAtomPubMappingOnProperty(str8, property.Name, typeName); throw new ODataException(str9); } SyndicationTextContentKind plaintext = SyndicationTextContentKind.Plaintext; if (annotationValues.ContentKind != null) { plaintext = MapContentKindToSyndicationTextContentKind(annotationValues.ContentKind, annotationValues.AttributeSuffix, typeName, (property == null) ? null : property.Name); } return(new EntityPropertyMappingAttribute(annotationValues.SourcePath, targetSyndicationItem, plaintext, result)); }
/// <summary> /// Applies EPM mapping to the specified entity type on the model and returns it for composablity. /// </summary> /// <param name="model">Model to use</param> /// <param name="entityTypeName">Entity type name</param> /// <param name="sourcePath">Source path</param> /// <param name="targetSyndicationItem">TargetSyndicationItem to use</param> /// <param name="targetTextContentKind">TargetTextContentKind to use</param> /// <param name="keepInContent">true to keep the mapped value in content; otherwise false (defaults to true).</param> /// <returns>Enity Model Schema with the mapping applied</returns> public static EntityModelSchema EntityPropertyMapping( this EntityModelSchema model, string entityTypeName, string sourcePath, SyndicationItemProperty targetSyndicationItem = SyndicationItemProperty.AuthorName, SyndicationTextContentKind targetTextContentKind = SyndicationTextContentKind.Plaintext, bool keepInContent = true) { ExceptionUtilities.CheckArgumentNotNull(model, "model"); ExceptionUtilities.CheckArgumentNotNull(entityTypeName, "entityTypeName"); ExceptionUtilities.CheckArgumentNotNull(sourcePath, "sourcePath"); var entityType = model.GetEntityType(entityTypeName); ExceptionUtilities.CheckObjectNotNull(entityType, "There are no entity types matching the name:{0} in the model", entityTypeName); entityType.EntityPropertyMapping(sourcePath, targetSyndicationItem, targetTextContentKind, keepInContent); return(model); }
/// <summary> /// Used for conditional mapping to atom:link[@href] and atom:category[@term]. /// </summary> /// <param name="sourcePath">Source property path.</param> /// <param name="targetSyndicationItem">Syndication item to which the <see cref="sourcePath"/> is mapped.</param> /// <param name="keepInContent">If true the property value is kept in the content section as before, /// when false the property value is only placed at the mapped location.</param> /// <param name="criteriaValue">Criteria value that is used as a condition.</param> public EntityPropertyMappingAttribute(String sourcePath, SyndicationItemProperty targetSyndicationItem, bool keepInContent, String criteriaValue) { if (String.IsNullOrEmpty(sourcePath)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("sourcePath")); } this.sourcePath = sourcePath; if (String.IsNullOrEmpty(criteriaValue)) { throw new ArgumentException(Strings.EntityPropertyMapping_EpmAttribute("criteriaValue")); } this.criteriaValue = criteriaValue; this.targetPath = SyndicationItemPropertyToPath(targetSyndicationItem); this.targetSyndicationItem = targetSyndicationItem; this.targetTextContentKind = SyndicationTextContentKind.Plaintext; this.targetNamespacePrefix = AtomConstants.NonEmptyAtomNamespacePrefix; this.targetNamespaceUri = AtomConstants.AtomNamespace; this.keepInContent = keepInContent; }
private static AtomTextConstruct CreateAtomTextConstruct(string textValue, SyndicationTextContentKind contentKind) { AtomTextConstructKind text; switch (contentKind) { case SyndicationTextContentKind.Plaintext: text = AtomTextConstructKind.Text; break; case SyndicationTextContentKind.Html: text = AtomTextConstructKind.Html; break; case SyndicationTextContentKind.Xhtml: text = AtomTextConstructKind.Xhtml; break; default: throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_CreateAtomTextConstruct)); } return new AtomTextConstruct { Kind = text, Text = textValue }; }
public PropertyMappingAnnotation( string sourcePath, SyndicationItemProperty targetSyndicationItem, SyndicationTextContentKind targetTextContentKind, bool keepInContent) : this(sourcePath, keepInContent) { this.SyndicationItemProperty = targetSyndicationItem; this.SyndicationTextContentKind = targetTextContentKind; this.TargetPath = targetSyndicationItem.ToString().ToLowerInvariant(); if (this.TargetPath.StartsWith(ODataConstants.AuthorElementName, StringComparison.Ordinal)) { this.TargetPath = this.TargetPath.Insert(ODataConstants.AuthorElementName.Length, "/"); } else if (this.TargetPath.StartsWith(ODataConstants.ContributorElementName, StringComparison.Ordinal)) { this.TargetPath = this.TargetPath.Insert(ODataConstants.ContributorElementName.Length, "/"); } this.TargetNamespacePrefix = null; this.TargetNamespaceUri = ODataConstants.AtomNamespaceName; }
private static AtomTextConstruct CreateAtomTextConstruct(string textValue, SyndicationTextContentKind contentKind, ODataVersion version) { // If V3 serialization is enabled write null values by adding the m:null="true" attribute. if (textValue == null && version >= ODataVersion.V3) { // Add the m:null attribute on the value } AtomTextConstructKind kind; switch (contentKind) { case SyndicationTextContentKind.Plaintext: kind = AtomTextConstructKind.Text; break; case SyndicationTextContentKind.Html: kind = AtomTextConstructKind.Html; break; case SyndicationTextContentKind.Xhtml: kind = AtomTextConstructKind.Xhtml; break; default: throw new ODataException(Strings.General_InternalError(InternalErrorCodes.EpmSyndicationWriter_CreateAtomTextConstruct)); } return new AtomTextConstruct() { Kind = kind, Text = textValue }; }
/// <summary> /// Converts test enum SyndicationTextContentKind to product enum. /// </summary> /// <param name="contentKind">test enum value</param> /// <returns>product enum</returns> public static AtomSyndicationTextContentKind ToProductEnum(this SyndicationTextContentKind contentKind) { return(ConvertEnum <SyndicationTextContentKind, AtomSyndicationTextContentKind>(contentKind)); }