Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / TypeElement.cs / 2 / TypeElement.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Data.Metadata.Edm; using System.Xml; using System.Data.Common; using System.Diagnostics; namespace System.Data.EntityModel.SchemaObjectModel { ////// Responsible for parsing Type ProviderManifest /// xml elements /// internal class TypeElement : SchemaType { PrimitiveType _primitiveType = new PrimitiveType(); List_facetDescriptions = new List (); public TypeElement(Schema parent) : base(parent) { _primitiveType.NamespaceName = Schema.Namespace; } protected override bool HandleElement(XmlReader reader) { if (base.HandleElement(reader)) { return true; } else if (CanHandleElement(reader, XmlConstants.FacetDescriptionsElement)) { SkipThroughElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.PrecisionElement)) { HandlePrecisionElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.ScaleElement)) { HandleScaleElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.MaxLengthElement)) { HandleMaxLengthElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.UnicodeElement)) { HandleUnicodeElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.FixedLengthElement)) { HandleFixedLengthElement(reader); return true; } return false; } protected override bool HandleAttribute(XmlReader reader) { if (base.HandleAttribute(reader)) { return true; } else if (CanHandleAttribute(reader, XmlConstants.PrimitiveTypeKindAttribute)) { HandlePrimitiveTypeKindAttribute(reader); return true; } return false; } ///////////////////////////////////////////////////////////////////// // Element Handlers /// /// Handler for the Precision element /// /// xml reader currently positioned at Precision element private void HandlePrecisionElement(XmlReader reader) { Debug.Assert(reader != null); ByteFacetDescriptionElement facetDescription = new ByteFacetDescriptionElement(this, DbProviderManifest.PrecisionFacetName); facetDescription.Parse(reader); // Bug 476451: Preventing decimal precision to be more than 29 since clr // decimal is capable of holding decimals upto 29 precision if ((this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Decimal) && (facetDescription.MaxValue > EdmProviderManifest.MaximumDecimalPrecision)) { AddError(ErrorCode.PrecisionMoreThanAllowedMax, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.PrecisionMoreThanAllowedMax(facetDescription.MaxValue, EdmProviderManifest.MaximumDecimalPrecision)); } else if (((this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.DateTime) || (this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.DateTimeOffset) || (this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Time)) && (facetDescription.MaxValue > EdmProviderManifest.MaximumDateTimePrecision)) { AddError(ErrorCode.PrecisionMoreThanAllowedMax, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.PrecisionMoreThanAllowedMax(facetDescription.MaxValue, EdmProviderManifest.MaximumDateTimePrecision)); } else { _facetDescriptions.Add(facetDescription); } } ////// Handler for the Scale element /// /// xml reader currently positioned at Scale element private void HandleScaleElement(XmlReader reader) { Debug.Assert(reader != null); ByteFacetDescriptionElement facetDescription = new ByteFacetDescriptionElement(this, DbProviderManifest.ScaleFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ////// Handler for the MaxLength element /// /// xml reader currently positioned at MaxLength element private void HandleMaxLengthElement(XmlReader reader) { Debug.Assert(reader != null); IntegerFacetDescriptionElement facetDescription = new IntegerFacetDescriptionElement(this, DbProviderManifest.MaxLengthFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ////// Handler for the Unicode element /// /// xml reader currently positioned at Unicode element private void HandleUnicodeElement(XmlReader reader) { Debug.Assert(reader != null); BooleanFacetDescriptionElement facetDescription = new BooleanFacetDescriptionElement(this, DbProviderManifest.UnicodeFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ////// Handler for the FixedLength element /// /// xml reader currently positioned at FixedLength element private void HandleFixedLengthElement(XmlReader reader) { Debug.Assert(reader != null); BooleanFacetDescriptionElement facetDescription = new BooleanFacetDescriptionElement(this, DbProviderManifest.FixedLengthFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ///////////////////////////////////////////////////////////////////// // Attribute Handlers ////// Handler for the PrimitiveTypeKind attribute /// /// xml reader currently positioned at Version attribute private void HandlePrimitiveTypeKindAttribute(XmlReader reader) { Debug.Assert(reader != null); string value = reader.Value; try { _primitiveType.PrimitiveTypeKind = (PrimitiveTypeKind)Enum.Parse(typeof(PrimitiveTypeKind), value); _primitiveType.BaseType = MetadataItem.EdmProviderManifest.GetPrimitiveType(_primitiveType.PrimitiveTypeKind); } catch (ArgumentException) { AddError(ErrorCode.InvalidPrimitiveTypeKind, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidPrimitiveTypeKind(value)); } } public override string Name { get { return _primitiveType.Name; } set { _primitiveType.Name = value; } } public PrimitiveType PrimitiveType { get { return _primitiveType; } } public IEnumerableFacetDescriptions { get { foreach (FacetDescriptionElement element in _facetDescriptions) { yield return element.FacetDescription; } } } internal override void ResolveTopLevelNames() { base.ResolveTopLevelNames(); // Call validate on the facet descriptions foreach (FacetDescriptionElement facetDescription in _facetDescriptions) { try { facetDescription.CreateAndValidateFacetDescription(this.Name); } catch (ArgumentException e) { AddError(ErrorCode.InvalidFacetInProviderManifest, EdmSchemaErrorSeverity.Error, e.Message); } } // facet descriptions don't have any names to resolve } internal override void Validate() { base.Validate(); if (!ValidateSufficientFacets()) { // the next checks will ---- up, so get out // if we had errors return; } if (!ValidateInterFacetConsistency()) { return; } } private bool ValidateInterFacetConsistency() { if (PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Decimal) { FacetDescription precisionFacetDescription = Helper.GetFacet(FacetDescriptions, EdmProviderManifest.PrecisionFacetName); FacetDescription scaleFacetDescription = Helper.GetFacet(FacetDescriptions, EdmProviderManifest.ScaleFacetName); if(precisionFacetDescription.MaxValue.Value < scaleFacetDescription.MaxValue.Value) { AddError(ErrorCode.BadPrecisionAndScale, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.BadPrecisionAndScale( precisionFacetDescription.MaxValue.Value, scaleFacetDescription.MaxValue.Value)); return false; } } return true; } private bool ValidateSufficientFacets() { PrimitiveType baseType = _primitiveType.BaseType as PrimitiveType; // the base type will be an edm type // the edm type is the athority for which facets are required if (baseType == null) { // an error will already have been added for this return false; } bool addedErrors = false; foreach (FacetDescription systemFacetDescription in baseType.FacetDescriptions) { FacetDescription providerFacetDescription = Helper.GetFacet(FacetDescriptions, systemFacetDescription.FacetName); if (providerFacetDescription == null) { AddError(ErrorCode.RequiredFacetMissing, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.MissingFacetDescription( PrimitiveType.Name, PrimitiveType.PrimitiveTypeKind, systemFacetDescription.FacetName)); addedErrors = true; } } return !addedErrors; } } } // 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.Data.Metadata.Edm; using System.Xml; using System.Data.Common; using System.Diagnostics; namespace System.Data.EntityModel.SchemaObjectModel { ////// Responsible for parsing Type ProviderManifest /// xml elements /// internal class TypeElement : SchemaType { PrimitiveType _primitiveType = new PrimitiveType(); List_facetDescriptions = new List (); public TypeElement(Schema parent) : base(parent) { _primitiveType.NamespaceName = Schema.Namespace; } protected override bool HandleElement(XmlReader reader) { if (base.HandleElement(reader)) { return true; } else if (CanHandleElement(reader, XmlConstants.FacetDescriptionsElement)) { SkipThroughElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.PrecisionElement)) { HandlePrecisionElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.ScaleElement)) { HandleScaleElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.MaxLengthElement)) { HandleMaxLengthElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.UnicodeElement)) { HandleUnicodeElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.FixedLengthElement)) { HandleFixedLengthElement(reader); return true; } return false; } protected override bool HandleAttribute(XmlReader reader) { if (base.HandleAttribute(reader)) { return true; } else if (CanHandleAttribute(reader, XmlConstants.PrimitiveTypeKindAttribute)) { HandlePrimitiveTypeKindAttribute(reader); return true; } return false; } ///////////////////////////////////////////////////////////////////// // Element Handlers /// /// Handler for the Precision element /// /// xml reader currently positioned at Precision element private void HandlePrecisionElement(XmlReader reader) { Debug.Assert(reader != null); ByteFacetDescriptionElement facetDescription = new ByteFacetDescriptionElement(this, DbProviderManifest.PrecisionFacetName); facetDescription.Parse(reader); // Bug 476451: Preventing decimal precision to be more than 29 since clr // decimal is capable of holding decimals upto 29 precision if ((this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Decimal) && (facetDescription.MaxValue > EdmProviderManifest.MaximumDecimalPrecision)) { AddError(ErrorCode.PrecisionMoreThanAllowedMax, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.PrecisionMoreThanAllowedMax(facetDescription.MaxValue, EdmProviderManifest.MaximumDecimalPrecision)); } else if (((this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.DateTime) || (this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.DateTimeOffset) || (this.PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Time)) && (facetDescription.MaxValue > EdmProviderManifest.MaximumDateTimePrecision)) { AddError(ErrorCode.PrecisionMoreThanAllowedMax, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.PrecisionMoreThanAllowedMax(facetDescription.MaxValue, EdmProviderManifest.MaximumDateTimePrecision)); } else { _facetDescriptions.Add(facetDescription); } } ////// Handler for the Scale element /// /// xml reader currently positioned at Scale element private void HandleScaleElement(XmlReader reader) { Debug.Assert(reader != null); ByteFacetDescriptionElement facetDescription = new ByteFacetDescriptionElement(this, DbProviderManifest.ScaleFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ////// Handler for the MaxLength element /// /// xml reader currently positioned at MaxLength element private void HandleMaxLengthElement(XmlReader reader) { Debug.Assert(reader != null); IntegerFacetDescriptionElement facetDescription = new IntegerFacetDescriptionElement(this, DbProviderManifest.MaxLengthFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ////// Handler for the Unicode element /// /// xml reader currently positioned at Unicode element private void HandleUnicodeElement(XmlReader reader) { Debug.Assert(reader != null); BooleanFacetDescriptionElement facetDescription = new BooleanFacetDescriptionElement(this, DbProviderManifest.UnicodeFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ////// Handler for the FixedLength element /// /// xml reader currently positioned at FixedLength element private void HandleFixedLengthElement(XmlReader reader) { Debug.Assert(reader != null); BooleanFacetDescriptionElement facetDescription = new BooleanFacetDescriptionElement(this, DbProviderManifest.FixedLengthFacetName); facetDescription.Parse(reader); _facetDescriptions.Add(facetDescription); } ///////////////////////////////////////////////////////////////////// // Attribute Handlers ////// Handler for the PrimitiveTypeKind attribute /// /// xml reader currently positioned at Version attribute private void HandlePrimitiveTypeKindAttribute(XmlReader reader) { Debug.Assert(reader != null); string value = reader.Value; try { _primitiveType.PrimitiveTypeKind = (PrimitiveTypeKind)Enum.Parse(typeof(PrimitiveTypeKind), value); _primitiveType.BaseType = MetadataItem.EdmProviderManifest.GetPrimitiveType(_primitiveType.PrimitiveTypeKind); } catch (ArgumentException) { AddError(ErrorCode.InvalidPrimitiveTypeKind, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidPrimitiveTypeKind(value)); } } public override string Name { get { return _primitiveType.Name; } set { _primitiveType.Name = value; } } public PrimitiveType PrimitiveType { get { return _primitiveType; } } public IEnumerableFacetDescriptions { get { foreach (FacetDescriptionElement element in _facetDescriptions) { yield return element.FacetDescription; } } } internal override void ResolveTopLevelNames() { base.ResolveTopLevelNames(); // Call validate on the facet descriptions foreach (FacetDescriptionElement facetDescription in _facetDescriptions) { try { facetDescription.CreateAndValidateFacetDescription(this.Name); } catch (ArgumentException e) { AddError(ErrorCode.InvalidFacetInProviderManifest, EdmSchemaErrorSeverity.Error, e.Message); } } // facet descriptions don't have any names to resolve } internal override void Validate() { base.Validate(); if (!ValidateSufficientFacets()) { // the next checks will ---- up, so get out // if we had errors return; } if (!ValidateInterFacetConsistency()) { return; } } private bool ValidateInterFacetConsistency() { if (PrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Decimal) { FacetDescription precisionFacetDescription = Helper.GetFacet(FacetDescriptions, EdmProviderManifest.PrecisionFacetName); FacetDescription scaleFacetDescription = Helper.GetFacet(FacetDescriptions, EdmProviderManifest.ScaleFacetName); if(precisionFacetDescription.MaxValue.Value < scaleFacetDescription.MaxValue.Value) { AddError(ErrorCode.BadPrecisionAndScale, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.BadPrecisionAndScale( precisionFacetDescription.MaxValue.Value, scaleFacetDescription.MaxValue.Value)); return false; } } return true; } private bool ValidateSufficientFacets() { PrimitiveType baseType = _primitiveType.BaseType as PrimitiveType; // the base type will be an edm type // the edm type is the athority for which facets are required if (baseType == null) { // an error will already have been added for this return false; } bool addedErrors = false; foreach (FacetDescription systemFacetDescription in baseType.FacetDescriptions) { FacetDescription providerFacetDescription = Helper.GetFacet(FacetDescriptions, systemFacetDescription.FacetName); if (providerFacetDescription == null) { AddError(ErrorCode.RequiredFacetMissing, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.MissingFacetDescription( PrimitiveType.Name, PrimitiveType.PrimitiveTypeKind, systemFacetDescription.FacetName)); addedErrors = true; } } return !addedErrors; } } } // 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
- MarkedHighlightComponent.cs
- ChildTable.cs
- TrackingProfileSerializer.cs
- BasicCellRelation.cs
- DayRenderEvent.cs
- GridProviderWrapper.cs
- Thickness.cs
- ControlDesignerState.cs
- Int32Rect.cs
- CodeParameterDeclarationExpressionCollection.cs
- ExitEventArgs.cs
- ToolTip.cs
- ContextMarshalException.cs
- LocationInfo.cs
- CornerRadius.cs
- X509InitiatorCertificateClientElement.cs
- LinqDataSourceUpdateEventArgs.cs
- HtmlGenericControl.cs
- ShowExpandedMultiValueConverter.cs
- InputReportEventArgs.cs
- WindowsFormsSectionHandler.cs
- Compiler.cs
- CompareInfo.cs
- IntPtr.cs
- FixedPage.cs
- CodeTypeDeclaration.cs
- ResXResourceWriter.cs
- GiveFeedbackEventArgs.cs
- DefaultEventAttribute.cs
- DataGridRowAutomationPeer.cs
- Point.cs
- XmlAttributeCollection.cs
- Content.cs
- DbConnectionHelper.cs
- HTTP_SERVICE_CONFIG_URLACL_PARAM.cs
- MatrixTransform3D.cs
- SubMenuStyleCollection.cs
- StickyNote.cs
- ThreadExceptionEvent.cs
- TextWriterTraceListener.cs
- UnsafeMethods.cs
- InvalidOperationException.cs
- PointLight.cs
- XmlSchemaSimpleTypeUnion.cs
- NumberSubstitution.cs
- TextEditorCopyPaste.cs
- OpenTypeLayoutCache.cs
- WCFServiceClientProxyGenerator.cs
- SetterTriggerConditionValueConverter.cs
- RowToFieldTransformer.cs
- ResizeBehavior.cs
- Size3D.cs
- SHA256Cng.cs
- AsyncOperation.cs
- DefaultValidator.cs
- DataKeyArray.cs
- AbandonedMutexException.cs
- InplaceBitmapMetadataWriter.cs
- OleDbWrapper.cs
- SerializationObjectManager.cs
- GridItemPattern.cs
- CookieProtection.cs
- SynchronousChannel.cs
- SettingsPropertyCollection.cs
- WorkflowRuntimeServiceElementCollection.cs
- Site.cs
- TypedReference.cs
- safex509handles.cs
- BitmapCacheBrush.cs
- AddressHeaderCollection.cs
- SystemFonts.cs
- GroupBox.cs
- UserNameSecurityTokenProvider.cs
- SessionState.cs
- ThousandthOfEmRealPoints.cs
- BindingListCollectionView.cs
- XmlElementCollection.cs
- DefaultBindingPropertyAttribute.cs
- VarRefManager.cs
- EmptyCollection.cs
- RequiredFieldValidator.cs
- HotSpot.cs
- ListBindingConverter.cs
- TrustLevel.cs
- DataObjectMethodAttribute.cs
- MailAddress.cs
- AccessDataSource.cs
- SQLDecimalStorage.cs
- Math.cs
- CryptoApi.cs
- DesignerRegionCollection.cs
- EventMap.cs
- AuthenticationException.cs
- ProfileServiceManager.cs
- dbenumerator.cs
- UpdateRecord.cs
- TextTreeRootNode.cs
- CookieParameter.cs
- DateTime.cs
- templategroup.cs