protected virtual object Execute(IUser dealer, object parameterObj, IReadOnlyState states, Context context) { if (!this.hasFullChildren) { var inputDic = JSON.ToDict(inputs, "nextDealerId", "nextDealerName", "isDone"); return(inputDic); } else { var children = this.Children; if (children.Count == 0) { this.StartChildActivity(context); } else { var actived = children.Where(p => p.Status != ActivityStates.Canceled && p.Status != ActivityStates.Completed); if (actived.Count() > 0) { foreach (var activity in actived) { activity.Process(context); } } else { return(new Dictionary <string, string>()); } } return(null); } }
private void AugmentArray( object obj, NestedTypeConfiguration ntc, object arr, APropertyInfo property, AArray nestedList, IReadOnlyState state, List <TypeConfiguration> tcs) { var asEnumerable = arr as IEnumerable; Debug.Assert(asEnumerable != null, "asEnumerable != null"); foreach (var item in asEnumerable) { var actual = item; if (property.TypeInfoWrapper.IsWrapper) { if (item is AugmenterWrapper wrapper) { actual = wrapper.Object; } } var dict = new AObject(); CopyAndAugmentObject(actual, tcs, dict, state, ntc, obj); nestedList.Add(dict); } }
private void AugmentArray( object obj, NestedTypeConfiguration ntc, object arr, APropertyInfo property, AArray nestedList, IReadOnlyState state, List <TypeConfiguration> typeConfigurations) { var asEnumerable = arr as IEnumerable; Debug.Assert(asEnumerable != null, "asEnumerable != null"); foreach (var item in asEnumerable) { var actual = item; if (property.TypeInfoWrapper.IsWrapper) { if (item is AugmenterWrapper wrapper) { actual = wrapper.Object; } } var dict = new AObject(); // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < typeConfigurations.Count; i++) { var tc = typeConfigurations[i]; var nestedState = CreateNestedState(obj, ntc, state); AugmentObject(actual, tc, dict, nestedState); } nestedList.Add(dict); } }
private void ApplyRemoveAugment(object obj, AObject root, Augment augment, IReadOnlyState state) { var value = augment.ValueFunc?.Invoke(obj, state); if (ShouldIgnoreAugment(value)) { return; } root.Remove(augment.Name); }
private void ApplyAddAugment(object obj, AObject root, Augment augment, IReadOnlyState state) { var value = augment.ValueFunc(obj, state); if (ShouldIgnoreAugment(value)) { return; } root[augment.Name] = augment.ValueFunc(obj, state); }
public State(IReadOnlyState state1, State state2) { foreach (var pair in state1) { this[pair.Key] = pair.Value; } foreach (var pair in state2) { this[pair.Key] = pair.Value; } }
void CombineState(IReadOnlyState append) { if (append != null && append.HasChanges) { var state = append as ReadOnlyState; foreach (var pair in state.Internals) { Internals[pair.Key] = pair.Value; } } }
private void ApplyAugment(object obj, AObject root, Augment augment, IReadOnlyState state) { switch (augment.Kind) { case AugmentKind.Add: ApplyAddAugment(obj, root, augment, state); break; case AugmentKind.Remove: ApplyRemoveAugment(obj, root, augment, state); break; default: throw new ArgumentOutOfRangeException(); } }
public virtual IReadOnlyDictionary <string, string> Navigate(IReadOnlyState states, Context context = null) { var assoc = this.Association; if (string.IsNullOrWhiteSpace(assoc.Key)) { throw new Exception("必须要有key"); } if (!states.TryGetValue(assoc.Key, out string value)) { return(null); } if (value != this.Association.Value) { return(null); } return(new Dictionary <string, string>()); }
public AugmentationContext(object obj, TypeConfiguration typeConfiguration, IReadOnlyState state) { Object = obj; TypeConfiguration = typeConfiguration; State = state; }
private void CopyObject(object obj, TypeConfiguration typeConfiguration, AObject root, IReadOnlyState state) { foreach (var property in typeConfiguration.Properties) { var nestedObject = property.GetValue(obj); if (property.TypeConfiguration == null) { // This should be copied verbatim. // REVIEW: Should we check if it's wrapped and unwrap it? root[property.PropertyInfo.Name] = nestedObject; } else { if (nestedObject == null) { root[property.PropertyInfo.Name] = null; } else if (!property.TypeInfoWrapper.IsArray) { var ntc = GetNestedTypeConfiguration(typeConfiguration, property); var done = false; if (property.TypeInfoWrapper.IsWrapper) { var wrapper = nestedObject as AugmenterWrapper; Debug.Assert(wrapper != null, "wrapper != null"); nestedObject = wrapper.Object; if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(nestedObject.GetType().GetTypeInfo())) { // The nested object is an array. This means we should apply the // wrapper's configuration to all items in the array. var nestedList = (nestedObject as IList) != null ? new AArray((nestedObject as IList).Count) : new AArray(); AugmentArray(obj, ntc, nestedObject, property, nestedList, state, BuildList(property.TypeConfiguration, wrapper.TypeConfiguration)); root[property.PropertyInfo.Name] = nestedList; done = true; } } if (done) { continue; } var nestedDict = new AObject(); var tcs = BuildList(property.TypeConfiguration, ntc?.TypeConfiguration); CopyAndAugmentObject(nestedObject, tcs, nestedDict, state, ntc, obj); root[property.PropertyInfo.Name] = nestedDict; } else { var ntc = GetNestedTypeConfiguration(typeConfiguration, property); var nestedList = new AArray(); AugmentArray(obj, ntc, nestedObject, property, nestedList, state, BuildList(property.TypeConfiguration, ntc?.TypeConfiguration)); root[property.PropertyInfo.Name] = nestedList; } } } }
private void CopyAndAugmentObject(object obj, List <TypeConfiguration> typeConfigurations, AObject root, IReadOnlyState state, NestedTypeConfiguration ntc, object parentForNested) { foreach (var typeConfiguration in typeConfigurations) { if (ntc != null) { state = CreateNestedState(parentForNested, ntc, state); } CopyObject(obj, typeConfiguration, root, state); } foreach (var typeConfiguration in typeConfigurations) { if (ntc != null) { state = CreateNestedState(parentForNested, ntc, state); } AugmentObject(obj, typeConfiguration, root, state); } }
private void ApplyCustomThunk(object obj, AObject root, IReadOnlyState state, Action <object, AObject, IReadOnlyState> customThunk) { customThunk(obj, root, state); }
private static IReadOnlyState CreateNestedState(object obj, NestedTypeConfiguration ntc, IReadOnlyState state) { if (ntc?.AddState == null) { return(state); } var addedState = new State(); ntc.AddState(obj, state, addedState); var newState = new State(state, addedState); return(new ReadOnlyState(newState)); }
private void AugmentObject(object obj, TypeConfiguration typeConfiguration, AObject root, IReadOnlyState state) { foreach (var augment in typeConfiguration.Augments) { ApplyAugment(obj, root, augment, state); } foreach (var v in typeConfiguration.CustomThunks) { ApplyCustomThunk(obj, root, state, v); } }