| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Text; |
| | | 4 | | using Microsoft.Xrm.Sdk; |
| | | 5 | | using Microsoft.Xrm.Sdk.Query; |
| | | 6 | | |
| | | 7 | | namespace Xrm.Oss.XTL.Interpreter |
| | | 8 | | { |
| | | 9 | | public static class DataRetriever |
| | | 10 | | { |
| | | 11 | | public static ValueExpression ResolveTokenValue(string token, Entity primary, IOrganizationService service, Conf |
| | 105 | 12 | | { |
| | 105 | 13 | | var path = new Queue<string>(token.Split('.')); |
| | 105 | 14 | | var currentEntity = primary; |
| | 105 | 15 | | ValueExpression value = null; |
| | | 16 | | |
| | | 17 | | do |
| | 113 | 18 | | { |
| | 113 | 19 | | var currentField = path.Dequeue(); |
| | 113 | 20 | | var currentObject = currentEntity.GetAttributeValue<object>(currentField); |
| | | 21 | | |
| | 113 | 22 | | if (currentObject == null) |
| | 13 | 23 | | { |
| | 13 | 24 | | return new ValueExpression(null); |
| | | 25 | | } |
| | | 26 | | |
| | 100 | 27 | | var entityReference = currentObject as EntityReference; |
| | 100 | 28 | | var nextField = path.Count > 0 ? path.Peek() : null; |
| | | 29 | | |
| | 100 | 30 | | if (entityReference == null || (entityReference != null && nextField == null)) |
| | 92 | 31 | | { |
| | 92 | 32 | | value = new ValueExpression(PropertyStringifier.Stringify(currentField, currentEntity, service, conf |
| | 92 | 33 | | } |
| | | 34 | | else |
| | 8 | 35 | | { |
| | 8 | 36 | | currentEntity = service.Retrieve(entityReference.LogicalName, entityReference.Id, new ColumnSet(next |
| | 8 | 37 | | } |
| | 200 | 38 | | } while (path.Count > 0); |
| | | 39 | | |
| | 92 | 40 | | return value; |
| | 105 | 41 | | } |
| | | 42 | | } |
| | | 43 | | } |