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
- Authorization.cs
- InstanceKeyCompleteException.cs
- WpfXamlType.cs
- ProxyHelper.cs
- Win32Exception.cs
- ResourcesChangeInfo.cs
- ParameterModifier.cs
- WebPartVerbCollection.cs
- ColorAnimation.cs
- ReadContentAsBinaryHelper.cs
- PenContext.cs
- LocalValueEnumerator.cs
- PropertyEntry.cs
- ToolZoneDesigner.cs
- InputBindingCollection.cs
- HtmlContainerControl.cs
- DataGridViewTextBoxColumn.cs
- UdpChannelListener.cs
- XPathSelectionIterator.cs
- TraceSection.cs
- securitymgrsite.cs
- UrlAuthFailureHandler.cs
- InfoCardBaseException.cs
- UInt64Storage.cs
- ScrollItemPattern.cs
- DictionarySurrogate.cs
- BaseProcessor.cs
- UdpTransportBindingElement.cs
- IteratorFilter.cs
- DoWorkEventArgs.cs
- safesecurityhelperavalon.cs
- ComPlusServiceHost.cs
- CachedTypeface.cs
- UserPersonalizationStateInfo.cs
- CloudCollection.cs
- EntitySetBase.cs
- ModuleBuilder.cs
- DataObjectMethodAttribute.cs
- StringDictionaryEditor.cs
- Exceptions.cs
- SharedConnectionListener.cs
- NumberFormatInfo.cs
- HtmlInputButton.cs
- EntityDataSourceEntitySetNameItem.cs
- DispatchChannelSink.cs
- InkPresenterAutomationPeer.cs
- SmiRequestExecutor.cs
- Deserializer.cs
- DrawingGroup.cs
- ConnectorDragDropGlyph.cs
- UnsafeNativeMethodsPenimc.cs
- FaultFormatter.cs
- EnlistmentTraceIdentifier.cs
- CodeMemberMethod.cs
- ListViewItemMouseHoverEvent.cs
- ControlType.cs
- LogEntrySerialization.cs
- XmlBinaryReader.cs
- WebPartZoneBase.cs
- DispatcherSynchronizationContext.cs
- SignatureToken.cs
- QuadraticBezierSegment.cs
- ActivityFunc.cs
- SapiAttributeParser.cs
- WindowsListViewGroup.cs
- SendingRequestEventArgs.cs
- MimeReflector.cs
- OdbcException.cs
- PerformanceCounterLib.cs
- OSFeature.cs
- IsolationInterop.cs
- ScrollChrome.cs
- TreeNodeCollectionEditor.cs
- Wildcard.cs
- ContextProperty.cs
- SchemaImporterExtensionElementCollection.cs
- UnsafeNativeMethods.cs
- ConfigurationException.cs
- EmbeddedMailObject.cs
- JobCollate.cs
- UserControlCodeDomTreeGenerator.cs
- TextTreeInsertElementUndoUnit.cs
- Journal.cs
- UnaryNode.cs
- Decimal.cs
- GradientBrush.cs
- WebProxyScriptElement.cs
- _ContextAwareResult.cs
- SqlRowUpdatedEvent.cs
- BitmapFrame.cs
- BinaryUtilClasses.cs
- TableDetailsRow.cs
- xdrvalidator.cs
- HtmlTableRow.cs
- PenThread.cs
- VisualCollection.cs
- CollectionViewGroupInternal.cs
- PublisherIdentityPermission.cs
- MatrixKeyFrameCollection.cs
- WebServiceHandlerFactory.cs