2 // Copyright (c) Microsoft Corporation. All rights reserved.
5 namespace System.Activities.Core.Presentation
7 using System.Activities.Presentation.Validation;
8 using System.Activities.Statements;
9 using System.Collections.Generic;
11 internal class PickValidationErrorSourceLocator : IValidationErrorSourceLocator
13 public List<object> FindSourceDetailFromActivity(Activity errorSource, object errorSourceDetail)
15 if (errorSourceDetail == null)
17 return new List<object> { errorSource };
21 return FindRelativePath((Pick)errorSource, errorSourceDetail);
25 public void ReplaceParentChainWithSource(Activity parentActivity, List<object> parentChain)
27 Pick pick = (Pick)parentActivity;
29 if (parentChain.Count > 1)
31 // assume last object in parentChain is PickBranchBody
33 // remove PickBranchBody
34 parentChain.RemoveAt(parentChain.Count - 1);
36 Activity targetActivity = (Activity)parentChain[parentChain.Count - 1];
38 // the targetActivity will be available in the path
39 parentChain.RemoveAt(parentChain.Count - 1);
41 List<object> path = FindRelativePath(pick, targetActivity);
43 foreach (object pathObject in path)
45 parentChain.Add(pathObject);
50 private static List<object> FindRelativePath(Pick pickActivity, object descendent)
52 List<object> path = FindDescendentFromPick(pickActivity, descendent);
57 private static List<object> FindDescendentFromPick(Pick pickActivity, object descendent)
59 List<object> path = new List<object>();
60 path.Add(pickActivity);
61 foreach (PickBranch branch in pickActivity.Branches)
63 if (branch == descendent)
67 else if (branch.Trigger == descendent)
72 else if (branch.Action == descendent)
79 bool isVariableError = false;
80 foreach (Variable variable in branch.Variables)
82 if (variable.Default == descendent)
84 isVariableError = true;