public virtual void Update(Event eventInstance, HandlerInvokeGraph invokeGraph) { this.handlerVersion = this.Handler.Version; this.handlerExecutors.Clear(); ArgumentNode argumentNode = invokeGraph.ArgumentNodes[0]; List <EntityNode> entityNodes = argumentNode.entityNodes; HandlerArgument argument = argumentNode.argument; bool flag = false; for (int i = 0; i < entityNodes.Count; i++) { if (this.CollectExecutors(invokeGraph, entityNodes[i], 0)) { if (!argument.Combine && flag) { throw new IllegalCombineException(this.Handler, argumentNode); } flag = true; } } if (!flag) { throw new InvalidInvokeGraphException(this.Handler); } for (int j = 0; j < this.handlerExecutors.Count; j++) { this.handlerExecutors[j].SetEvent(eventInstance); } }
private void FindMostSuitableEntities(HandlerArgument handlerArgument, ICollection <Entity> entities) { int count = 0x7fffffff; foreach (Entity entity in entities) { ICollection <Type> missingComponents = GetMissingComponents(entity, handlerArgument.NodeDescription); if ((missingComponents.Count != 0) && (missingComponents.Count < count)) { count = missingComponents.Count; continue; } if (missingComponents.Count == 0) { count = 0; break; } } if (count > 0) { foreach (Entity entity2 in entities) { ICollection <Type> missingComponents = GetMissingComponents(entity2, handlerArgument.NodeDescription); if (missingComponents.Count == count) { this.missingComponentsByEntity.Add(entity2, missingComponents); } } } }
private bool CollectExecutors(HandlerInvokeGraph invokeGraph, EntityNode entityNode, int argumentIndex) { HandlerArgument argument = this.HandlerArguments[argumentIndex]; if (argumentIndex == (this.HandlerArguments.Count - 1)) { HandlerExecutor item = this.CreateExecutor(); item.ArgumentForMethod[argumentIndex + 1] = entityNode.invokeArgument; this.handlerExecutors.Add(item); return(true); } ArgumentNode argumentNode = invokeGraph.ArgumentNodes[argumentIndex + 1]; List <EntityNode> source = (argument.Collection || argumentNode.linkBreak) ? argumentNode.entityNodes : entityNode.nextArgumentEntityNodes; int count = this.handlerExecutors.Count; bool flag = false; for (int i = 0; i < source.Count <EntityNode>(); i++) { if (this.CollectExecutors(invokeGraph, source[i], argumentIndex + 1)) { if (flag && !argumentNode.argument.Combine) { throw new IllegalCombineException(this.Handler, argumentNode); } flag = true; } } for (int j = count; j < this.handlerExecutors.Count; j++) { this.handlerExecutors[j].ArgumentForMethod[argumentIndex + 1] = entityNode.invokeArgument; } return(flag); }
private bool FillEntityNodes(ICollection <Entity> contextEntities, ArgumentNode fromArgumentNode, ArgumentNode toArgumentNode) { HandlerArgument argument = toArgumentNode.argument; if (!toArgumentNode.filled) { Optional <JoinType> joinType = argument.JoinType; if (argument.Context && argument.SelectAll) { if (contextEntities != null) { this.FillEntityNodes(toArgumentNode, contextEntities); } else { this.FillEntityNodesBySelectAll(toArgumentNode); } } else if (joinType.IsPresent()) { if (joinType.Get() is JoinAllType) { this.FillEntityNodesBySelectAll(toArgumentNode); } else { this.FillArgumentNodesByJoin(joinType.Get(), contextEntities, fromArgumentNode, toArgumentNode); } } } return((argument.Collection || argument.Optional) || (toArgumentNode.entityNodes.Count > 0)); }
public HandlerArgumentLogPart(HandlerArgument handlerArgument, ICollection <Entity> entities) { this.handlerArgument = handlerArgument; this.entities = entities; if (!handlerArgument.Collection) { this.FindMostSuitableEntities(handlerArgument, entities); } }
private static string CreateMessage(Handler handler, HandlerArgument argument, Entity entity) { object[] objArray1 = new object[] { "\nMethod: ", handler.GetHandlerName(), "\nNodeClass: ", argument.ClassInstanceDescription.NodeClass.Name, " Node: ", argument.NodeDescription }; string str = string.Concat(objArray1); if (entity != null) { str = str + "\nEntity: " + (entity as EntityInternal).ToStringWithComponentsClasses(); } return(str); }
private void CheckFirstNotJoin(IList <HandlerArgument> arguments) { if (arguments.Count > 0) { HandlerArgument handlerArgument = arguments[0]; if (handlerArgument.JoinType.IsPresent() && handlerArgument.JoinType.Get().ContextComponent.IsPresent()) { throw new JoinFirstNodeArgumentException(this.method, handlerArgument); } } }
protected bool FillEntityNodes(ArgumentNode fromArgumentNode, ArgumentNode toArgumentNode, Entity contextEntity, ICollection <NodeDescription> changedNodes) { Optional <JoinType> optional; bool flag = toArgumentNode.argument.Context && changedNodes.Contains(toArgumentNode.argument.NodeDescription); if (((fromArgumentNode != null) && fromArgumentNode.filled) && ((optional = fromArgumentNode.argument.JoinType).IsPresent() && !(optional.Get() is JoinAllType))) { this.FillArgumentNodesByJoin(optional.Get(), fromArgumentNode, toArgumentNode, !flag ? null : contextEntity); HandlerArgument argument = toArgumentNode.argument; return(argument.Collection || (argument.Optional || (toArgumentNode.entityNodes.Count > 0))); } if (flag) { this.FillEntityNodes(toArgumentNode, contextEntity); } return(true); }
public CheckGroupComponentLogPart(HandlerArgument handlerArgument, ICollection <Entity> entities) { Optional <Type> contextComponent = handlerArgument.JoinType.Get().ContextComponent; if (contextComponent.IsPresent()) { this.groupComponent = contextComponent.Get(); this.entitiesWithMissingGroupComponentByEntity = new List <Entity>(); foreach (Entity entity in entities) { if (entity.HasComponent(this.groupComponent)) { break; } this.entitiesWithMissingGroupComponentByEntity.Add(entity); } } }
private ICollection <Entity> PrintReasonForHandlerArgument(HandlerArgument handlerArgument, ICollection <Entity> leftEntities, ICollection <LogPart> parts) { if (handlerArgument.Context) { parts.Add(new HandlerArgumentLogPart(handlerArgument, this.contextEntities)); if (handlerArgument.JoinType.IsPresent()) { parts.Add(new CheckGroupComponentLogPart(handlerArgument, this.contextEntities)); } } else if (handlerArgument.JoinType.IsPresent()) { if (handlerArgument.JoinType.Get() is JoinAllType) { ICollection <Entity> entities = Flow.Current.NodeCollector.GetEntities(handlerArgument.NodeDescription); parts.Add(new JoinAllLogPart(handlerArgument, entities)); return(entities); } if (handlerArgument.JoinType.Get().ContextComponent.IsPresent()) {
private List <HandlerArgument> ParseHandlerArguments(bool isNodeChangeHandler) { ParameterInfo[] parameters = this.method.GetParameters(); HandlerArgument[] arguments = new HandlerArgument[parameters.Length - 1]; int position = 0; Optional <JoinType> rightJoin = Optional <JoinType> .empty(); for (int i = parameters.Length - 1; i > 0; i--) { position = i - 1; ParameterInfo parameterInfo = parameters[i]; object[] customAttributes = parameterInfo.GetCustomAttributes(true); Optional <JoinType> joinType = GetJoinType(customAttributes); HandlerArgument argument = CreateNodeType(position, parameterInfo.ParameterType, joinType, rightJoin, customAttributes, isNodeChangeHandler); rightJoin = joinType; if (argument == null) { throw new ArgumentMustBeNodeException(this.method, parameterInfo); } arguments[position] = argument; } this.CheckArguments(arguments); return(arguments.ToList <HandlerArgument>()); }
public JoinFirstNodeArgumentException(MethodInfo method, HandlerArgument handlerArgument) : base($"Join-node can''t be first node-argument of method [method={method}, handlerArgument={handlerArgument}]") { }
private bool FilterByContext(HandlerArgument argument, Entity entity, ICollection <Entity> contextEntities) => (argument.Context && (contextEntities != null)) && !contextEntities.Contains(entity);
public HandlerCallContextChangedException(Handler handler, HandlerArgument argument, Entity entity) : base(CreateMessage(handler, argument, entity)) { }
public ArgumentNode(HandlerArgument argument) { this.argument = argument; this.entityNodes = new List <EntityNode>(); }
public JoinAllLogPart(HandlerArgument handlerArgument, ICollection <Entity> resolvedEntities) { this.resolvedEntities = resolvedEntities; this.handlerArgument = handlerArgument; }
public JoinToCollectionException(MethodInfo method, HandlerArgument handlerArgument) : base($"Join-node can''t be joined by collection [method={method}, handlerArgument={handlerArgument}]") { }
public MandatoryException(ICollection <Entity> contexEntities, Handler handler, HandlerArgument handlerArgument) : base(new SkipLog(contexEntities, handler).ToString()) { }