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
- MetadataSerializer.cs
- WebPartManager.cs
- VirtualPathUtility.cs
- TraceLevelStore.cs
- DataServiceConfiguration.cs
- LoginView.cs
- SmtpReplyReader.cs
- Win32.cs
- ClientConfigPaths.cs
- SmtpReplyReaderFactory.cs
- WindowsEditBoxRange.cs
- WebPartDisplayModeCancelEventArgs.cs
- InvokeMethodActivityDesigner.cs
- ByteStorage.cs
- PresentationTraceSources.cs
- HtmlFormWrapper.cs
- CacheAxisQuery.cs
- TableLayoutCellPaintEventArgs.cs
- ISO2022Encoding.cs
- Range.cs
- SignatureHelper.cs
- DataGridRowHeader.cs
- ImagingCache.cs
- querybuilder.cs
- QilGeneratorEnv.cs
- RetrieveVirtualItemEventArgs.cs
- PropertyTabAttribute.cs
- IsolatedStorageException.cs
- HtmlTernaryTree.cs
- Constants.cs
- RijndaelManagedTransform.cs
- PerformanceCountersElement.cs
- IISUnsafeMethods.cs
- SelectionProviderWrapper.cs
- UnsafeNativeMethods.cs
- ValidationPropertyAttribute.cs
- AsnEncodedData.cs
- FullTextBreakpoint.cs
- ResolvedKeyFrameEntry.cs
- SqlRowUpdatingEvent.cs
- GeneralTransform3DTo2DTo3D.cs
- MailAddress.cs
- EntityContainerRelationshipSetEnd.cs
- DrawingCollection.cs
- Int32CollectionConverter.cs
- StyleModeStack.cs
- Mapping.cs
- DBConnectionString.cs
- AccessDataSourceWizardForm.cs
- SourceElementsCollection.cs
- KeyValueInternalCollection.cs
- SizeChangedEventArgs.cs
- CachingHintValidation.cs
- OleDbParameterCollection.cs
- WindowsGrip.cs
- SqlVisitor.cs
- DependencyPropertyValueSerializer.cs
- WmpBitmapEncoder.cs
- ToolStrip.cs
- AnnotationResourceCollection.cs
- DataObjectEventArgs.cs
- BitmapFrameEncode.cs
- DataGridBoolColumn.cs
- JulianCalendar.cs
- DispatcherExceptionEventArgs.cs
- ByteViewer.cs
- TagPrefixCollection.cs
- ELinqQueryState.cs
- ThreadPool.cs
- HostingPreferredMapPath.cs
- SqlErrorCollection.cs
- ELinqQueryState.cs
- XsltArgumentList.cs
- FlowDocumentReaderAutomationPeer.cs
- MembershipUser.cs
- CredentialCache.cs
- JoinSymbol.cs
- DataGridBeginningEditEventArgs.cs
- WebPartCloseVerb.cs
- IteratorFilter.cs
- OperationExecutionFault.cs
- LoginUtil.cs
- CompressionTransform.cs
- SqlMethodAttribute.cs
- DupHandleConnectionReader.cs
- MessageEncoder.cs
- BigInt.cs
- HtmlSelect.cs
- DataMemberConverter.cs
- METAHEADER.cs
- TextBlockAutomationPeer.cs
- PropertyTabAttribute.cs
- login.cs
- AdRotator.cs
- BuildProvidersCompiler.cs
- TextDecoration.cs
- LocalFileSettingsProvider.cs
- _LocalDataStoreMgr.cs
- WebPartActionVerb.cs
- DefaultPrintController.cs