Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / EntityClient / EntityConnectionStringBuilder.cs / 2 / EntityConnectionStringBuilder.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Data; using System.Data.Common; using System.Configuration; using System.Globalization; using System.Diagnostics.CodeAnalysis; using System.Diagnostics; using System.ComponentModel; namespace System.Data.EntityClient { ////// Class representing a connection string builder for the entity client provider /// [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "EntityConnectionStringBuilder follows the naming convention of DbConnectionStringBuilder.")] [SuppressMessage("Microsoft.Design", "CA1035:ICollectionImplementationsHaveStronglyTypedMembers", Justification = "There is no applicable strongly-typed implementation of CopyTo.")] public sealed class EntityConnectionStringBuilder : DbConnectionStringBuilder { // Names of parameters to look for in the connection string internal const string NameParameterName = "name"; internal const string MetadataParameterName = "metadata"; internal const string ProviderParameterName = "provider"; internal const string ProviderConnectionStringParameterName = "provider connection string"; // An array to hold the keywords private static readonly string[] s_validKeywords = new string[] { NameParameterName, MetadataParameterName, ProviderParameterName, ProviderConnectionStringParameterName }; private static Hashtable s_synonyms; // Information and data used by the connection private string _namedConnectionName; private string _providerName; private string _metadataLocations; private string _storeProviderConnectionString; ////// Constructs the EntityConnectionStringBuilder object /// public EntityConnectionStringBuilder() { // Everything just defaults to null } ////// Constructs the EntityConnectionStringBuilder object with a connection string /// /// The connection string to initialize this builder public EntityConnectionStringBuilder(string connectionString) { this.ConnectionString = connectionString; } ////// Gets or sets the named connection name in the connection string /// [DisplayName("Name")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_NamedConnectionString)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Name)] [RefreshProperties(RefreshProperties.All)] public string Name { get { return this._namedConnectionName ?? ""; } set { this._namedConnectionName = value; base[NameParameterName] = value; } } ////// Gets or sets the name of the underlying .NET Framework data provider in the connection string /// [DisplayName("Provider")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_Source)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Provider)] [RefreshProperties(RefreshProperties.All)] public string Provider { get { return this._providerName ?? ""; } set { this._providerName = value; base[ProviderParameterName] = value; } } ////// Gets or sets the metadata locations in the connection string, which is a pipe-separated sequence /// of paths to folders and individual files /// [DisplayName("Metadata")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_Context)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Metadata)] [RefreshProperties(RefreshProperties.All)] public string Metadata { get { return this._metadataLocations ?? ""; } set { this._metadataLocations = value; base[MetadataParameterName] = value; } } ////// Gets or sets the inner connection string in the connection string /// [DisplayName("Provider Connection String")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_Source)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_ProviderConnectionString)] [RefreshProperties(RefreshProperties.All)] public string ProviderConnectionString { get { return this._storeProviderConnectionString ?? ""; } set { this._storeProviderConnectionString = value; base[ProviderConnectionStringParameterName] = value; } } ////// Gets whether the EntityConnectionStringBuilder has a fixed size /// public override bool IsFixedSize { get { return true; } } ////// Gets a collection of all keywords used by EntityConnectionStringBuilder /// public override ICollection Keys { get { return new System.Collections.ObjectModel.ReadOnlyCollection(s_validKeywords); } } /// /// Returns a hash table object containing all the valid keywords. This is really the same as the Keys /// property, it's just that the returned object is a hash table. /// internal static Hashtable Synonyms { get { // Build the synonyms table if we don't have one if (s_synonyms == null) { Hashtable table = new Hashtable(s_validKeywords.Length); foreach (string keyword in s_validKeywords) { table.Add(keyword, keyword); } s_synonyms = table; } return s_synonyms; } } ////// Gets or sets the value associated with the keyword /// public override object this[string keyword] { get { EntityUtil.CheckArgumentNull(keyword, "keyword"); // Just access the properties to get the value since the fields, which the properties will be accessing, will // have already been set when the connection string is set if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.Metadata; } else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.ProviderConnectionString; } else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.Name; } else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.Provider; } throw EntityUtil.KeywordNotSupported(keyword); } set { EntityUtil.CheckArgumentNull(keyword, "keyword"); // If a null value is set, just remove the parameter and return if (value == null) { this.Remove(keyword); return; } // Since all of our parameters must be string value, perform the cast here and check string stringValue = value as string; if (stringValue == null) { throw EntityUtil.Argument(System.Data.Entity.Strings.EntityClient_ValueNotString, "value"); } // Just access the properties to get the value since the fields, which the properties will be accessing, will // have already been set when the connection string is set if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.Metadata = stringValue; } else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.ProviderConnectionString = stringValue; } else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.Name = stringValue; } else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.Provider = stringValue; } else { throw EntityUtil.KeywordNotSupported(keyword); } } } ////// Clear all the parameters in the connection string /// public override void Clear() { base.Clear(); this._namedConnectionName = null; this._providerName = null; this._metadataLocations = null; this._storeProviderConnectionString = null; } ////// Determine if this connection string builder contains a specific key /// /// The keyword to find in this connection string builder ///True if this connections string builder contains the specific key public override bool ContainsKey(string keyword) { EntityUtil.CheckArgumentNull(keyword, "keyword"); foreach (string validKeyword in s_validKeywords) { if (validKeyword.Equals(keyword, StringComparison.OrdinalIgnoreCase)) { return true; } } return false; } ////// Gets the value of the given keyword, returns false if there isn't a value with the given keyword /// /// The keyword specifying the name of the parameter to retrieve /// The value retrieved ///True if the value is retrieved public override bool TryGetValue(string keyword, out object value) { EntityUtil.CheckArgumentNull(keyword, "keyword"); if (ContainsKey(keyword)) { value = this[keyword]; return true; } value = null; return false; } ////// Removes a parameter from the builder /// /// The keyword specifying the name of the parameter to remove ///True if the parameter is removed public override bool Remove(string keyword) { EntityUtil.CheckArgumentNull(keyword, "keyword"); // Convert the given object into a string if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._metadataLocations = null; } else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._storeProviderConnectionString = null; } else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._namedConnectionName = null; } else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._providerName = null; } return base.Remove(keyword); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....], [....] //--------------------------------------------------------------------- using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Data; using System.Data.Common; using System.Configuration; using System.Globalization; using System.Diagnostics.CodeAnalysis; using System.Diagnostics; using System.ComponentModel; namespace System.Data.EntityClient { ////// Class representing a connection string builder for the entity client provider /// [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "EntityConnectionStringBuilder follows the naming convention of DbConnectionStringBuilder.")] [SuppressMessage("Microsoft.Design", "CA1035:ICollectionImplementationsHaveStronglyTypedMembers", Justification = "There is no applicable strongly-typed implementation of CopyTo.")] public sealed class EntityConnectionStringBuilder : DbConnectionStringBuilder { // Names of parameters to look for in the connection string internal const string NameParameterName = "name"; internal const string MetadataParameterName = "metadata"; internal const string ProviderParameterName = "provider"; internal const string ProviderConnectionStringParameterName = "provider connection string"; // An array to hold the keywords private static readonly string[] s_validKeywords = new string[] { NameParameterName, MetadataParameterName, ProviderParameterName, ProviderConnectionStringParameterName }; private static Hashtable s_synonyms; // Information and data used by the connection private string _namedConnectionName; private string _providerName; private string _metadataLocations; private string _storeProviderConnectionString; ////// Constructs the EntityConnectionStringBuilder object /// public EntityConnectionStringBuilder() { // Everything just defaults to null } ////// Constructs the EntityConnectionStringBuilder object with a connection string /// /// The connection string to initialize this builder public EntityConnectionStringBuilder(string connectionString) { this.ConnectionString = connectionString; } ////// Gets or sets the named connection name in the connection string /// [DisplayName("Name")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_NamedConnectionString)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Name)] [RefreshProperties(RefreshProperties.All)] public string Name { get { return this._namedConnectionName ?? ""; } set { this._namedConnectionName = value; base[NameParameterName] = value; } } ////// Gets or sets the name of the underlying .NET Framework data provider in the connection string /// [DisplayName("Provider")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_Source)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Provider)] [RefreshProperties(RefreshProperties.All)] public string Provider { get { return this._providerName ?? ""; } set { this._providerName = value; base[ProviderParameterName] = value; } } ////// Gets or sets the metadata locations in the connection string, which is a pipe-separated sequence /// of paths to folders and individual files /// [DisplayName("Metadata")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_Context)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Metadata)] [RefreshProperties(RefreshProperties.All)] public string Metadata { get { return this._metadataLocations ?? ""; } set { this._metadataLocations = value; base[MetadataParameterName] = value; } } ////// Gets or sets the inner connection string in the connection string /// [DisplayName("Provider Connection String")] [EntityResCategoryAttribute(EntityRes.EntityDataCategory_Source)] [EntityResDescriptionAttribute(EntityRes.EntityConnectionString_ProviderConnectionString)] [RefreshProperties(RefreshProperties.All)] public string ProviderConnectionString { get { return this._storeProviderConnectionString ?? ""; } set { this._storeProviderConnectionString = value; base[ProviderConnectionStringParameterName] = value; } } ////// Gets whether the EntityConnectionStringBuilder has a fixed size /// public override bool IsFixedSize { get { return true; } } ////// Gets a collection of all keywords used by EntityConnectionStringBuilder /// public override ICollection Keys { get { return new System.Collections.ObjectModel.ReadOnlyCollection(s_validKeywords); } } /// /// Returns a hash table object containing all the valid keywords. This is really the same as the Keys /// property, it's just that the returned object is a hash table. /// internal static Hashtable Synonyms { get { // Build the synonyms table if we don't have one if (s_synonyms == null) { Hashtable table = new Hashtable(s_validKeywords.Length); foreach (string keyword in s_validKeywords) { table.Add(keyword, keyword); } s_synonyms = table; } return s_synonyms; } } ////// Gets or sets the value associated with the keyword /// public override object this[string keyword] { get { EntityUtil.CheckArgumentNull(keyword, "keyword"); // Just access the properties to get the value since the fields, which the properties will be accessing, will // have already been set when the connection string is set if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.Metadata; } else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.ProviderConnectionString; } else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.Name; } else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0) { return this.Provider; } throw EntityUtil.KeywordNotSupported(keyword); } set { EntityUtil.CheckArgumentNull(keyword, "keyword"); // If a null value is set, just remove the parameter and return if (value == null) { this.Remove(keyword); return; } // Since all of our parameters must be string value, perform the cast here and check string stringValue = value as string; if (stringValue == null) { throw EntityUtil.Argument(System.Data.Entity.Strings.EntityClient_ValueNotString, "value"); } // Just access the properties to get the value since the fields, which the properties will be accessing, will // have already been set when the connection string is set if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.Metadata = stringValue; } else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.ProviderConnectionString = stringValue; } else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.Name = stringValue; } else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this.Provider = stringValue; } else { throw EntityUtil.KeywordNotSupported(keyword); } } } ////// Clear all the parameters in the connection string /// public override void Clear() { base.Clear(); this._namedConnectionName = null; this._providerName = null; this._metadataLocations = null; this._storeProviderConnectionString = null; } ////// Determine if this connection string builder contains a specific key /// /// The keyword to find in this connection string builder ///True if this connections string builder contains the specific key public override bool ContainsKey(string keyword) { EntityUtil.CheckArgumentNull(keyword, "keyword"); foreach (string validKeyword in s_validKeywords) { if (validKeyword.Equals(keyword, StringComparison.OrdinalIgnoreCase)) { return true; } } return false; } ////// Gets the value of the given keyword, returns false if there isn't a value with the given keyword /// /// The keyword specifying the name of the parameter to retrieve /// The value retrieved ///True if the value is retrieved public override bool TryGetValue(string keyword, out object value) { EntityUtil.CheckArgumentNull(keyword, "keyword"); if (ContainsKey(keyword)) { value = this[keyword]; return true; } value = null; return false; } ////// Removes a parameter from the builder /// /// The keyword specifying the name of the parameter to remove ///True if the parameter is removed public override bool Remove(string keyword) { EntityUtil.CheckArgumentNull(keyword, "keyword"); // Convert the given object into a string if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._metadataLocations = null; } else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._storeProviderConnectionString = null; } else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._namedConnectionName = null; } else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0) { this._providerName = null; } return base.Remove(keyword); } } } // 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
- Decorator.cs
- BitmapEffect.cs
- NavigationCommands.cs
- XsltQilFactory.cs
- MemberAccessException.cs
- HtmlDocument.cs
- AutomationElementCollection.cs
- HttpListenerResponse.cs
- ToggleButton.cs
- VisualTarget.cs
- PrintPreviewControl.cs
- FileVersionInfo.cs
- Suspend.cs
- UpdatableGenericsFeature.cs
- ByteArrayHelperWithString.cs
- StyleBamlRecordReader.cs
- Char.cs
- OracleFactory.cs
- Executor.cs
- RandomDelayQueuedSendsAsyncResult.cs
- GeneralTransformGroup.cs
- SqlAggregateChecker.cs
- RichTextBox.cs
- DataTableReader.cs
- AutomationFocusChangedEventArgs.cs
- RepeaterItemEventArgs.cs
- RecommendedAsConfigurableAttribute.cs
- configsystem.cs
- Light.cs
- SupportingTokenBindingElement.cs
- TypedOperationInfo.cs
- SQLGuid.cs
- PackagingUtilities.cs
- ErrorProvider.cs
- SmtpFailedRecipientsException.cs
- OrderingInfo.cs
- DataGridViewControlCollection.cs
- ScriptServiceAttribute.cs
- FontUnitConverter.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- Stack.cs
- StringFormat.cs
- FixedHighlight.cs
- TraceContext.cs
- LayoutTable.cs
- ClientSettingsSection.cs
- XsdDataContractExporter.cs
- WmpBitmapDecoder.cs
- FileDataSourceCache.cs
- NativeMethods.cs
- PermissionSetTriple.cs
- WpfGeneratedKnownProperties.cs
- ApplicationInterop.cs
- LinqDataSourceSelectEventArgs.cs
- Color.cs
- OpCodes.cs
- ThicknessAnimationUsingKeyFrames.cs
- StyleXamlParser.cs
- Win32Native.cs
- Task.cs
- PathFigureCollectionConverter.cs
- EntityDataSourceDataSelectionPanel.cs
- BitmapPalettes.cs
- RepeaterItemEventArgs.cs
- elementinformation.cs
- StylusPlugInCollection.cs
- Asn1IntegerConverter.cs
- ObjectStateManagerMetadata.cs
- ControlCachePolicy.cs
- SocketPermission.cs
- Grid.cs
- Freezable.cs
- Help.cs
- EqualityComparer.cs
- QuotedStringFormatReader.cs
- GifBitmapEncoder.cs
- PropertyCollection.cs
- Thickness.cs
- FamilyTypefaceCollection.cs
- GridViewSelectEventArgs.cs
- HttpCapabilitiesBase.cs
- _Semaphore.cs
- ServicePointManagerElement.cs
- HorizontalAlignConverter.cs
- ToolStripCustomTypeDescriptor.cs
- BinHexEncoding.cs
- DiagnosticTraceSource.cs
- XmlAttributeAttribute.cs
- FaultReasonText.cs
- TemplatedMailWebEventProvider.cs
- TextEffectCollection.cs
- CdpEqualityComparer.cs
- ImageField.cs
- RefExpr.cs
- HttpCapabilitiesEvaluator.cs
- DataBinder.cs
- EncryptedPackage.cs
- ExpressionHelper.cs
- HtmlPanelAdapter.cs
- PrimarySelectionAdorner.cs