Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntityDesign / Design / System / Data / Entity / Design / EntityFrameworkVersions.cs / 1305376 / EntityFrameworkVersions.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Reflection; using System.Data.Metadata.Edm; using System.Data.Entity.Design.Common; using System.IO; using System.Data.Mapping; using System.Data.EntityModel.SchemaObjectModel; using System.Linq; namespace System.Data.Entity.Design { public static class EntityFrameworkVersions { public static readonly Version Version1 = new Version(1, 0, 0, 0); public static readonly Version Version2 = new Version(2, 0, 0, 0); ////// Returns the stream of the XSD corosponding tot he frameworkVersion, and dataSpace passed in /// /// The version of the EntityFramework that you want the Schema XSD for. /// The data space of the schem XSD that you want. ///Stream version of the XSD public static Stream GetSchemaXsd(Version entityFrameworkVersion, DataSpace dataSpace) { EDesignUtil.CheckTargetEntityFrameworkVersionArgument(entityFrameworkVersion, "entityFrameworkVersion"); string resourceName = null; switch(dataSpace) { case DataSpace.CSpace: resourceName = GetEdmSchemaXsdResourceName(entityFrameworkVersion); break; case DataSpace.CSSpace: resourceName = GetMappingSchemaXsdResourceName(entityFrameworkVersion); break; case DataSpace.SSpace: resourceName = GetStoreSchemaXsdResourceName(entityFrameworkVersion); break; default: throw EDesignUtil.Argument("dataSpace"); } Debug.Assert(!string.IsNullOrEmpty(resourceName), "Did you forget to map something new?"); Assembly dataEntity = typeof(EdmItemCollection).Assembly; return dataEntity.GetManifestResourceStream(resourceName); } private static string GetStoreSchemaXsdResourceName(Version entityFrameworkVersion) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); Dictionarymap = new Dictionary (); XmlSchemaResource.AddStoreSchemaResourceMapEntries(map, GetEdmVersion(entityFrameworkVersion)); return map[GetStoreSchemaNamespace(entityFrameworkVersion)].ResourceName; } private static string GetMappingSchemaXsdResourceName(Version entityFrameworkVersion) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); Dictionary map = new Dictionary (); XmlSchemaResource.AddMappingSchemaResourceMapEntries(map, GetEdmVersion(entityFrameworkVersion)); return map[GetMappingSchemaNamespace(entityFrameworkVersion)].ResourceName; } private static double GetEdmVersion(Version entityFrameworkVersion) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you add a new version or forget to check the version"); if (entityFrameworkVersion.Major == 1) { if (entityFrameworkVersion.Minor == 1) { return XmlConstants.EdmVersionForV1_1; } else { return XmlConstants.EdmVersionForV1; } } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return XmlConstants.EdmVersionForV2; } } private static string GetEdmSchemaXsdResourceName(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); Dictionary map = new Dictionary (); XmlSchemaResource.AddEdmSchemaResourceMapEntries(map, GetEdmVersion(entityFrameworkVersion)); return map[GetEdmSchemaNamespace(entityFrameworkVersion)].ResourceName; } internal static string GetSchemaNamespace(Version entityFrameworkVersion, DataSpace dataSpace) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you add a new version or forget to check the version"); Debug.Assert(dataSpace == DataSpace.CSpace || dataSpace == DataSpace.CSSpace || dataSpace == DataSpace.SSpace, "only support the three spaces with an xml file format"); switch (dataSpace) { case DataSpace.CSpace: return GetEdmSchemaNamespace(entityFrameworkVersion); case DataSpace.SSpace: return GetStoreSchemaNamespace(entityFrameworkVersion); default: return GetMappingSchemaNamespace(entityFrameworkVersion); } } private static string GetStoreSchemaNamespace(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); if (entityFrameworkVersion == EntityFrameworkVersions.Version1) { return XmlConstants.TargetNamespace_1; } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return XmlConstants.TargetNamespace_2; } } private static string GetMappingSchemaNamespace(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); if (entityFrameworkVersion == EntityFrameworkVersions.Version1) { return StorageMslConstructs.NamespaceUriV1; } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return StorageMslConstructs.NamespaceUriV2; } } private static string GetEdmSchemaNamespace(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); if (entityFrameworkVersion == EntityFrameworkVersions.Version1) { return XmlConstants.ModelNamespace_1; } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return XmlConstants.ModelNamespace_2; } } internal static Version Latest = Version2; private static Version[] ValidVersions = new Version[] { Version1, Version2 }; internal static bool IsValidVersion(Version entityFrameworkVersion) { return ValidVersions.Contains(entityFrameworkVersion); } internal static Version ConvertToVersion(double runtimeVersion) { if (runtimeVersion == 1.0 || runtimeVersion == 0.0) { return Version1; } else if (runtimeVersion == 1.1) { // this is not a valid EntityFramework version, // but only a valid EdmVersion return new Version(1, 1); } else { Debug.Assert(runtimeVersion == 2.0, "Did you add a new version?"); return Version2; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Reflection; using System.Data.Metadata.Edm; using System.Data.Entity.Design.Common; using System.IO; using System.Data.Mapping; using System.Data.EntityModel.SchemaObjectModel; using System.Linq; namespace System.Data.Entity.Design { public static class EntityFrameworkVersions { public static readonly Version Version1 = new Version(1, 0, 0, 0); public static readonly Version Version2 = new Version(2, 0, 0, 0); ////// Returns the stream of the XSD corosponding tot he frameworkVersion, and dataSpace passed in /// /// The version of the EntityFramework that you want the Schema XSD for. /// The data space of the schem XSD that you want. ///Stream version of the XSD public static Stream GetSchemaXsd(Version entityFrameworkVersion, DataSpace dataSpace) { EDesignUtil.CheckTargetEntityFrameworkVersionArgument(entityFrameworkVersion, "entityFrameworkVersion"); string resourceName = null; switch(dataSpace) { case DataSpace.CSpace: resourceName = GetEdmSchemaXsdResourceName(entityFrameworkVersion); break; case DataSpace.CSSpace: resourceName = GetMappingSchemaXsdResourceName(entityFrameworkVersion); break; case DataSpace.SSpace: resourceName = GetStoreSchemaXsdResourceName(entityFrameworkVersion); break; default: throw EDesignUtil.Argument("dataSpace"); } Debug.Assert(!string.IsNullOrEmpty(resourceName), "Did you forget to map something new?"); Assembly dataEntity = typeof(EdmItemCollection).Assembly; return dataEntity.GetManifestResourceStream(resourceName); } private static string GetStoreSchemaXsdResourceName(Version entityFrameworkVersion) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); Dictionarymap = new Dictionary (); XmlSchemaResource.AddStoreSchemaResourceMapEntries(map, GetEdmVersion(entityFrameworkVersion)); return map[GetStoreSchemaNamespace(entityFrameworkVersion)].ResourceName; } private static string GetMappingSchemaXsdResourceName(Version entityFrameworkVersion) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); Dictionary map = new Dictionary (); XmlSchemaResource.AddMappingSchemaResourceMapEntries(map, GetEdmVersion(entityFrameworkVersion)); return map[GetMappingSchemaNamespace(entityFrameworkVersion)].ResourceName; } private static double GetEdmVersion(Version entityFrameworkVersion) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you add a new version or forget to check the version"); if (entityFrameworkVersion.Major == 1) { if (entityFrameworkVersion.Minor == 1) { return XmlConstants.EdmVersionForV1_1; } else { return XmlConstants.EdmVersionForV1; } } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return XmlConstants.EdmVersionForV2; } } private static string GetEdmSchemaXsdResourceName(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); Dictionary map = new Dictionary (); XmlSchemaResource.AddEdmSchemaResourceMapEntries(map, GetEdmVersion(entityFrameworkVersion)); return map[GetEdmSchemaNamespace(entityFrameworkVersion)].ResourceName; } internal static string GetSchemaNamespace(Version entityFrameworkVersion, DataSpace dataSpace) { Debug.Assert(IsValidVersion(entityFrameworkVersion), "Did you add a new version or forget to check the version"); Debug.Assert(dataSpace == DataSpace.CSpace || dataSpace == DataSpace.CSSpace || dataSpace == DataSpace.SSpace, "only support the three spaces with an xml file format"); switch (dataSpace) { case DataSpace.CSpace: return GetEdmSchemaNamespace(entityFrameworkVersion); case DataSpace.SSpace: return GetStoreSchemaNamespace(entityFrameworkVersion); default: return GetMappingSchemaNamespace(entityFrameworkVersion); } } private static string GetStoreSchemaNamespace(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); if (entityFrameworkVersion == EntityFrameworkVersions.Version1) { return XmlConstants.TargetNamespace_1; } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return XmlConstants.TargetNamespace_2; } } private static string GetMappingSchemaNamespace(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); if (entityFrameworkVersion == EntityFrameworkVersions.Version1) { return StorageMslConstructs.NamespaceUriV1; } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return StorageMslConstructs.NamespaceUriV2; } } private static string GetEdmSchemaNamespace(Version entityFrameworkVersion) { Debug.Assert(ValidVersions.Contains(entityFrameworkVersion), "Did you forget to check for valid versions before calling this private method?"); if (entityFrameworkVersion == EntityFrameworkVersions.Version1) { return XmlConstants.ModelNamespace_1; } else { Debug.Assert(entityFrameworkVersion == EntityFrameworkVersions.Version2, "did you add a new version?"); return XmlConstants.ModelNamespace_2; } } internal static Version Latest = Version2; private static Version[] ValidVersions = new Version[] { Version1, Version2 }; internal static bool IsValidVersion(Version entityFrameworkVersion) { return ValidVersions.Contains(entityFrameworkVersion); } internal static Version ConvertToVersion(double runtimeVersion) { if (runtimeVersion == 1.0 || runtimeVersion == 0.0) { return Version1; } else if (runtimeVersion == 1.1) { // this is not a valid EntityFramework version, // but only a valid EdmVersion return new Version(1, 1); } else { Debug.Assert(runtimeVersion == 2.0, "Did you add a new version?"); return Version2; } } } } // 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
- ToolStripItemCollection.cs
- UnmanagedMemoryStream.cs
- UnsafeNativeMethods.cs
- SHA1CryptoServiceProvider.cs
- LocatorPart.cs
- GradientBrush.cs
- WindowsGraphicsCacheManager.cs
- CancelEventArgs.cs
- MenuItemCollectionEditor.cs
- BookmarkEventArgs.cs
- SqlStatistics.cs
- ArraySortHelper.cs
- Freezable.cs
- MulticastOption.cs
- GridProviderWrapper.cs
- RegexNode.cs
- IApplicationTrustManager.cs
- Point4D.cs
- LoadGrammarCompletedEventArgs.cs
- AsyncOperationManager.cs
- PathTooLongException.cs
- FixedFlowMap.cs
- Recipient.cs
- WebPartDisplayModeCancelEventArgs.cs
- HttpValueCollection.cs
- UniqueIdentifierService.cs
- XmlSchemaSimpleType.cs
- Rect3DValueSerializer.cs
- InternalPermissions.cs
- ClientConfigurationSystem.cs
- ReaderWriterLockSlim.cs
- UniqueEventHelper.cs
- StylusEventArgs.cs
- ScrollData.cs
- CodeDirectoryCompiler.cs
- FileNameEditor.cs
- ApplicationActivator.cs
- DBSqlParser.cs
- ListChunk.cs
- DetailsViewDeleteEventArgs.cs
- MailAddressCollection.cs
- HttpResponseInternalBase.cs
- CodeSnippetStatement.cs
- FixedSOMSemanticBox.cs
- ClockController.cs
- MdImport.cs
- ForwardPositionQuery.cs
- UpWmlPageAdapter.cs
- FreezableCollection.cs
- NativeObjectSecurity.cs
- ReflectionPermission.cs
- TemplateBindingExtensionConverter.cs
- XmlElementAttribute.cs
- AffineTransform3D.cs
- ProcessHostServerConfig.cs
- ProvideValueServiceProvider.cs
- SqlDataSourceFilteringEventArgs.cs
- DataGridParentRows.cs
- XmlIgnoreAttribute.cs
- RowsCopiedEventArgs.cs
- ThumbButtonInfoCollection.cs
- CompModHelpers.cs
- ServiceTimeoutsBehavior.cs
- HttpEncoderUtility.cs
- MediaElementAutomationPeer.cs
- MouseCaptureWithinProperty.cs
- ExceptionUtility.cs
- ResourceAssociationType.cs
- TextBox.cs
- Input.cs
- IndividualDeviceConfig.cs
- XmlCollation.cs
- WebPartManagerInternals.cs
- RecognitionResult.cs
- Label.cs
- UnsafeNativeMethods.cs
- ToolStripGrip.cs
- SQLDoubleStorage.cs
- COM2ExtendedBrowsingHandler.cs
- X509Utils.cs
- ContainerParagraph.cs
- PersonalizationStateInfo.cs
- AdministrationHelpers.cs
- BeginEvent.cs
- XPathNode.cs
- TypeConverter.cs
- DuplicateDetector.cs
- HtmlForm.cs
- CroppedBitmap.cs
- ComEventsMethod.cs
- RootDesignerSerializerAttribute.cs
- coordinatorscratchpad.cs
- StateDesigner.Helpers.cs
- FormViewInsertedEventArgs.cs
- ColumnResizeAdorner.cs
- InputBinder.cs
- ConfigXmlCDataSection.cs
- StreamAsIStream.cs
- ProvideValueServiceProvider.cs
- PointCollection.cs