작업 2: PolicyActivity 및 RuleSet 만들기
작업 1: ConditionedActivityGroup 활동 만들기에서는 쿠폰이 큐에 남아 있지 않을 때까지 포함된 모든 자식 활동을 실행하는 ConditionedActivityGroup 활동을 워크플로에 추가했습니다. 쿠폰은 ConditionedActivityGroup에서 CodeActivity를 사용하여 제거됩니다.
이 작업에서는 단일 PolicyActivity 활동을 추가합니다. 이 PolicyActivity 활동은 각각의 네 가지 쿠폰 유형에 해당하는 네 가지 규칙이 포함된 RuleSet을 사용합니다. ConditionedActivityGroup 활동이 모든 쿠폰을 열거할 때 각 규칙이 확인됩니다. 규칙의 Condition이 true로 확인되면 해당 쿠폰과 연결된 논리가 적용됩니다.
PolicyActivity를 만들려면
DiscountWorkflow 클래스에서 couponPolicy라는 private PolicyActivity를 만듭니다.
this.couponPolicy = new System.Workflow.Activities.PolicyActivity();
DiscountWorkflow 클래스의 InitializeComponent 메서드에서 이전 단계에서 만든 PolicyActivity 개체의 인스턴스를 만듭니다.
이 부분은 CanModifyActivities 속성을 설정하는 줄 뒤에 나옵니다.
System.Workflow.Activities.Rules.RuleSetReference rulesetreference1 = new System.Workflow.Activities.Rules.RuleSetReference();
rulesetreference1이라는 InitializeComponent 메서드에서 지역 RuleSetReference 변수를 만들고 해당 개체의 인스턴스를 만듭니다.
this.conditionedActivityGroup1.Activities.Add(this.couponPolicy);
InitializeComponent 메서드에서 Activities 속성에 정의된 Add 메서드를 사용하여 couponPolicy 개체를 conditionedActivityGroup1 개체의 Activities 컬렉션에 추가합니다.
참고
removeCoupon 개체를 추가하기 전에 couponPolicy 개체를 추가해야 합니다. 자식 활동은 ConditionedActivityGroup에 추가되는 순서에 따라 실행됩니다.
// // couponPolicy // this.couponPolicy.Name = "couponPolicy"; rulesetreference1.RuleSetName = "RuleSet1"; this.couponPolicy.RuleSetReference = rulesetreference1;
couponPolicy 개체의 Name 속성을 "couponPolicy" 값으로 설정합니다.
rulesetreference1 개체의 RuleSetName을 "RuleSet1" 값으로 설정합니다.
참고
다음 절차에서 이 RuleSet을 만듭니다.
couponPolicy 개체의 RuleSetReference 속성을 rulesetreference1로 설정합니다. 이렇게 하면 PolicyActivity가 쿠폰을 처리하는 데 사용되는 규칙이 포함된 RuleSet과 연결됩니다.
this.couponPolicy.SetValue( System.Workflow.Activities.ConditionedActivityGroup.WhenConditionProperty , ruleconditionreference3);
couponPolicy 개체에 정의된 SetValue 메서드를 호출하여 WhenConditionProperty 형식과 ruleconditionreference3 개체를 매개 변수로 전달합니다.
참고
PolicyActivity 활동의 WhenConditionProperty를 설정하면 ConditionedActivityGroup 활동이 자식 활동을 열거할 때마다 PolicyActivity 활동이 실행됩니다. ConditionedActivityGroup에서 자식 활동의 WhenConditionProperty 조건을 지정하지 않으면 해당 자식 활동이 한 번만 실행됩니다.
쿠폰 RuleSet을 만들려면
DiscountWorkflow.rules 파일에서 RuleDefinitions.RuleSets라는 새 요소를 RuleDefinitions 루트 요소에 추가합니다.
RuleSet이라는 자식 요소를 RuleDefinitions.RuleSets 요소에 추가합니다.
이전 단계에서 만든 Name이라는 RuleSet 요소에 특성을 추가하고 "RuleSet1" 값을 지정합니다.
3단계에서 만든 ChainingBehavior라는 RuleSet 요소에 특성을 추가하고 "Full" 값을 지정합니다.
3단계에서 만든 Description이라는 RuleSet 요소에 특성을 추가하고 "Coupon RuleSet" 값을 지정합니다.
RuleSet.Rules라는 자식 요소를 RuleSet 요소에 추가합니다.
DiscountWorkflow.rules 파일은 다음 코드와 유사합니다.
<RuleDefinitions xmlns="https://schemas.microsoft.com/winfx/2006/xaml/workflow"> <RuleDefinitions.Conditions> <!-- Conditions hidden for this example for readability --> </RuleDefinitions.Conditions> <RuleDefinitions.RuleSets> <RuleSet Name="RuleSet1" ChainingBehavior="Full" Description="Coupon RuleSet"> <RuleSet.Rules> </RuleSet.Rules> </RuleSet> </RuleDefinitions.RuleSets> </RuleDefinitions>
getFreeItems 규칙을 만들려면
이전 절차에서 만든 RuleSet.Rules 요소로 다음 Rule을 복사합니다.
<Rule Name="getFreeItem" ReevaluationBehavior="Always" Priority="0" Description="{p5:Null}" Active="True" xmlns:p5="https://schemas.microsoft.com/winfx/2006/xaml"> <Rule.ThenActions> <RuleStatementAction> <RuleStatementAction.CodeDomStatement> <ns0:CodeAssignStatement LinePragma="{p5:Null}" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeAssignStatement.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeAssignStatement.Left> <ns0:CodeAssignStatement.Right> <ns0:CodeBinaryOperatorExpression Operator="Add"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeFieldReferenceExpression FieldName="price"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeIndexerExpression> <ns0:CodeIndexerExpression.Indices> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">0</ns1:Int32> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeIndexerExpression.Indices> <ns0:CodeIndexerExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Items"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeIndexerExpression.TargetObject> </ns0:CodeIndexerExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeAssignStatement.Right> </ns0:CodeAssignStatement> </RuleStatementAction.CodeDomStatement> </RuleStatementAction> </Rule.ThenActions> <Rule.Condition> <RuleExpressionCondition Name="{p5:Null}"> <RuleExpressionCondition.Expression> <ns0:CodeBinaryOperatorExpression Operator="BooleanAnd" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression Operator="ValueEquality"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="type"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeMethodInvokeExpression> <ns0:CodeMethodInvokeExpression.Method> <ns0:CodeMethodReferenceExpression MethodName="Peek"> <ns0:CodeMethodReferenceExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Coupons"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeMethodReferenceExpression.TargetObject> </ns0:CodeMethodReferenceExpression> </ns0:CodeMethodInvokeExpression.Method> </ns0:CodeMethodInvokeExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeFieldReferenceExpression FieldName="FreeItem"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeTypeReferenceExpression Type="Microsoft.Samples.Workflow.Tutorials.RulesAndConditions.DiscountWorkflow+CouponType" /> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeBinaryOperatorExpression Operator="GreaterThanOrEqual"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="Count"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Items"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">5</ns1:Int32> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </RuleExpressionCondition.Expression> </RuleExpressionCondition> </Rule.Condition> </Rule>
applyPercentageOffHighest 규칙을 만들려면
이전 절차에서 만든 RuleSet.Rules 요소로 다음 Rule을 복사합니다.
<Rule Name="applyPercentageOffHighest" ReevaluationBehavior="Always" Priority="0" Description="{p5:Null}" Active="True" xmlns:p5="https://schemas.microsoft.com/winfx/2006/xaml"> <Rule.ThenActions> <RuleStatementAction> <RuleStatementAction.CodeDomStatement> <ns0:CodeAssignStatement LinePragma="{p5:Null}" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeAssignStatement.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeAssignStatement.Left> <ns0:CodeAssignStatement.Right> <ns0:CodeBinaryOperatorExpression Operator="Add"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeBinaryOperatorExpression Operator="Multiply"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="price"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeIndexerExpression> <ns0:CodeIndexerExpression.Indices> <ns0:CodeBinaryOperatorExpression Operator="Subtract"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="Count"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Items"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">1</ns1:Int32> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeIndexerExpression.Indices> <ns0:CodeIndexerExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Items"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeIndexerExpression.TargetObject> </ns0:CodeIndexerExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Double xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">0.1</ns1:Double> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeAssignStatement.Right> </ns0:CodeAssignStatement> </RuleStatementAction.CodeDomStatement> </RuleStatementAction> </Rule.ThenActions> <Rule.Condition> <RuleExpressionCondition Name="{p5:Null}"> <RuleExpressionCondition.Expression> <ns0:CodeBinaryOperatorExpression Operator="ValueEquality" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="type"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeMethodInvokeExpression> <ns0:CodeMethodInvokeExpression.Method> <ns0:CodeMethodReferenceExpression MethodName="Peek"> <ns0:CodeMethodReferenceExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Coupons"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeMethodReferenceExpression.TargetObject> </ns0:CodeMethodReferenceExpression> </ns0:CodeMethodInvokeExpression.Method> </ns0:CodeMethodInvokeExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeFieldReferenceExpression FieldName="PercentageOffHighest"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeTypeReferenceExpression Type="Microsoft.Samples.Workflow.Tutorials.RulesAndConditions.DiscountWorkflow+CouponType" /> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </RuleExpressionCondition.Expression> </RuleExpressionCondition> </Rule.Condition> </Rule>
절차 제목
이전 절차에서 만든 RuleSet.Rules 요소로 다음 Rule을 복사합니다.
<Rule Name="applyPercentageOffLowest" ReevaluationBehavior="Always" Priority="0" Description="{p5:Null}" Active="True" xmlns:p5="https://schemas.microsoft.com/winfx/2006/xaml"> <Rule.ThenActions> <RuleStatementAction> <RuleStatementAction.CodeDomStatement> <ns0:CodeAssignStatement LinePragma="{p5:Null}" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeAssignStatement.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeAssignStatement.Left> <ns0:CodeAssignStatement.Right> <ns0:CodeBinaryOperatorExpression Operator="Add"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeBinaryOperatorExpression Operator="Multiply"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="price"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeIndexerExpression> <ns0:CodeIndexerExpression.Indices> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">0</ns1:Int32> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeIndexerExpression.Indices> <ns0:CodeIndexerExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Items"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeIndexerExpression.TargetObject> </ns0:CodeIndexerExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Double xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">0.15</ns1:Double> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeAssignStatement.Right> </ns0:CodeAssignStatement> </RuleStatementAction.CodeDomStatement> </RuleStatementAction> </Rule.ThenActions> <Rule.Condition> <RuleExpressionCondition Name="{p5:Null}"> <RuleExpressionCondition.Expression> <ns0:CodeBinaryOperatorExpression Operator="ValueEquality" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="type"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeMethodInvokeExpression> <ns0:CodeMethodInvokeExpression.Method> <ns0:CodeMethodReferenceExpression MethodName="Peek"> <ns0:CodeMethodReferenceExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Coupons"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeMethodReferenceExpression.TargetObject> </ns0:CodeMethodReferenceExpression> </ns0:CodeMethodInvokeExpression.Method> </ns0:CodeMethodInvokeExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeFieldReferenceExpression FieldName="PercentageOffLowest"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeTypeReferenceExpression Type="Microsoft.Samples.Workflow.Tutorials.RulesAndConditions.DiscountWorkflow+CouponType" /> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </RuleExpressionCondition.Expression> </RuleExpressionCondition> </Rule.Condition> </Rule>
applyPercentageOffLowest 규칙을 만들려면
이전 절차에서 만든 RuleSet.Rules 요소로 다음 Rule을 복사합니다.
<Rule Name="applyPercentageOffLowest" ReevaluationBehavior="Always" Priority="0" Description="{p5:Null}" Active="True" xmlns:p5="https://schemas.microsoft.com/winfx/2006/xaml"> <Rule.ThenActions> <RuleStatementAction> <RuleStatementAction.CodeDomStatement> <ns0:CodeAssignStatement LinePragma="{p5:Null}" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeAssignStatement.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeAssignStatement.Left> <ns0:CodeAssignStatement.Right> <ns0:CodeBinaryOperatorExpression Operator="Add"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeBinaryOperatorExpression Operator="Multiply"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="price"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeIndexerExpression> <ns0:CodeIndexerExpression.Indices> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Int32 xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">0</ns1:Int32> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeIndexerExpression.Indices> <ns0:CodeIndexerExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Items"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeIndexerExpression.TargetObject> </ns0:CodeIndexerExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Double xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">0.15</ns1:Double> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeAssignStatement.Right> </ns0:CodeAssignStatement> </RuleStatementAction.CodeDomStatement> </RuleStatementAction> </Rule.ThenActions> <Rule.Condition> <RuleExpressionCondition Name="{p5:Null}"> <RuleExpressionCondition.Expression> <ns0:CodeBinaryOperatorExpression Operator="ValueEquality" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="type"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeMethodInvokeExpression> <ns0:CodeMethodInvokeExpression.Method> <ns0:CodeMethodReferenceExpression MethodName="Peek"> <ns0:CodeMethodReferenceExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Coupons"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeMethodReferenceExpression.TargetObject> </ns0:CodeMethodReferenceExpression> </ns0:CodeMethodInvokeExpression.Method> </ns0:CodeMethodInvokeExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeFieldReferenceExpression FieldName="PercentageOffLowest"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeTypeReferenceExpression Type="Microsoft.Samples.Workflow.Tutorials.RulesAndConditions.DiscountWorkflow+CouponType" /> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </RuleExpressionCondition.Expression> </RuleExpressionCondition> </Rule.Condition> </Rule>
applyPercentageOffTotal 규칙을 만들려면
이전 절차에서 만든 RuleSet.Rules 요소로 다음 Rule을 복사합니다.
<Rule Name="applyPercentageOffTotal" ReevaluationBehavior="Always" Priority="0" Description="{p5:Null}" Active="True" xmlns:p5="https://schemas.microsoft.com/winfx/2006/xaml"> <Rule.ThenActions> <RuleStatementAction> <RuleStatementAction.CodeDomStatement> <ns0:CodeAssignStatement LinePragma="{p5:Null}" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeAssignStatement.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeAssignStatement.Left> <ns0:CodeAssignStatement.Right> <ns0:CodeBinaryOperatorExpression Operator="Add"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="Discount"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeBinaryOperatorExpression Operator="Multiply"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodePropertyReferenceExpression PropertyName="SubTotal"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodePrimitiveExpression> <ns0:CodePrimitiveExpression.Value> <ns1:Double xmlns:ns1="clr-namespace:System;Assembly=mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">0.2</ns1:Double> </ns0:CodePrimitiveExpression.Value> </ns0:CodePrimitiveExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </ns0:CodeAssignStatement.Right> </ns0:CodeAssignStatement> </RuleStatementAction.CodeDomStatement> </RuleStatementAction> </Rule.ThenActions> <Rule.Condition> <RuleExpressionCondition Name="{p5:Null}"> <RuleExpressionCondition.Expression> <ns0:CodeBinaryOperatorExpression Operator="ValueEquality" xmlns:ns0="clr-namespace:System.CodeDom;Assembly=System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeFieldReferenceExpression FieldName="type"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeMethodInvokeExpression> <ns0:CodeMethodInvokeExpression.Method> <ns0:CodeMethodReferenceExpression MethodName="Peek"> <ns0:CodeMethodReferenceExpression.TargetObject> <ns0:CodePropertyReferenceExpression PropertyName="Coupons"> <ns0:CodePropertyReferenceExpression.TargetObject> <ns0:CodeThisReferenceExpression /> </ns0:CodePropertyReferenceExpression.TargetObject> </ns0:CodePropertyReferenceExpression> </ns0:CodeMethodReferenceExpression.TargetObject> </ns0:CodeMethodReferenceExpression> </ns0:CodeMethodInvokeExpression.Method> </ns0:CodeMethodInvokeExpression> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Left> <ns0:CodeBinaryOperatorExpression.Right> <ns0:CodeFieldReferenceExpression FieldName="PercentageOffTotal"> <ns0:CodeFieldReferenceExpression.TargetObject> <ns0:CodeTypeReferenceExpression Type="Microsoft.Samples.Workflow.Tutorials.RulesAndConditions.DiscountWorkflow+CouponType" /> </ns0:CodeFieldReferenceExpression.TargetObject> </ns0:CodeFieldReferenceExpression> </ns0:CodeBinaryOperatorExpression.Right> </ns0:CodeBinaryOperatorExpression> </RuleExpressionCondition.Expression> </RuleExpressionCondition> </Rule.Condition> </Rule>
코드 컴파일
코드 컴파일에 대한 자세한 내용은 코드 컴파일을 참조하십시오.
자습서의 완성된 버전을 보려면 규칙 및 조건 총괄 자습서를 참조하십시오.
참고 항목
참조
ConditionedActivityGroup
UntilCondition
RuleConditionReference
ConditionName
Activities
WhenConditionProperty
SetValue
기타 리소스
IfElse With Rules
Rules and Conditions
Copyright © 2007 by Microsoft Corporation. All rights reserved.