Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / XmlUtils / System / Xml / Xsl / Runtime / XmlQueryStaticData.cs / 1305376 / XmlQueryStaticData.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Xml.Xsl.IlGen; using System.Xml.Xsl.Qil; namespace System.Xml.Xsl.Runtime { ////// Contains all static data that is used by the runtime. /// internal class XmlQueryStaticData { // Name of the field to serialize to public const string DataFieldName = "staticData"; public const string TypesFieldName = "ebTypes"; // Format version marker to support versioning: (major << 8) | minor private const int CurrentFormatVersion = (0 << 8) | 0; private XmlWriterSettings defaultWriterSettings; private IListwhitespaceRules; private string[] names; private StringPair[][] prefixMappingsList; private Int32Pair[] filters; private XmlQueryType[] types; private XmlCollation[] collations; private string[] globalNames; private EarlyBoundInfo[] earlyBound; /// /// Constructor. /// public XmlQueryStaticData(XmlWriterSettings defaultWriterSettings, IListwhitespaceRules, StaticDataManager staticData) { Debug.Assert(defaultWriterSettings != null && staticData != null); this.defaultWriterSettings = defaultWriterSettings; this.whitespaceRules = whitespaceRules; this.names = staticData.Names; this.prefixMappingsList = staticData.PrefixMappingsList; this.filters = staticData.NameFilters; this.types = staticData.XmlTypes; this.collations = staticData.Collations; this.globalNames = staticData.GlobalNames; this.earlyBound = staticData.EarlyBound; #if DEBUG // Round-trip check byte[] data; Type[] ebTypes; this.GetObjectData(out data, out ebTypes); XmlQueryStaticData copy = new XmlQueryStaticData(data, ebTypes); this.defaultWriterSettings = copy.defaultWriterSettings; this.whitespaceRules = copy.whitespaceRules; this.names = copy.names; this.prefixMappingsList = copy.prefixMappingsList; this.filters = copy.filters; this.types = copy.types; this.collations = copy.collations; this.globalNames = copy.globalNames; this.earlyBound = copy.earlyBound; #endif } /// /// Deserialize XmlQueryStaticData object from a byte array. /// public XmlQueryStaticData(byte[] data, Type[] ebTypes) { MemoryStream dataStream = new MemoryStream(data, /*writable:*/false); XmlQueryDataReader dataReader = new XmlQueryDataReader(dataStream); int length; // Read a format version int formatVersion = dataReader.ReadInt32Encoded(); // Changes in the major part of version are not supported if ((formatVersion & ~0xff) > CurrentFormatVersion) throw new NotSupportedException(); // XmlWriterSettings defaultWriterSettings; defaultWriterSettings = new XmlWriterSettings(dataReader); // IListwhitespaceRules; length = dataReader.ReadInt32(); if (length != 0) { this.whitespaceRules = new WhitespaceRule[length]; for (int idx = 0; idx < length; idx++) { this.whitespaceRules[idx] = new WhitespaceRule(dataReader); } } // string[] names; length = dataReader.ReadInt32(); if (length != 0) { this.names = new string[length]; for (int idx = 0; idx < length; idx++) { this.names[idx] = dataReader.ReadString(); } } // StringPair[][] prefixMappingsList; length = dataReader.ReadInt32(); if (length != 0) { this.prefixMappingsList = new StringPair[length][]; for (int idx = 0; idx < length; idx++) { int length2 = dataReader.ReadInt32(); this.prefixMappingsList[idx] = new StringPair[length2]; for (int idx2 = 0; idx2 < length2; idx2++) { this.prefixMappingsList[idx][idx2] = new StringPair(dataReader.ReadString(), dataReader.ReadString()); } } } // Int32Pair[] filters; length = dataReader.ReadInt32(); if (length != 0) { this.filters = new Int32Pair[length]; for (int idx = 0; idx < length; idx++) { this.filters[idx] = new Int32Pair(dataReader.ReadInt32Encoded(), dataReader.ReadInt32Encoded()); } } // XmlQueryType[] types; length = dataReader.ReadInt32(); if (length != 0) { this.types = new XmlQueryType[length]; for (int idx = 0; idx < length; idx++) { this.types[idx] = XmlQueryTypeFactory.Deserialize(dataReader); } } // XmlCollation[] collations; length = dataReader.ReadInt32(); if (length != 0) { this.collations = new XmlCollation[length]; for (int idx = 0; idx < length; idx++) { this.collations[idx] = new XmlCollation(dataReader); } } // string[] globalNames; length = dataReader.ReadInt32(); if (length != 0) { this.globalNames = new string[length]; for (int idx = 0; idx < length; idx++) { this.globalNames[idx] = dataReader.ReadString(); } } // EarlyBoundInfo[] earlyBound; length = dataReader.ReadInt32(); if (length != 0) { this.earlyBound = new EarlyBoundInfo[length]; for (int idx = 0; idx < length; idx++) { this.earlyBound[idx] = new EarlyBoundInfo(dataReader.ReadString(), ebTypes[idx]); } } Debug.Assert(formatVersion != CurrentFormatVersion || dataReader.Read() == -1, "Extra data at the end of the stream"); dataReader.Close(); } /// /// Serialize XmlQueryStaticData object into a byte array. /// public void GetObjectData(out byte[] data, out Type[] ebTypes) { MemoryStream dataStream = new MemoryStream(4096); XmlQueryDataWriter dataWriter = new XmlQueryDataWriter(dataStream); // First put the format version dataWriter.WriteInt32Encoded(CurrentFormatVersion); // XmlWriterSettings defaultWriterSettings; defaultWriterSettings.GetObjectData(dataWriter); // IListwhitespaceRules; if (this.whitespaceRules == null) { dataWriter.Write(0); } else { dataWriter.Write(this.whitespaceRules.Count); foreach (WhitespaceRule rule in this.whitespaceRules) { rule.GetObjectData(dataWriter); } } // string[] names; if (this.names == null) { dataWriter.Write(0); } else { dataWriter.Write(this.names.Length); foreach (string name in this.names) { dataWriter.Write(name); } } // StringPair[][] prefixMappingsList; if (this.prefixMappingsList == null) { dataWriter.Write(0); } else { dataWriter.Write(this.prefixMappingsList.Length); foreach (StringPair[] mappings in this.prefixMappingsList) { dataWriter.Write(mappings.Length); foreach (StringPair mapping in mappings) { dataWriter.Write(mapping.Left); dataWriter.Write(mapping.Right); } } } // Int32Pair[] filters; if (this.filters == null) { dataWriter.Write(0); } else { dataWriter.Write(this.filters.Length); foreach (Int32Pair filter in this.filters) { dataWriter.WriteInt32Encoded(filter.Left); dataWriter.WriteInt32Encoded(filter.Right); } } // XmlQueryType[] types; if (this.types == null) { dataWriter.Write(0); } else { dataWriter.Write(this.types.Length); foreach (XmlQueryType type in this.types) { XmlQueryTypeFactory.Serialize(dataWriter, type); } } // XmlCollation[] collations; if (collations == null) { dataWriter.Write(0); } else { dataWriter.Write(this.collations.Length); foreach (XmlCollation collation in this.collations) { collation.GetObjectData(dataWriter); } } // string[] globalNames; if (this.globalNames == null) { dataWriter.Write(0); } else { dataWriter.Write(this.globalNames.Length); foreach (string name in this.globalNames) { dataWriter.Write(name); } } // EarlyBoundInfo[] earlyBound; if (this.earlyBound == null) { dataWriter.Write(0); ebTypes = null; } else { dataWriter.Write(this.earlyBound.Length); ebTypes = new Type[this.earlyBound.Length]; int idx = 0; foreach (EarlyBoundInfo info in this.earlyBound) { dataWriter.Write(info.NamespaceUri); ebTypes[idx++] = info.EarlyBoundType; } } dataWriter.Close(); data = dataStream.ToArray(); } /// /// Return the default writer settings. /// public XmlWriterSettings DefaultWriterSettings { get { return this.defaultWriterSettings; } } ////// Return the rules used for whitespace stripping/preservation. /// public IListWhitespaceRules { get { return this.whitespaceRules; } } /// /// Return array of names used by this query. /// public string[] Names { get { return this.names; } } ////// Return array of prefix mappings used by this query. /// public StringPair[][] PrefixMappingsList { get { return this.prefixMappingsList; } } ////// Return array of name filter specifications used by this query. /// public Int32Pair[] Filters { get { return this.filters; } } ////// Return array of types used by this query. /// public XmlQueryType[] Types { get { return this.types; } } ////// Return array of collations used by this query. /// public XmlCollation[] Collations { get { return this.collations; } } ////// Return names of all global variables and parameters used by this query. /// public string[] GlobalNames { get { return this.globalNames; } } ////// Return array of early bound object information related to this query. /// public EarlyBoundInfo[] EarlyBound { get { return this.earlyBound; } } } ////// Subclass of BinaryReader used to serialize query static data. /// internal class XmlQueryDataReader : BinaryReader { public XmlQueryDataReader(Stream input) : base(input) { } ////// Read in a 32-bit integer in compressed format. /// public int ReadInt32Encoded() { return Read7BitEncodedInt(); } ////// Read a string value from the stream. Value can be null. /// public string ReadStringQ() { return ReadBoolean() ? ReadString() : null; } ////// Read a signed byte value from the stream and check if it belongs to the given diapason. /// public sbyte ReadSByte(sbyte minValue, sbyte maxValue) { sbyte value = ReadSByte(); if (value < minValue) throw new ArgumentOutOfRangeException("minValue"); if (maxValue < value) throw new ArgumentOutOfRangeException("maxValue"); return value; } } ////// Subclass of BinaryWriter used to deserialize query static data. /// internal class XmlQueryDataWriter : BinaryWriter { public XmlQueryDataWriter(Stream output) : base(output) { } ////// Write a 32-bit integer in a compressed format. /// public void WriteInt32Encoded(int value) { Write7BitEncodedInt(value); } ////// Write a string value to the stream. Value can be null. /// public void WriteStringQ(string value) { Write(value != null); if (value != null) { Write(value); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Xml.Xsl.IlGen; using System.Xml.Xsl.Qil; namespace System.Xml.Xsl.Runtime { ////// Contains all static data that is used by the runtime. /// internal class XmlQueryStaticData { // Name of the field to serialize to public const string DataFieldName = "staticData"; public const string TypesFieldName = "ebTypes"; // Format version marker to support versioning: (major << 8) | minor private const int CurrentFormatVersion = (0 << 8) | 0; private XmlWriterSettings defaultWriterSettings; private IListwhitespaceRules; private string[] names; private StringPair[][] prefixMappingsList; private Int32Pair[] filters; private XmlQueryType[] types; private XmlCollation[] collations; private string[] globalNames; private EarlyBoundInfo[] earlyBound; /// /// Constructor. /// public XmlQueryStaticData(XmlWriterSettings defaultWriterSettings, IListwhitespaceRules, StaticDataManager staticData) { Debug.Assert(defaultWriterSettings != null && staticData != null); this.defaultWriterSettings = defaultWriterSettings; this.whitespaceRules = whitespaceRules; this.names = staticData.Names; this.prefixMappingsList = staticData.PrefixMappingsList; this.filters = staticData.NameFilters; this.types = staticData.XmlTypes; this.collations = staticData.Collations; this.globalNames = staticData.GlobalNames; this.earlyBound = staticData.EarlyBound; #if DEBUG // Round-trip check byte[] data; Type[] ebTypes; this.GetObjectData(out data, out ebTypes); XmlQueryStaticData copy = new XmlQueryStaticData(data, ebTypes); this.defaultWriterSettings = copy.defaultWriterSettings; this.whitespaceRules = copy.whitespaceRules; this.names = copy.names; this.prefixMappingsList = copy.prefixMappingsList; this.filters = copy.filters; this.types = copy.types; this.collations = copy.collations; this.globalNames = copy.globalNames; this.earlyBound = copy.earlyBound; #endif } /// /// Deserialize XmlQueryStaticData object from a byte array. /// public XmlQueryStaticData(byte[] data, Type[] ebTypes) { MemoryStream dataStream = new MemoryStream(data, /*writable:*/false); XmlQueryDataReader dataReader = new XmlQueryDataReader(dataStream); int length; // Read a format version int formatVersion = dataReader.ReadInt32Encoded(); // Changes in the major part of version are not supported if ((formatVersion & ~0xff) > CurrentFormatVersion) throw new NotSupportedException(); // XmlWriterSettings defaultWriterSettings; defaultWriterSettings = new XmlWriterSettings(dataReader); // IListwhitespaceRules; length = dataReader.ReadInt32(); if (length != 0) { this.whitespaceRules = new WhitespaceRule[length]; for (int idx = 0; idx < length; idx++) { this.whitespaceRules[idx] = new WhitespaceRule(dataReader); } } // string[] names; length = dataReader.ReadInt32(); if (length != 0) { this.names = new string[length]; for (int idx = 0; idx < length; idx++) { this.names[idx] = dataReader.ReadString(); } } // StringPair[][] prefixMappingsList; length = dataReader.ReadInt32(); if (length != 0) { this.prefixMappingsList = new StringPair[length][]; for (int idx = 0; idx < length; idx++) { int length2 = dataReader.ReadInt32(); this.prefixMappingsList[idx] = new StringPair[length2]; for (int idx2 = 0; idx2 < length2; idx2++) { this.prefixMappingsList[idx][idx2] = new StringPair(dataReader.ReadString(), dataReader.ReadString()); } } } // Int32Pair[] filters; length = dataReader.ReadInt32(); if (length != 0) { this.filters = new Int32Pair[length]; for (int idx = 0; idx < length; idx++) { this.filters[idx] = new Int32Pair(dataReader.ReadInt32Encoded(), dataReader.ReadInt32Encoded()); } } // XmlQueryType[] types; length = dataReader.ReadInt32(); if (length != 0) { this.types = new XmlQueryType[length]; for (int idx = 0; idx < length; idx++) { this.types[idx] = XmlQueryTypeFactory.Deserialize(dataReader); } } // XmlCollation[] collations; length = dataReader.ReadInt32(); if (length != 0) { this.collations = new XmlCollation[length]; for (int idx = 0; idx < length; idx++) { this.collations[idx] = new XmlCollation(dataReader); } } // string[] globalNames; length = dataReader.ReadInt32(); if (length != 0) { this.globalNames = new string[length]; for (int idx = 0; idx < length; idx++) { this.globalNames[idx] = dataReader.ReadString(); } } // EarlyBoundInfo[] earlyBound; length = dataReader.ReadInt32(); if (length != 0) { this.earlyBound = new EarlyBoundInfo[length]; for (int idx = 0; idx < length; idx++) { this.earlyBound[idx] = new EarlyBoundInfo(dataReader.ReadString(), ebTypes[idx]); } } Debug.Assert(formatVersion != CurrentFormatVersion || dataReader.Read() == -1, "Extra data at the end of the stream"); dataReader.Close(); } /// /// Serialize XmlQueryStaticData object into a byte array. /// public void GetObjectData(out byte[] data, out Type[] ebTypes) { MemoryStream dataStream = new MemoryStream(4096); XmlQueryDataWriter dataWriter = new XmlQueryDataWriter(dataStream); // First put the format version dataWriter.WriteInt32Encoded(CurrentFormatVersion); // XmlWriterSettings defaultWriterSettings; defaultWriterSettings.GetObjectData(dataWriter); // IListwhitespaceRules; if (this.whitespaceRules == null) { dataWriter.Write(0); } else { dataWriter.Write(this.whitespaceRules.Count); foreach (WhitespaceRule rule in this.whitespaceRules) { rule.GetObjectData(dataWriter); } } // string[] names; if (this.names == null) { dataWriter.Write(0); } else { dataWriter.Write(this.names.Length); foreach (string name in this.names) { dataWriter.Write(name); } } // StringPair[][] prefixMappingsList; if (this.prefixMappingsList == null) { dataWriter.Write(0); } else { dataWriter.Write(this.prefixMappingsList.Length); foreach (StringPair[] mappings in this.prefixMappingsList) { dataWriter.Write(mappings.Length); foreach (StringPair mapping in mappings) { dataWriter.Write(mapping.Left); dataWriter.Write(mapping.Right); } } } // Int32Pair[] filters; if (this.filters == null) { dataWriter.Write(0); } else { dataWriter.Write(this.filters.Length); foreach (Int32Pair filter in this.filters) { dataWriter.WriteInt32Encoded(filter.Left); dataWriter.WriteInt32Encoded(filter.Right); } } // XmlQueryType[] types; if (this.types == null) { dataWriter.Write(0); } else { dataWriter.Write(this.types.Length); foreach (XmlQueryType type in this.types) { XmlQueryTypeFactory.Serialize(dataWriter, type); } } // XmlCollation[] collations; if (collations == null) { dataWriter.Write(0); } else { dataWriter.Write(this.collations.Length); foreach (XmlCollation collation in this.collations) { collation.GetObjectData(dataWriter); } } // string[] globalNames; if (this.globalNames == null) { dataWriter.Write(0); } else { dataWriter.Write(this.globalNames.Length); foreach (string name in this.globalNames) { dataWriter.Write(name); } } // EarlyBoundInfo[] earlyBound; if (this.earlyBound == null) { dataWriter.Write(0); ebTypes = null; } else { dataWriter.Write(this.earlyBound.Length); ebTypes = new Type[this.earlyBound.Length]; int idx = 0; foreach (EarlyBoundInfo info in this.earlyBound) { dataWriter.Write(info.NamespaceUri); ebTypes[idx++] = info.EarlyBoundType; } } dataWriter.Close(); data = dataStream.ToArray(); } /// /// Return the default writer settings. /// public XmlWriterSettings DefaultWriterSettings { get { return this.defaultWriterSettings; } } ////// Return the rules used for whitespace stripping/preservation. /// public IListWhitespaceRules { get { return this.whitespaceRules; } } /// /// Return array of names used by this query. /// public string[] Names { get { return this.names; } } ////// Return array of prefix mappings used by this query. /// public StringPair[][] PrefixMappingsList { get { return this.prefixMappingsList; } } ////// Return array of name filter specifications used by this query. /// public Int32Pair[] Filters { get { return this.filters; } } ////// Return array of types used by this query. /// public XmlQueryType[] Types { get { return this.types; } } ////// Return array of collations used by this query. /// public XmlCollation[] Collations { get { return this.collations; } } ////// Return names of all global variables and parameters used by this query. /// public string[] GlobalNames { get { return this.globalNames; } } ////// Return array of early bound object information related to this query. /// public EarlyBoundInfo[] EarlyBound { get { return this.earlyBound; } } } ////// Subclass of BinaryReader used to serialize query static data. /// internal class XmlQueryDataReader : BinaryReader { public XmlQueryDataReader(Stream input) : base(input) { } ////// Read in a 32-bit integer in compressed format. /// public int ReadInt32Encoded() { return Read7BitEncodedInt(); } ////// Read a string value from the stream. Value can be null. /// public string ReadStringQ() { return ReadBoolean() ? ReadString() : null; } ////// Read a signed byte value from the stream and check if it belongs to the given diapason. /// public sbyte ReadSByte(sbyte minValue, sbyte maxValue) { sbyte value = ReadSByte(); if (value < minValue) throw new ArgumentOutOfRangeException("minValue"); if (maxValue < value) throw new ArgumentOutOfRangeException("maxValue"); return value; } } ////// Subclass of BinaryWriter used to deserialize query static data. /// internal class XmlQueryDataWriter : BinaryWriter { public XmlQueryDataWriter(Stream output) : base(output) { } ////// Write a 32-bit integer in a compressed format. /// public void WriteInt32Encoded(int value) { Write7BitEncodedInt(value); } ////// Write a string value to the stream. Value can be null. /// public void WriteStringQ(string value) { Write(value != null); if (value != null) { Write(value); } } } } // 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
- StorageRoot.cs
- FixedSOMPageElement.cs
- ListBoxItemWrapperAutomationPeer.cs
- XmlRawWriter.cs
- XmlSerializationReader.cs
- PublishLicense.cs
- LocatorPartList.cs
- TypeBuilder.cs
- CasesDictionary.cs
- DirtyTextRange.cs
- HandledEventArgs.cs
- Token.cs
- PrintDialog.cs
- SettingsProperty.cs
- ServiceAuthorizationBehavior.cs
- CodeChecksumPragma.cs
- DataSourceControlBuilder.cs
- LocationUpdates.cs
- HierarchicalDataBoundControl.cs
- ForwardPositionQuery.cs
- SymmetricKeyWrap.cs
- XmlAttribute.cs
- AutomationPropertyInfo.cs
- BeginEvent.cs
- RegexCode.cs
- HttpStreamMessageEncoderFactory.cs
- AstNode.cs
- TypeHelpers.cs
- CaseInsensitiveComparer.cs
- Section.cs
- CodeDOMUtility.cs
- TextBoxAutomationPeer.cs
- XamlFilter.cs
- DynamicValueConverter.cs
- CollectionViewGroupRoot.cs
- ColorConvertedBitmap.cs
- TdsValueSetter.cs
- StringReader.cs
- XamlWriter.cs
- ObjectListCommandsPage.cs
- ItemsPanelTemplate.cs
- PseudoWebRequest.cs
- EntityDataSourceContainerNameItem.cs
- DynamicQueryableWrapper.cs
- CardSpacePolicyElement.cs
- NullableConverter.cs
- EnumerableWrapperWeakToStrong.cs
- AsyncDataRequest.cs
- MD5CryptoServiceProvider.cs
- PropertyToken.cs
- ZipIOExtraFieldZip64Element.cs
- securitycriticaldata.cs
- Content.cs
- LocationEnvironment.cs
- CompiledIdentityConstraint.cs
- DocumentViewerHelper.cs
- ControlAdapter.cs
- FieldBuilder.cs
- QuaternionAnimationBase.cs
- XmlAnyAttributeAttribute.cs
- FixedPosition.cs
- streamingZipPartStream.cs
- FieldAccessException.cs
- formatter.cs
- BulletChrome.cs
- DefaultTraceListener.cs
- DateTimePicker.cs
- CodeCompileUnit.cs
- HttpServerProtocol.cs
- VisualTreeHelper.cs
- CompiledXpathExpr.cs
- EventItfInfo.cs
- WindowsToolbarAsMenu.cs
- OracleMonthSpan.cs
- PropertyGridCommands.cs
- Int32KeyFrameCollection.cs
- SharedStatics.cs
- CorrelationToken.cs
- SoapSchemaExporter.cs
- OleDbDataReader.cs
- HttpModulesSection.cs
- SchemaNames.cs
- RegexTree.cs
- RealizationDrawingContextWalker.cs
- HeaderFilter.cs
- ButtonStandardAdapter.cs
- XamlReader.cs
- AttachedPropertyMethodSelector.cs
- InvokeMethodActivity.cs
- ChangeDirector.cs
- ValidationErrorCollection.cs
- SafeProcessHandle.cs
- ModelItem.cs
- DeflateEmulationStream.cs
- DtrList.cs
- SecuritySessionServerSettings.cs
- ActivityCollectionMarkupSerializer.cs
- DuplicateWaitObjectException.cs
- DataGridViewRow.cs
- ScrollBarRenderer.cs