Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / Epm / EpmHelper.cs / 1305376 / EpmHelper.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides the interface definition for web data service // data sources. // // // @owner [....] //--------------------------------------------------------------------- #if ASTORIA_SERVER namespace System.Data.Services.Providers { using System.Data.Services; #else namespace System.Data.EntityModel.Emitters { using System.Data.Services.Design; #endif using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.EntityClient; using System.Data.Metadata.Edm; using System.Data.Objects; using System.Data.Services.Common; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Text; using System.Xml; ////// This class contains code for translating epm information stored in Metadata properties to objects of EpmPropertyInformation class /// !!! THIS CODE IS USED BY System.Data.Services.Providers.ObjectContextProvider *AND* System.Data.EntityModel.Emitters.AttributeEmitter CLASSES !!! /// #if ASTORIA_SERVER internal partial class ObjectContextServiceProvider #else internal sealed partial class AttributeEmitter #endif { ////// Obtains the epm information for a single property by reading csdl content /// /// Collection of extended metadata properties for a resource /// Type for which we are reading the metadata properties /// Member for which we are reading the metadata properties ///EpmPropertyInformation corresponding to read metadata properties private static IEnumerableGetEpmPropertyInformation(IEnumerable extendedProperties, String typeName, String memberName) { EpmAttributeNameBuilder epmAttributeNameBuilder = new EpmAttributeNameBuilder(); while (true) { bool pathGiven = true; // EpmTargetPath is the only non-optional EPM attribute. If it is declared we need to take care of mapping. MetadataProperty epmTargetPathProperty = FindSingletonExtendedProperty( extendedProperties, epmAttributeNameBuilder.EpmTargetPath, typeName, memberName); if (epmTargetPathProperty != null) { // By default, we keep the copy in content for backwards compatibility bool epmKeepInContent = true; MetadataProperty epmKeepInContentProperty = FindSingletonExtendedProperty( extendedProperties, epmAttributeNameBuilder.EpmKeepInContent, typeName, memberName); if (epmKeepInContentProperty != null) { if (!Boolean.TryParse(Convert.ToString(epmKeepInContentProperty.Value, CultureInfo.InvariantCulture), out epmKeepInContent)) { throw new InvalidOperationException(memberName == null ? Strings.ObjectContext_InvalidValueForEpmPropertyType(epmAttributeNameBuilder.EpmKeepInContent, typeName) : Strings.ObjectContext_InvalidValueForEpmPropertyMember(epmAttributeNameBuilder.EpmKeepInContent, memberName, typeName)); } } MetadataProperty epmSourcePathProperty = FindSingletonExtendedProperty( extendedProperties, epmAttributeNameBuilder.EpmSourcePath, typeName, memberName); String epmSourcePath; if (epmSourcePathProperty == null) { if (memberName == null) { throw new InvalidOperationException(Strings.ObjectContext_MissingExtendedAttributeType(epmAttributeNameBuilder.EpmSourcePath, typeName)); } pathGiven = false; epmSourcePath = memberName; } else { epmSourcePath = Convert.ToString(epmSourcePathProperty.Value, CultureInfo.InvariantCulture); } String epmTargetPath = Convert.ToString(epmTargetPathProperty.Value, CultureInfo.InvariantCulture); // if the property is not a sydication property MapEpmTargetPathToSyndicationProperty // will return SyndicationItemProperty.CustomProperty SyndicationItemProperty targetSyndicationItem = MapEpmTargetPathToSyndicationProperty(epmTargetPath); MetadataProperty epmContentKindProperty = FindSingletonExtendedProperty( extendedProperties, epmAttributeNameBuilder.EpmContentKind, typeName, memberName); MetadataProperty epmNsPrefixProperty = FindSingletonExtendedProperty( extendedProperties, epmAttributeNameBuilder.EpmNsPrefix, typeName, memberName); MetadataProperty epmNsUriProperty = FindSingletonExtendedProperty( extendedProperties, epmAttributeNameBuilder.EpmNsUri, typeName, memberName); // ContentKind is mutually exclusive with NsPrefix and NsUri properties if (epmContentKindProperty != null) { if (epmNsPrefixProperty != null || epmNsUriProperty != null) { string epmPropertyName = epmNsPrefixProperty != null ? epmAttributeNameBuilder.EpmNsPrefix : epmAttributeNameBuilder.EpmNsUri; throw new InvalidOperationException(memberName == null ? Strings.ObjectContext_InvalidAttributeForNonSyndicationItemsType(epmPropertyName, typeName) : Strings.ObjectContext_InvalidAttributeForNonSyndicationItemsMember(epmPropertyName, memberName, typeName)); } } // epmNsPrefixProperty and epmNsUriProperty can be non-null only for non-Atom mapping. Since they are optional we need to check // if it was possible to map the target path to a syndication item name. if it was not (i.e. targetSyndicationItem == SyndicationItemProperty.CustomProperty) // this is a non-Atom kind of mapping. if (epmNsPrefixProperty != null || epmNsUriProperty != null || targetSyndicationItem == SyndicationItemProperty.CustomProperty) { String epmNsPrefix = epmNsPrefixProperty != null ? Convert.ToString(epmNsPrefixProperty.Value, CultureInfo.InvariantCulture) : null; String epmNsUri = epmNsUriProperty != null ? Convert.ToString(epmNsUriProperty.Value, CultureInfo.InvariantCulture) : null; yield return new EpmPropertyInformation { IsAtom = false, KeepInContent = epmKeepInContent, SourcePath = epmSourcePath, PathGiven = pathGiven, TargetPath = epmTargetPath, NsPrefix = epmNsPrefix, NsUri = epmNsUri }; } else { SyndicationTextContentKind syndicationContentKind; if (epmContentKindProperty != null) { syndicationContentKind = MapEpmContentKindToSyndicationTextContentKind( Convert.ToString(epmContentKindProperty.Value, CultureInfo.InvariantCulture), typeName, memberName); } else { syndicationContentKind = SyndicationTextContentKind.Plaintext; } yield return new EpmPropertyInformation { IsAtom = true, KeepInContent = epmKeepInContent, SourcePath = epmSourcePath, PathGiven = pathGiven, SyndicationItem = targetSyndicationItem, ContentKind = syndicationContentKind }; } epmAttributeNameBuilder.MoveNext(); } else { yield break; } } } /// /// Finds the extended property from a collection of extended EFx properties, only allows singletons /// /// Collection of metadata extended properties of/// Name of the property /// Type to which the property belongs /// Name of the member whose extended properties we are searching from /// The corresponding MetadataProperty object if found, null otherwise private static MetadataProperty FindSingletonExtendedProperty(IEnumerablemetadataExtendedProperties, String propertyName, String typeName, String memberName) { string extendedPropertyName = System.Data.Services.XmlConstants.DataWebMetadataNamespace + ":" + propertyName; IEnumerable result = metadataExtendedProperties.Where(mdp => mdp.Name == extendedPropertyName); bool found = false; MetadataProperty property = null; foreach (MetadataProperty p in result) { if (found) { throw new InvalidOperationException(memberName == null ? Strings.ObjectContext_MultipleValuesForSameExtendedAttributeType(propertyName, typeName) : Strings.ObjectContext_MultipleValuesForSameExtendedAttributeMember(propertyName, memberName, typeName)); } property = p; found = true; } return property; } /// /// Given a /// Target path in the form of syndication property name ///gets the corresponding syndication property. /// /// Enumerated value of a SyndicationItemProperty or SyndicationItemProperty.CustomProperty if the private static SyndicationItemProperty MapEpmTargetPathToSyndicationProperty(String targetPath) { Debug.Assert(Enum.GetNames(typeof(SyndicationItemProperty)).Count() == 12, "Any addition to SyndicationItemPropery enum requires updating this method."); SyndicationItemProperty targetSyndicationItem = SyndicationItemProperty.CustomProperty; switch (targetPath) { case System.Data.Services.XmlConstants.SyndAuthorEmail: targetSyndicationItem = SyndicationItemProperty.AuthorEmail; break; case System.Data.Services.XmlConstants.SyndAuthorName: targetSyndicationItem = SyndicationItemProperty.AuthorName; break; case System.Data.Services.XmlConstants.SyndAuthorUri: targetSyndicationItem = SyndicationItemProperty.AuthorUri; break; case System.Data.Services.XmlConstants.SyndContributorEmail: targetSyndicationItem = SyndicationItemProperty.ContributorEmail; break; case System.Data.Services.XmlConstants.SyndContributorName: targetSyndicationItem = SyndicationItemProperty.ContributorName; break; case System.Data.Services.XmlConstants.SyndContributorUri: targetSyndicationItem = SyndicationItemProperty.ContributorUri; break; case System.Data.Services.XmlConstants.SyndUpdated: targetSyndicationItem = SyndicationItemProperty.Updated; break; case System.Data.Services.XmlConstants.SyndPublished: targetSyndicationItem = SyndicationItemProperty.Published; break; case System.Data.Services.XmlConstants.SyndRights: targetSyndicationItem = SyndicationItemProperty.Rights; break; case System.Data.Services.XmlConstants.SyndSummary: targetSyndicationItem = SyndicationItemProperty.Summary; break; case System.Data.Services.XmlConstants.SyndTitle: targetSyndicationItem = SyndicationItemProperty.Title; break; default: targetSyndicationItem = SyndicationItemProperty.CustomProperty; break; } return targetSyndicationItem; } ////// does not map to any syndication property name. /// /// Given the string representation in /// String representation of syndication content kind e.g. plaintext, html or xhtml /// Type to which the property belongs /// Name of the member whose extended properties we are searching from ///gets back the corresponding enumerated value /// Enumerated value of SyndicationTextContentKind 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; } ////// Class for holding de-serialized Epm attribute from csdl file /// private sealed class EpmPropertyInformation { ///Syndication mapping or custom mapping internal bool IsAtom { get; set; } ///KeepInContent internal bool KeepInContent { get; set; } ///SourcePath internal String SourcePath { get; set; } ///Was path provided or inferred internal bool PathGiven { get; set; } ///TargetPath internal String TargetPath { get; set; } ///Target syndication item when IsAtom is true internal SyndicationItemProperty SyndicationItem { get; set; } ///Target syndication item content kind when IsAtom is true internal SyndicationTextContentKind ContentKind { get; set; } ///Namespace prefix when IsAtom is false internal String NsPrefix { get; set; } ///Namespace Uri when IsAtom is false internal String NsUri { get; set; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ServiceDescriptionImporter.cs
- CompressStream.cs
- MenuBase.cs
- RequestQueryProcessor.cs
- BufferedGraphicsContext.cs
- Section.cs
- CodeRegionDirective.cs
- DrawingContextDrawingContextWalker.cs
- XmlWrappingWriter.cs
- XmlReflectionImporter.cs
- ZipFileInfoCollection.cs
- ErrorTableItemStyle.cs
- FontCollection.cs
- ImageSource.cs
- ServiceProviders.cs
- COM2PropertyBuilderUITypeEditor.cs
- DCSafeHandle.cs
- FileIOPermission.cs
- SafeSecurityHandles.cs
- SecuritySessionSecurityTokenAuthenticator.cs
- Inflater.cs
- _UriSyntax.cs
- GeneratedCodeAttribute.cs
- SafeSecurityHelper.cs
- PageCache.cs
- ErasingStroke.cs
- PreloadedPackages.cs
- CodeStatement.cs
- HtmlInputButton.cs
- NonSerializedAttribute.cs
- WebPartDescriptionCollection.cs
- ToolStripPanelDesigner.cs
- TogglePatternIdentifiers.cs
- XPathNavigator.cs
- DropDownList.cs
- Types.cs
- CodeCommentStatement.cs
- CodeIdentifier.cs
- SapiAttributeParser.cs
- SharingService.cs
- SamlSubject.cs
- DataGridViewComboBoxCell.cs
- XmlDataSourceView.cs
- Flattener.cs
- CatalogZoneBase.cs
- FileLoadException.cs
- HtmlInputSubmit.cs
- MailMessageEventArgs.cs
- EmptyEnumerator.cs
- BitHelper.cs
- UnsafeNativeMethods.cs
- QualifiedCellIdBoolean.cs
- ExtensibleClassFactory.cs
- OuterGlowBitmapEffect.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- SecurityTokenRequirement.cs
- ChannelSinkStacks.cs
- Effect.cs
- ArrangedElementCollection.cs
- HierarchicalDataBoundControl.cs
- ScriptModule.cs
- CqlBlock.cs
- ProgressiveCrcCalculatingStream.cs
- OracleBinary.cs
- SafeArrayRankMismatchException.cs
- WebControlsSection.cs
- GridViewColumn.cs
- XmlTypeAttribute.cs
- DataStreamFromComStream.cs
- WsatExtendedInformation.cs
- webproxy.cs
- InvalidCastException.cs
- UnsafePeerToPeerMethods.cs
- NodeFunctions.cs
- SharedRuntimeState.cs
- PathSegmentCollection.cs
- WebPartHeaderCloseVerb.cs
- Drawing.cs
- TableStyle.cs
- DataServiceResponse.cs
- EntityCodeGenerator.cs
- LineUtil.cs
- DbProviderConfigurationHandler.cs
- Transform3DGroup.cs
- HttpInputStream.cs
- LOSFormatter.cs
- Mappings.cs
- ValidatingPropertiesEventArgs.cs
- MyContact.cs
- HtmlInputControl.cs
- MultilineStringConverter.cs
- DeleteMemberBinder.cs
- RequestSecurityTokenResponse.cs
- EntityViewGenerationConstants.cs
- OdbcCommand.cs
- ValidationRule.cs
- HttpCachePolicyBase.cs
- DataControlImageButton.cs
- XPathNode.cs
- ScopedKnownTypes.cs