Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Common / CommandTrees / Internal / DbExpressionRules.cs / 1305376 / DbExpressionRules.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Data.Common.CommandTrees; using System.Collections.Generic; using System.Data.Metadata.Edm; using System.Diagnostics; using System.Data.Common.Utils; using System.Linq; using System.Globalization; using System.Data.Common.CommandTrees.ExpressionBuilder; namespace System.Data.Common.CommandTrees.Internal { ////// Enacapsulates the logic that defines an expression 'rule' which is capable of transforming a candidate internal abstract class DbExpressionRule { ////// into a result DbExpression, and indicating what action should be taken on that result expression by the rule application logic. /// /// Indicates what action the rule processor should take if the rule successfully processes an expression. /// internal enum ProcessedAction { ////// Continue to apply rules, from the rule immediately following this rule, to the result expression /// Continue = 0, ////// Going back to the first rule, apply all rules to the result expression /// Reset, ////// Stop all rule processing and return the result expression as the final result expression /// Stop } ////// Indicates whether /// Theshould be called on the specified argument expression. /// that the rule should inspect and determine if processing is possible /// internal abstract bool ShouldProcess(DbExpression expression); /// true if the rule can attempt processing of the expression via themethod; otherwise false /// Attempts to process the input /// The input expression that the rule should process /// The result expression produced by the rule if processing was successful ///to produce a . /// internal abstract bool TryProcess(DbExpression expression, out DbExpression result); /// true if the rule was able to successfully process the input expression and produce a result expression; otherwisefalse /// Indicates what action - as a internal abstract ProcessedAction OnExpressionProcessed { get; } } ///value - the rule processor should take if returns true. /// /// Abstract base class for a DbExpression visitor that can apply a collection of internal abstract class DbExpressionRuleProcessingVisitor : DefaultExpressionVisitor { protected DbExpressionRuleProcessingVisitor() { } protected abstract IEnumerables during the visitor pass, returning the final result expression. /// This class encapsulates the rule application logic that applies regardless of how the ruleset - modelled as the abstract method - is provided. /// GetRules(); private static Tuple ProcessRules(DbExpression expression, List rules) { // Considering each rule in the rule set in turn, if the rule indicates that it can process the // input expression, call TryProcess to attempt processing. If successful, take the action specified // by the rule's OnExpressionProcessed action, which may involve returning the action and the result // expression so that processing can be reset or halted. for (int idx = 0; idx < rules.Count; idx++) { DbExpressionRule currentRule = rules[idx]; if (currentRule.ShouldProcess(expression)) { DbExpression result; if (currentRule.TryProcess(expression, out result)) { if (currentRule.OnExpressionProcessed != DbExpressionRule.ProcessedAction.Continue) { return Tuple.Create(result, currentRule.OnExpressionProcessed); } else { expression = result; } } } } return Tuple.Create(expression, DbExpressionRule.ProcessedAction.Continue); } private bool _stopped; private DbExpression ApplyRules(DbExpression expression) { // Driver loop to apply rules while the status of processing is 'Reset', // or correctly set the _stopped flag if status is 'Stopped'. List currentRules = this.GetRules().ToList(); var ruleResult = ProcessRules(expression, currentRules); while (ruleResult.Item2 == DbExpressionRule.ProcessedAction.Reset) { currentRules = this.GetRules().ToList(); ruleResult = ProcessRules(ruleResult.Item1, currentRules); } if (ruleResult.Item2 == DbExpressionRule.ProcessedAction.Stop) { _stopped = true; } return ruleResult.Item1; } protected override DbExpression VisitExpression(DbExpression expression) { // Pre-process this visitor's rules DbExpression result = ApplyRules(expression); if (_stopped) { // If rule processing was stopped, the result expression must be returned immediately return result; } // Visit the expression to recursively apply rules to subexpressions result = base.VisitExpression(result); if (_stopped) { // If rule processing was stopped, the result expression must be returned immediately return result; } // Post-process the rules over the resulting expression and return the result. // This is done so that rules that did not match the original structure of the // expression have an opportunity to examine the structure of the result expression. result = ApplyRules(result); return result; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Data.Common.CommandTrees; using System.Collections.Generic; using System.Data.Metadata.Edm; using System.Diagnostics; using System.Data.Common.Utils; using System.Linq; using System.Globalization; using System.Data.Common.CommandTrees.ExpressionBuilder; namespace System.Data.Common.CommandTrees.Internal { ////// Enacapsulates the logic that defines an expression 'rule' which is capable of transforming a candidate internal abstract class DbExpressionRule { ////// into a result DbExpression, and indicating what action should be taken on that result expression by the rule application logic. /// /// Indicates what action the rule processor should take if the rule successfully processes an expression. /// internal enum ProcessedAction { ////// Continue to apply rules, from the rule immediately following this rule, to the result expression /// Continue = 0, ////// Going back to the first rule, apply all rules to the result expression /// Reset, ////// Stop all rule processing and return the result expression as the final result expression /// Stop } ////// Indicates whether /// Theshould be called on the specified argument expression. /// that the rule should inspect and determine if processing is possible /// internal abstract bool ShouldProcess(DbExpression expression); /// true if the rule can attempt processing of the expression via themethod; otherwise false /// Attempts to process the input /// The input expression that the rule should process /// The result expression produced by the rule if processing was successful ///to produce a . /// internal abstract bool TryProcess(DbExpression expression, out DbExpression result); /// true if the rule was able to successfully process the input expression and produce a result expression; otherwisefalse /// Indicates what action - as a internal abstract ProcessedAction OnExpressionProcessed { get; } } ///value - the rule processor should take if returns true. /// /// Abstract base class for a DbExpression visitor that can apply a collection of internal abstract class DbExpressionRuleProcessingVisitor : DefaultExpressionVisitor { protected DbExpressionRuleProcessingVisitor() { } protected abstract IEnumerables during the visitor pass, returning the final result expression. /// This class encapsulates the rule application logic that applies regardless of how the ruleset - modelled as the abstract method - is provided. /// GetRules(); private static Tuple ProcessRules(DbExpression expression, List rules) { // Considering each rule in the rule set in turn, if the rule indicates that it can process the // input expression, call TryProcess to attempt processing. If successful, take the action specified // by the rule's OnExpressionProcessed action, which may involve returning the action and the result // expression so that processing can be reset or halted. for (int idx = 0; idx < rules.Count; idx++) { DbExpressionRule currentRule = rules[idx]; if (currentRule.ShouldProcess(expression)) { DbExpression result; if (currentRule.TryProcess(expression, out result)) { if (currentRule.OnExpressionProcessed != DbExpressionRule.ProcessedAction.Continue) { return Tuple.Create(result, currentRule.OnExpressionProcessed); } else { expression = result; } } } } return Tuple.Create(expression, DbExpressionRule.ProcessedAction.Continue); } private bool _stopped; private DbExpression ApplyRules(DbExpression expression) { // Driver loop to apply rules while the status of processing is 'Reset', // or correctly set the _stopped flag if status is 'Stopped'. List currentRules = this.GetRules().ToList(); var ruleResult = ProcessRules(expression, currentRules); while (ruleResult.Item2 == DbExpressionRule.ProcessedAction.Reset) { currentRules = this.GetRules().ToList(); ruleResult = ProcessRules(ruleResult.Item1, currentRules); } if (ruleResult.Item2 == DbExpressionRule.ProcessedAction.Stop) { _stopped = true; } return ruleResult.Item1; } protected override DbExpression VisitExpression(DbExpression expression) { // Pre-process this visitor's rules DbExpression result = ApplyRules(expression); if (_stopped) { // If rule processing was stopped, the result expression must be returned immediately return result; } // Visit the expression to recursively apply rules to subexpressions result = base.VisitExpression(result); if (_stopped) { // If rule processing was stopped, the result expression must be returned immediately return result; } // Post-process the rules over the resulting expression and return the result. // This is done so that rules that did not match the original structure of the // expression have an opportunity to examine the structure of the result expression. result = ApplyRules(result); return result; } } } // 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
- InternalBase.cs
- CheckBox.cs
- StateBag.cs
- SimpleExpression.cs
- SimpleWebHandlerParser.cs
- TreeViewItem.cs
- HMACRIPEMD160.cs
- SynchronizedInputProviderWrapper.cs
- HttpRawResponse.cs
- DataRow.cs
- TextServicesManager.cs
- BinaryFormatter.cs
- UrlMappingCollection.cs
- PartBasedPackageProperties.cs
- AssociationType.cs
- AutomationElementIdentifiers.cs
- Image.cs
- DataGridViewRowHeaderCell.cs
- CodeParameterDeclarationExpression.cs
- ConstructorExpr.cs
- CompiledIdentityConstraint.cs
- ProfileBuildProvider.cs
- SqlDelegatedTransaction.cs
- InputScope.cs
- ServiceHostingEnvironment.cs
- ContentElement.cs
- ExtendedPropertyCollection.cs
- XPathNodeInfoAtom.cs
- RuntimeHelpers.cs
- ProcessThread.cs
- BamlLocalizableResource.cs
- Rotation3DAnimationBase.cs
- NameValueConfigurationElement.cs
- HealthMonitoringSectionHelper.cs
- ConversionContext.cs
- RequestContext.cs
- DoubleAnimationBase.cs
- ByteAnimation.cs
- Adorner.cs
- ManualResetEventSlim.cs
- ChildrenQuery.cs
- XmlArrayAttribute.cs
- Int32RectConverter.cs
- infer.cs
- SoapFault.cs
- RuleAction.cs
- Parameter.cs
- ISAPIWorkerRequest.cs
- Exceptions.cs
- SpeakProgressEventArgs.cs
- MetroSerializationManager.cs
- SignatureHelper.cs
- EffectiveValueEntry.cs
- ParentUndoUnit.cs
- TypeLibConverter.cs
- NetTcpSecurityElement.cs
- unitconverter.cs
- XmlElement.cs
- PerfCounterSection.cs
- EditorPart.cs
- ImmutableCommunicationTimeouts.cs
- SqlDeflator.cs
- HtmlPhoneCallAdapter.cs
- EmbeddedMailObject.cs
- SpeechSynthesizer.cs
- GeometryModel3D.cs
- CustomWebEventKey.cs
- HtmlInputButton.cs
- HyperLink.cs
- PermissionAttributes.cs
- KeyboardDevice.cs
- SqlHelper.cs
- SmiEventSink.cs
- InfoCardListRequest.cs
- ContextMenu.cs
- DataGridViewCheckBoxColumn.cs
- SystemNetworkInterface.cs
- BuildDependencySet.cs
- StylesEditorDialog.cs
- QilNode.cs
- InitializationEventAttribute.cs
- NoneExcludedImageIndexConverter.cs
- ListControlBuilder.cs
- DataGridViewDataErrorEventArgs.cs
- ButtonColumn.cs
- FormsAuthenticationCredentials.cs
- StructuralObject.cs
- Queue.cs
- CodeEventReferenceExpression.cs
- CompilerResults.cs
- TextStore.cs
- CompileXomlTask.cs
- EntityProxyFactory.cs
- ThreadAttributes.cs
- LogAppendAsyncResult.cs
- XamlInt32CollectionSerializer.cs
- ParameterModifier.cs
- ContextBase.cs
- translator.cs
- linebase.cs