Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / System / data / design / DesignConnection.cs / 1 / DesignConnection.cs
///------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All Rights Reserved. // Information Contained Herein is Proprietary and Confidential. // //----------------------------------------------------------------------------- using System; using System.Data; using System.Data.Common; using System.Design; using System.ComponentModel; using System.CodeDom; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using System.Collections; using System.Collections.Specialized; using System.IO; using System.Globalization; using System.Diagnostics; using System.Runtime.Serialization; using System.Text; namespace System.Data.Design { internal interface IDesignConnection : IDataSourceNamedObject, ICloneable, IDataSourceInitAfterLoading, IDataSourceXmlSpecialOwner { ConnectionString ConnectionStringObject { get; set; } string ConnectionString { get; set; } string Provider { get; set; } bool IsAppSettingsProperty { get; set; } string AppSettingsObjectName { get; set; } CodePropertyReferenceExpression PropertyReference { get; set; } IDictionary Properties { get; } IDbConnection CreateEmptyDbConnection(); } [ DataSourceXmlClass (SchemaName.Connection) ] internal class DesignConnection: DataSourceComponent, IDesignConnection, IDataSourceCollectionMember { private string name; private ConnectionString connectionStringObject; private string connectionStringValue; private string provider; private bool isAppSettingsProperty = false; private string appSettingsObjectName; private CodePropertyReferenceExpression propertyReference; private HybridDictionary properties = new HybridDictionary(); private MemberAttributes modifier = MemberAttributes.Assembly; private static readonly string regexAlphaCharacter = @"[\p{L}\p{Nl}]"; private static readonly string regexUnderscoreCharacter = @"\p{Pc}"; private static readonly string regexIdentifierCharacter = @"[\p{L}\p{Nl}\p{Nd}\p{Mn}\p{Mc}\p{Cf}]"; private static readonly string regexIdentifierStart = "(" + regexAlphaCharacter + "|(" + regexUnderscoreCharacter + regexIdentifierCharacter + "))"; private static readonly string regexIdentifier = regexIdentifierStart + regexIdentifierCharacter + "*"; private string parameterPrefix = null; public DesignConnection() { } public DesignConnection( string connectionName, ConnectionString cs, string provider ) { this.name = connectionName; this.connectionStringObject = cs; this.provider = provider; } public DesignConnection( string connectionName, IDbConnection conn ) { if( conn == null ) { throw new ArgumentNullException("conn"); } this.name = connectionName; DbProviderFactory factory = ProviderManager.GetFactoryFromType( conn.GetType(), ProviderManager.ProviderSupportedClasses.DbConnection ); this.provider = ProviderManager.GetInvariantProviderName( factory ); this.connectionStringObject = new ConnectionString( this.provider, conn.ConnectionString ); } internal static string ConnectionNameRegex { get { return DesignConnection.regexIdentifier; } } [ DefaultValue (MemberAttributes.Assembly), DataSourceXmlAttribute () ] public MemberAttributes Modifier { get { return modifier; } set { modifier = value; } } [ DataSourceXmlAttribute() ] public string Name { get { return this.name; } set { if (this.name != value) { if (this.CollectionParent != null) { CollectionParent.ValidateUniqueName(this, value); } this.name = value; } } } [DataSourceXmlAttribute(SpecialWay = true), Browsable(false)] public ConnectionString ConnectionStringObject { get { return this.connectionStringObject; } set { ConnectionString oldConnectionString = this.connectionStringObject; this.connectionStringObject = value; } } public string ConnectionString { get { if (ConnectionStringObject != null) { return this.ConnectionStringObject.ToString (); // we can customize this string by calling ToStringUsing(...) if needed } return string.Empty; } set { Debug.Assert(this.ConnectionStringObject != null," Don't know how to set the connection string"); if (this.ConnectionStringObject != null) { this.ConnectionStringObject = new ConnectionString( this.provider, value ); } } } [DataSourceXmlAttribute(), Browsable (false)] public string Provider { get { return this.provider; } set { this.provider = value; } } [DataSourceXmlAttribute(), Browsable(false)] public bool IsAppSettingsProperty { get { return this.isAppSettingsProperty; } set { this.isAppSettingsProperty = value; } } [DataSourceXmlAttribute(), Browsable(false)] public string AppSettingsObjectName { get { return this.appSettingsObjectName; } set { this.appSettingsObjectName = value; } } [DataSourceXmlAttribute(SpecialWay = true), Browsable(false)] public CodePropertyReferenceExpression PropertyReference { get { return this.propertyReference; } set { this.propertyReference = value; } } [DataSourceXmlAttribute(), Browsable(false)] public string ParameterPrefix { get { return this.parameterPrefix; } set { this.parameterPrefix = value; } } [Browsable(false)] public IDictionary Properties { get { return this.properties; } } [Browsable(false)] public string PublicTypeName { get { return "Connection"; } } public IDbConnection CreateEmptyDbConnection() { DbProviderFactory factory = ProviderManager.GetFactory( this.provider ); return factory.CreateConnection(); } public object Clone() { DesignConnection clone = new DesignConnection(); clone.Name = this.name; if (this.ConnectionStringObject != null){ clone.ConnectionStringObject = (ConnectionString) ((ICloneable) this.ConnectionStringObject).Clone(); } clone.provider = this.provider; clone.isAppSettingsProperty = this.isAppSettingsProperty; clone.propertyReference = this.propertyReference; clone.properties = (HybridDictionary) DesignUtil.CloneDictionary( this.properties ); return clone; } void IDataSourceInitAfterLoading.InitializeAfterLoading() { if (name == null || name.Length == 0) { throw new DataSourceSerializationException( SR.GetString( SR.DTDS_NameIsRequired, "Connection") ); } if (StringUtil.EmptyOrSpace(this.provider)) { throw new DataSourceSerializationException( SR.GetString( SR.DTDS_CouldNotDeserializeConnection ) ); } if (connectionStringValue != null) { this.ConnectionStringObject = new ConnectionString( this.provider, this.connectionStringValue ); } this.properties.Clear(); } void IDataSourceXmlSpecialOwner.ReadSpecialItem(string propertyName, XmlNode xmlNode, DataSourceXmlSerializer serializer) { if (propertyName == "ConnectionStringObject") { this.connectionStringValue = xmlNode.InnerText; } else if (propertyName == "PropertyReference") { this.propertyReference = PropertyReferenceSerializer.Deserialize(xmlNode.InnerText); } } void IDataSourceXmlSpecialOwner.WriteSpecialItem(string propertyName, XmlWriter writer, DataSourceXmlSerializer serializer) { if (propertyName == "ConnectionStringObject") { writer.WriteString(this.ConnectionStringObject.ToFullString()); } else if (propertyName == "PropertyReference") { writer.WriteString(PropertyReferenceSerializer.Serialize(this.PropertyReference)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BulletedListEventArgs.cs
- ExpressionParser.cs
- EntityWithChangeTrackerStrategy.cs
- ChangeProcessor.cs
- FixedSOMImage.cs
- ApplicationFileCodeDomTreeGenerator.cs
- HttpHeaderCollection.cs
- FrameworkName.cs
- linebase.cs
- ErrorFormatter.cs
- TableSectionStyle.cs
- BaseCAMarshaler.cs
- ArcSegment.cs
- CultureInfoConverter.cs
- CodeExporter.cs
- UnsafeNativeMethods.cs
- XPathNodeIterator.cs
- AttributeAction.cs
- TimelineCollection.cs
- CodeArrayIndexerExpression.cs
- ComplexTypeEmitter.cs
- TraceContextRecord.cs
- OdbcEnvironmentHandle.cs
- PagesSection.cs
- LinearKeyFrames.cs
- DynamicILGenerator.cs
- DataObjectEventArgs.cs
- StateMachineWorkflowInstance.cs
- OleDbCommandBuilder.cs
- DbParameterCollectionHelper.cs
- securitymgrsite.cs
- InfiniteIntConverter.cs
- Calendar.cs
- OleAutBinder.cs
- MarshalDirectiveException.cs
- BaseParaClient.cs
- ContentPosition.cs
- TagMapCollection.cs
- VariantWrapper.cs
- QueryCacheManager.cs
- DynamicDataRouteHandler.cs
- LinkedResourceCollection.cs
- QilFunction.cs
- ValidationPropertyAttribute.cs
- KnownTypeHelper.cs
- BounceEase.cs
- HandlerFactoryCache.cs
- safex509handles.cs
- SHA256CryptoServiceProvider.cs
- ProfileGroupSettingsCollection.cs
- SuppressMergeCheckAttribute.cs
- HwndHostAutomationPeer.cs
- DataGridViewCellStyleConverter.cs
- SubMenuStyle.cs
- ASCIIEncoding.cs
- HttpStreamXmlDictionaryReader.cs
- XsltArgumentList.cs
- FilteredAttributeCollection.cs
- ZipIOFileItemStream.cs
- UiaCoreTypesApi.cs
- CatalogZone.cs
- ModelItemImpl.cs
- TimeoutException.cs
- ActivityWithResult.cs
- EventSinkHelperWriter.cs
- Atom10FormatterFactory.cs
- XPathNode.cs
- ToolStripContextMenu.cs
- FlowDecision.cs
- SystemResources.cs
- TouchesOverProperty.cs
- MultiDataTrigger.cs
- ItemsControlAutomationPeer.cs
- ScrollPattern.cs
- MSAAWinEventWrap.cs
- documentsequencetextview.cs
- EndpointInfo.cs
- PassportAuthenticationEventArgs.cs
- Win32.cs
- ConnectionPointCookie.cs
- SeekStoryboard.cs
- ProtectedConfigurationProviderCollection.cs
- ProfilePropertySettings.cs
- GiveFeedbackEventArgs.cs
- ResourceManagerWrapper.cs
- _NetworkingPerfCounters.cs
- LineSegment.cs
- Single.cs
- BackgroundFormatInfo.cs
- IndexerNameAttribute.cs
- ComplexTypeEmitter.cs
- SudsWriter.cs
- DataGridCommandEventArgs.cs
- EnumConverter.cs
- activationcontext.cs
- CompositionAdorner.cs
- TextControl.cs
- CancelEventArgs.cs
- XmlProcessingInstruction.cs
- Rectangle.cs