Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / Compilation / ConnectionStringsExpressionBuilder.cs / 1 / ConnectionStringsExpressionBuilder.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.Security.Permissions; using System.CodeDom; using System.Configuration; using System.Globalization; using System.Web.UI; [ExpressionPrefix("ConnectionStrings")] [ExpressionEditor("System.Web.UI.Design.ConnectionStringsExpressionEditor, " + AssemblyRef.SystemDesign)] [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class ConnectionStringsExpressionBuilder : ExpressionBuilder { public override bool SupportsEvaluate { get { return true; } } public override object ParseExpression(string expression, Type propertyType, ExpressionBuilderContext context) { // This code is also copied in ConnectionStringsExpressionEditor.ParseExpression() const string connectionStringSuffix = ".connectionstring"; const string providerNameSuffix = ".providername"; string name = String.Empty; bool connectionString = true; if (expression != null) { if (expression.EndsWith(connectionStringSuffix, StringComparison.OrdinalIgnoreCase)) { name = expression.Substring(0, expression.Length - connectionStringSuffix.Length); } else { if (expression.EndsWith(providerNameSuffix, StringComparison.OrdinalIgnoreCase)) { connectionString = false; name = expression.Substring(0, expression.Length - providerNameSuffix.Length); } else { name = expression; } } } return new Pair(name, connectionString); } public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { Pair p = (Pair)parsedData; string name = (string)p.First; bool connectionString = (bool)p.Second; if (connectionString) { return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()), "GetConnectionString", new CodePrimitiveExpression(name)); } else { return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()), "GetConnectionStringProviderName", new CodePrimitiveExpression(name)); } } public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { Pair p = (Pair)parsedData; string name = (string)p.First; bool connectionString = (bool)p.Second; ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[name]; if (connectionString) { return GetConnectionString(name); } else { return GetConnectionStringProviderName(name); } } public static string GetConnectionStringProviderName(string connectionStringName) { ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[connectionStringName]; if (setting == null) { throw new InvalidOperationException(SR.GetString(SR.Connection_string_not_found, connectionStringName)); } return setting.ProviderName; } public static string GetConnectionString(string connectionStringName) { ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[connectionStringName]; if (setting == null) { throw new InvalidOperationException(SR.GetString(SR.Connection_string_not_found, connectionStringName)); } return setting.ConnectionString; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.Security.Permissions; using System.CodeDom; using System.Configuration; using System.Globalization; using System.Web.UI; [ExpressionPrefix("ConnectionStrings")] [ExpressionEditor("System.Web.UI.Design.ConnectionStringsExpressionEditor, " + AssemblyRef.SystemDesign)] [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class ConnectionStringsExpressionBuilder : ExpressionBuilder { public override bool SupportsEvaluate { get { return true; } } public override object ParseExpression(string expression, Type propertyType, ExpressionBuilderContext context) { // This code is also copied in ConnectionStringsExpressionEditor.ParseExpression() const string connectionStringSuffix = ".connectionstring"; const string providerNameSuffix = ".providername"; string name = String.Empty; bool connectionString = true; if (expression != null) { if (expression.EndsWith(connectionStringSuffix, StringComparison.OrdinalIgnoreCase)) { name = expression.Substring(0, expression.Length - connectionStringSuffix.Length); } else { if (expression.EndsWith(providerNameSuffix, StringComparison.OrdinalIgnoreCase)) { connectionString = false; name = expression.Substring(0, expression.Length - providerNameSuffix.Length); } else { name = expression; } } } return new Pair(name, connectionString); } public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { Pair p = (Pair)parsedData; string name = (string)p.First; bool connectionString = (bool)p.Second; if (connectionString) { return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()), "GetConnectionString", new CodePrimitiveExpression(name)); } else { return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(this.GetType()), "GetConnectionStringProviderName", new CodePrimitiveExpression(name)); } } public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context) { Pair p = (Pair)parsedData; string name = (string)p.First; bool connectionString = (bool)p.Second; ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[name]; if (connectionString) { return GetConnectionString(name); } else { return GetConnectionStringProviderName(name); } } public static string GetConnectionStringProviderName(string connectionStringName) { ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[connectionStringName]; if (setting == null) { throw new InvalidOperationException(SR.GetString(SR.Connection_string_not_found, connectionStringName)); } return setting.ProviderName; } public static string GetConnectionString(string connectionStringName) { ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[connectionStringName]; if (setting == null) { throw new InvalidOperationException(SR.GetString(SR.Connection_string_not_found, connectionStringName)); } return setting.ConnectionString; } } } // 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
- DtrList.cs
- SystemEvents.cs
- ListViewItemSelectionChangedEvent.cs
- ArraySortHelper.cs
- ZipIOLocalFileBlock.cs
- DoubleLinkListEnumerator.cs
- SchemaMapping.cs
- PropertySourceInfo.cs
- ScriptingSectionGroup.cs
- QuotedPrintableStream.cs
- FirewallWrapper.cs
- OpenCollectionAsyncResult.cs
- ObjectQueryExecutionPlan.cs
- AssertValidation.cs
- InstanceDescriptor.cs
- DataObjectSettingDataEventArgs.cs
- RegisteredHiddenField.cs
- AssociatedControlConverter.cs
- BlurBitmapEffect.cs
- WpfGeneratedKnownProperties.cs
- ScriptingProfileServiceSection.cs
- FixedBufferAttribute.cs
- NegotiateStream.cs
- CategoryAttribute.cs
- GridViewSortEventArgs.cs
- InteropAutomationProvider.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- UIAgentMonitorHandle.cs
- CompilerTypeWithParams.cs
- xmlglyphRunInfo.cs
- OdbcParameterCollection.cs
- ColorMap.cs
- SQLChars.cs
- DataColumnSelectionConverter.cs
- PolicyLevel.cs
- DataGridViewDataConnection.cs
- _NativeSSPI.cs
- TaiwanCalendar.cs
- CircleHotSpot.cs
- ElementInit.cs
- ErrorHandler.cs
- DebugTraceHelper.cs
- HelpInfo.cs
- DecimalAnimationBase.cs
- SchemaSetCompiler.cs
- ManipulationVelocities.cs
- UnknownBitmapDecoder.cs
- ToolStripPanelRenderEventArgs.cs
- ToggleProviderWrapper.cs
- Currency.cs
- SmiEventStream.cs
- NavigationFailedEventArgs.cs
- CompressEmulationStream.cs
- MatrixCamera.cs
- ToolBarButtonClickEvent.cs
- UDPClient.cs
- XmlException.cs
- EventlogProvider.cs
- CanExecuteRoutedEventArgs.cs
- MessageEnumerator.cs
- InvalidProgramException.cs
- ComponentManagerBroker.cs
- Hashtable.cs
- ClientConvert.cs
- CanExecuteRoutedEventArgs.cs
- EDesignUtil.cs
- SchemaNotation.cs
- AuthStoreRoleProvider.cs
- TrustLevelCollection.cs
- JoinGraph.cs
- ExpressionBuilderContext.cs
- OleDbConnectionFactory.cs
- SimpleRecyclingCache.cs
- RelationshipNavigation.cs
- HttpCookie.cs
- RawTextInputReport.cs
- DataViewSetting.cs
- WindowsIdentity.cs
- DockAndAnchorLayout.cs
- CapabilitiesUse.cs
- XPathParser.cs
- Rect3DConverter.cs
- EditingCoordinator.cs
- EventListener.cs
- AlternateViewCollection.cs
- SafeRegistryHandle.cs
- ExecutorLocksHeldException.cs
- hwndwrapper.cs
- LongTypeConverter.cs
- diagnosticsswitches.cs
- CookieProtection.cs
- UpdateProgress.cs
- SafeBitVector32.cs
- ExtentCqlBlock.cs
- WorkflowTimerService.cs
- AccessedThroughPropertyAttribute.cs
- TextAdaptor.cs
- MessageSecurityOverMsmq.cs
- ThreadInterruptedException.cs
- dataSvcMapFileLoader.cs