Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Metadata / MetadataArtifactLoaderResource.cs / 2 / MetadataArtifactLoaderResource.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
//---------------------------------------------------------------------
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Data.Mapping;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.Security.Cryptography;
using System.Data.EntityModel.SchemaObjectModel;
namespace System.Data.Metadata.Edm
{
///
/// This class represents one resource item to be loaded from an assembly.
///
internal class MetadataArtifactLoaderResource : MetadataArtifactLoader, IComparable
{
private readonly bool _alreadyLoaded = false;
private readonly Assembly _assembly;
private readonly string _resourceName;
///
/// Constructor - loads the resource stream
///
/// The path to the resource to load
/// The global registry of URIs
internal MetadataArtifactLoaderResource(Assembly assembly, string resourceName, ICollection uriRegistry)
{
Debug.Assert(assembly != null);
Debug.Assert(resourceName != null);
_assembly = assembly;
_resourceName = resourceName;
string tempPath = MetadataArtifactLoaderCompositeResource.CreateResPath(_assembly, _resourceName);
_alreadyLoaded = uriRegistry.Contains(tempPath);
if (!_alreadyLoaded)
{
uriRegistry.Add(tempPath);
// '_alreadyLoaded' is not set because while we would like to prevent
// other instances of MetadataArtifactLoaderFile that wrap the same
// _path from being added to the list of paths/readers, we do want to
// include this particular instance.
}
}
public override string Path
{
get
{
return MetadataArtifactLoaderCompositeResource.CreateResPath(_assembly, _resourceName);
}
}
///
/// Implementation of IComparable.CompareTo()
///
/// The object to compare to
/// 0 if the loaders are "equal" (i.e., have the same _path value)
public int CompareTo(object obj)
{
MetadataArtifactLoaderResource loader = obj as MetadataArtifactLoaderResource;
if (loader != null)
{
return string.Compare(Path, loader.Path, StringComparison.OrdinalIgnoreCase);
}
Debug.Assert(false, "object is not a MetadataArtifactLoaderResource");
return -1;
}
///
/// Equals() returns true if the objects have the same _path value
///
/// The object to compare to
/// true if the objects have the same _path value
public override bool Equals(object obj)
{
return this.CompareTo(obj) == 0;
}
///
/// GetHashCode override that defers the result to the _path member variable.
///
///
public override int GetHashCode()
{
return Path.GetHashCode();
}
public override void CollectFilePermissionPaths(List paths, DataSpace spaceToGet)
{
// does not apply
}
///
/// Get paths to artifacts for a specific DataSpace.
///
/// The DataSpace for the artifacts of interest
/// A List of strings identifying paths to all artifacts for a specific DataSpace
public override List GetPaths(DataSpace spaceToGet)
{
List list = new List();
if (!_alreadyLoaded && MetadataArtifactLoader.IsArtifactOfDataSpace(Path, spaceToGet))
{
list.Add(Path);
}
return list;
}
///
/// Get paths to all artifacts
///
/// A List of strings identifying paths to all resources
public override List GetPaths()
{
List list = new List();
if (!_alreadyLoaded)
{
list.Add(Path);
}
return list;
}
///
/// Create and return an XmlReader around the resource represented by this instance.
///
/// A List of XmlReaders for all resources
public override List GetReaders(Dictionary sourceDictionary)
{
List list = new List();
if (!_alreadyLoaded)
{
XmlReader reader = CreateReader();
list.Add(reader);
if (sourceDictionary != null)
{
sourceDictionary.Add(this, reader);
}
}
return list;
}
private XmlReader CreateReader()
{
Stream stream = LoadResource();
XmlReaderSettings readerSettings = Schema.CreateEdmStandardXmlReaderSettings();
// close the stream when the xmlreader is closed
// now the reader owns the stream
readerSettings.CloseInput = true;
// we know that we aren't reading a fragment
readerSettings.ConformanceLevel = ConformanceLevel.Document;
XmlReader reader = XmlReader.Create(stream, readerSettings);
// cannot set the base URI because res:// URIs cause the schema parser
// to choke
return reader;
}
///
/// Create and return an XmlReader around the resource represented by this instance
/// if it is of the requested DataSpace type.
///
/// The DataSpace corresponding to the requested artifacts
/// A List of XmlReader objects
public override List CreateReaders(DataSpace spaceToGet)
{
List list = new List();
if (!_alreadyLoaded)
{
if (MetadataArtifactLoader.IsArtifactOfDataSpace(Path, spaceToGet))
{
XmlReader reader = CreateReader();
list.Add(reader);
}
}
return list;
}
///
/// This method parses the path to the resource and attempts to load it.
/// The method also accounts for the wildcard assembly name.
///
private Stream LoadResource()
{
Stream resourceStream;
if (TryCreateResourceStream(out resourceStream))
{
return resourceStream;
}
throw EntityUtil.Metadata(System.Data.Entity.Strings.UnableToLoadResource);
}
private bool TryCreateResourceStream(out Stream resourceStream)
{
resourceStream = _assembly.GetManifestResourceStream(_resourceName);
return resourceStream != null;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
//---------------------------------------------------------------------
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Data.Mapping;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.Security.Cryptography;
using System.Data.EntityModel.SchemaObjectModel;
namespace System.Data.Metadata.Edm
{
///
/// This class represents one resource item to be loaded from an assembly.
///
internal class MetadataArtifactLoaderResource : MetadataArtifactLoader, IComparable
{
private readonly bool _alreadyLoaded = false;
private readonly Assembly _assembly;
private readonly string _resourceName;
///
/// Constructor - loads the resource stream
///
/// The path to the resource to load
/// The global registry of URIs
internal MetadataArtifactLoaderResource(Assembly assembly, string resourceName, ICollection uriRegistry)
{
Debug.Assert(assembly != null);
Debug.Assert(resourceName != null);
_assembly = assembly;
_resourceName = resourceName;
string tempPath = MetadataArtifactLoaderCompositeResource.CreateResPath(_assembly, _resourceName);
_alreadyLoaded = uriRegistry.Contains(tempPath);
if (!_alreadyLoaded)
{
uriRegistry.Add(tempPath);
// '_alreadyLoaded' is not set because while we would like to prevent
// other instances of MetadataArtifactLoaderFile that wrap the same
// _path from being added to the list of paths/readers, we do want to
// include this particular instance.
}
}
public override string Path
{
get
{
return MetadataArtifactLoaderCompositeResource.CreateResPath(_assembly, _resourceName);
}
}
///
/// Implementation of IComparable.CompareTo()
///
/// The object to compare to
/// 0 if the loaders are "equal" (i.e., have the same _path value)
public int CompareTo(object obj)
{
MetadataArtifactLoaderResource loader = obj as MetadataArtifactLoaderResource;
if (loader != null)
{
return string.Compare(Path, loader.Path, StringComparison.OrdinalIgnoreCase);
}
Debug.Assert(false, "object is not a MetadataArtifactLoaderResource");
return -1;
}
///
/// Equals() returns true if the objects have the same _path value
///
/// The object to compare to
/// true if the objects have the same _path value
public override bool Equals(object obj)
{
return this.CompareTo(obj) == 0;
}
///
/// GetHashCode override that defers the result to the _path member variable.
///
///
public override int GetHashCode()
{
return Path.GetHashCode();
}
public override void CollectFilePermissionPaths(List paths, DataSpace spaceToGet)
{
// does not apply
}
///
/// Get paths to artifacts for a specific DataSpace.
///
/// The DataSpace for the artifacts of interest
/// A List of strings identifying paths to all artifacts for a specific DataSpace
public override List GetPaths(DataSpace spaceToGet)
{
List list = new List();
if (!_alreadyLoaded && MetadataArtifactLoader.IsArtifactOfDataSpace(Path, spaceToGet))
{
list.Add(Path);
}
return list;
}
///
/// Get paths to all artifacts
///
/// A List of strings identifying paths to all resources
public override List GetPaths()
{
List list = new List();
if (!_alreadyLoaded)
{
list.Add(Path);
}
return list;
}
///
/// Create and return an XmlReader around the resource represented by this instance.
///
/// A List of XmlReaders for all resources
public override List GetReaders(Dictionary sourceDictionary)
{
List list = new List();
if (!_alreadyLoaded)
{
XmlReader reader = CreateReader();
list.Add(reader);
if (sourceDictionary != null)
{
sourceDictionary.Add(this, reader);
}
}
return list;
}
private XmlReader CreateReader()
{
Stream stream = LoadResource();
XmlReaderSettings readerSettings = Schema.CreateEdmStandardXmlReaderSettings();
// close the stream when the xmlreader is closed
// now the reader owns the stream
readerSettings.CloseInput = true;
// we know that we aren't reading a fragment
readerSettings.ConformanceLevel = ConformanceLevel.Document;
XmlReader reader = XmlReader.Create(stream, readerSettings);
// cannot set the base URI because res:// URIs cause the schema parser
// to choke
return reader;
}
///
/// Create and return an XmlReader around the resource represented by this instance
/// if it is of the requested DataSpace type.
///
/// The DataSpace corresponding to the requested artifacts
/// A List of XmlReader objects
public override List CreateReaders(DataSpace spaceToGet)
{
List list = new List();
if (!_alreadyLoaded)
{
if (MetadataArtifactLoader.IsArtifactOfDataSpace(Path, spaceToGet))
{
XmlReader reader = CreateReader();
list.Add(reader);
}
}
return list;
}
///
/// This method parses the path to the resource and attempts to load it.
/// The method also accounts for the wildcard assembly name.
///
private Stream LoadResource()
{
Stream resourceStream;
if (TryCreateResourceStream(out resourceStream))
{
return resourceStream;
}
throw EntityUtil.Metadata(System.Data.Entity.Strings.UnableToLoadResource);
}
private bool TryCreateResourceStream(out Stream resourceStream)
{
resourceStream = _assembly.GetManifestResourceStream(_resourceName);
return resourceStream != null;
}
}
}
// 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
- AddInActivator.cs
- PrimitiveXmlSerializers.cs
- StoryFragments.cs
- Imaging.cs
- MsmqIntegrationInputChannel.cs
- ExtractorMetadata.cs
- ShapingWorkspace.cs
- ListControlConvertEventArgs.cs
- AccessorTable.cs
- CompilerResults.cs
- InvariantComparer.cs
- StreamInfo.cs
- SmiConnection.cs
- HwndMouseInputProvider.cs
- AlphaSortedEnumConverter.cs
- TrackingDataItem.cs
- TextServicesProperty.cs
- FactoryRecord.cs
- TypeNameHelper.cs
- CodeDomSerializerException.cs
- ItemChangedEventArgs.cs
- XmlHierarchicalDataSourceView.cs
- TableAutomationPeer.cs
- XmlSchemaCompilationSettings.cs
- CfgSemanticTag.cs
- X509WindowsSecurityToken.cs
- metadatamappinghashervisitor.cs
- XmlElementList.cs
- DataGridViewRowPostPaintEventArgs.cs
- NullableConverter.cs
- BooleanSwitch.cs
- TargetConverter.cs
- CryptoConfig.cs
- PackageRelationshipSelector.cs
- DataGridViewRowsAddedEventArgs.cs
- NumericExpr.cs
- ColumnHeaderConverter.cs
- ModelPerspective.cs
- KeyProperty.cs
- ListViewItemEventArgs.cs
- XmlReflectionImporter.cs
- XmlSchemaComplexContent.cs
- SelectionBorderGlyph.cs
- UserNameSecurityTokenAuthenticator.cs
- GetPageNumberCompletedEventArgs.cs
- InvokeWebServiceDesigner.cs
- DataGridItemAttachedStorage.cs
- MatchAllMessageFilter.cs
- AttributeAction.cs
- AdapterUtil.cs
- Rights.cs
- ChangeProcessor.cs
- XmlDictionaryReader.cs
- OperandQuery.cs
- AudioSignalProblemOccurredEventArgs.cs
- HostProtectionPermission.cs
- StringComparer.cs
- TripleDES.cs
- FixedPageAutomationPeer.cs
- CacheDependency.cs
- StringUtil.cs
- ManipulationDelta.cs
- BitmapEffectInput.cs
- HiddenField.cs
- EnumerableCollectionView.cs
- QilUnary.cs
- LinqDataSourceDeleteEventArgs.cs
- FlatButtonAppearance.cs
- JsonStringDataContract.cs
- DataListGeneralPage.cs
- TreeNodeCollection.cs
- DecodeHelper.cs
- ScriptingProfileServiceSection.cs
- ConnectionStringsExpressionBuilder.cs
- FileDialogCustomPlace.cs
- CodeAttributeArgumentCollection.cs
- ExtensionWindowResizeGrip.cs
- LeftCellWrapper.cs
- ProcessHostConfigUtils.cs
- PasswordRecovery.cs
- LockCookie.cs
- XmlSchemaSimpleTypeUnion.cs
- SQLMoney.cs
- EventLog.cs
- PointCollection.cs
- ConfigXmlSignificantWhitespace.cs
- ResourceProviderFactory.cs
- WebHttpBinding.cs
- SessionSwitchEventArgs.cs
- ToolTipAutomationPeer.cs
- TableAdapterManagerNameHandler.cs
- ElementAction.cs
- FuncTypeConverter.cs
- TrackingMemoryStreamFactory.cs
- DefaultValueMapping.cs
- BaseServiceProvider.cs
- TypedElement.cs
- PartialCachingControl.cs
- ValueConversionAttribute.cs
- RepeatButtonAutomationPeer.cs