IValueSource <T> CreateSourceNode <T>(ISourceDefinition <T> source, Action <Exception> onError) { switch (source.NodeType) { case NodeType.Formula: var getValue = source.CreateGetValueDelegateWithCurrentValue(); return(new ReadOnlyNodeInfo <T>(getValue, source.FullPath, source.PathFromParent, nodeRepository, false, onError, new VisualisationInfo(NodeType.Formula, false))); case NodeType.Member: var memberDefinition = (MemberDefinition <T>)source; var getValueDelegate = memberDefinition.CreateGetValueDelegate(); var shouldTrackChanges = !source.SourceType.IsValueType; var visualisationInfo = new VisualisationInfo(NodeType.Member, IsRoot(memberDefinition)); if (memberDefinition.IsWritable) { return(new ReadWriteNode <T>(getValueDelegate, memberDefinition.CreateSetValueDelegate(), source.FullPath, memberDefinition.PathFromParent, visualisationInfo, nodeRepository, shouldTrackChanges, onError)); } return(new ReadOnlyNodeInfo <T>(_ => getValueDelegate(), memberDefinition.FullPath, memberDefinition.PathFromParent, nodeRepository, shouldTrackChanges, onError, visualisationInfo)); default: throw new ArgumentOutOfRangeException(); } }
public WhenFormulaChangesBuilder(Expression <Func <T, T> > sourceFunction, string nodeId, DependencyEngine dependencyEngine) { this.dependencyEngine = dependencyEngine; if (sourceFunction.IsWritable()) { sourceDefinition = CreateMemberDefinition(sourceFunction, nodeId, true, true); } else { sourceDefinition = CreateFormulaDefinition(sourceFunction, nodeId, true); } }
protected override Expression VisitConstant(ConstantExpression node) { if (current != null) { // Create node for 'this' currentTopLevelDefinition.SourcePaths.Add(MemberToSourcePath(node)); subExpressions.Add(current); current = null; currentTopLevelDefinition = null; } return(base.VisitConstant(node)); }
protected override Expression VisitMember(MemberExpression node) { var sourcePath = MemberToSourcePath(node); if (currentTopLevelDefinition == null) { currentTopLevelDefinition = sourcePath; current = sourcePath; } else { currentTopLevelDefinition.SourcePaths.Add(sourcePath); currentTopLevelDefinition = sourcePath; } return(base.VisitMember(node)); }
IValueSource <T> GetSourceNode <T>(ISourceDefinition <T> source, Action <Exception> onError) { IValueSource <T> sourceNode; if (definitionToNodeLookup.ContainsKey(source)) { sourceNode = (IValueSource <T>)definitionToNodeLookup[source]; sourceNode.TrackChanges(); } else { sourceNode = CreateSourceNode(source, onError); definitionToNodeLookup.Add(source, sourceNode); } return(sourceNode); }
void AddSourcePathExpressions(ISourceDefinition sourceDefinition, IValueSource sourceNode, Action <Exception> onError) { foreach (var sourcePath in sourceDefinition.SourcePaths) { IValueSource pathNode; if (definitionToNodeLookup.ContainsKey(sourcePath)) { pathNode = (IValueSource)definitionToNodeLookup[sourcePath]; } else { pathNode = CreateSourceNode(sourcePath, onError); definitionToNodeLookup.Add(sourcePath, pathNode); } graph.AddEdge(pathNode, sourceNode, sourcePath.NodeName, sourceDefinition.NodeName); AddSourcePathExpressions(sourcePath, pathNode, onError); } }
public void Add <T>(ISourceDefinition <T> source, ITargetDefinition <T> target, Action <Exception> onError) { var sourceNode = GetSourceNode(source, onError); var targetNode = GetTargetNode(target, onError); sourceNode.VisualisationInfo.IsDirectlyReferenced = true; targetNode.VisualisationInfo.IsDirectlyReferenced = true; targetNode.SetSource(sourceNode); var valueSource = (targetNode) as IValueSource <T>; if (valueSource != null) { var initialValue = valueSource.GetValue(); sourceNode.SetTarget(targetNode, initialValue); } graph.AddEdge(sourceNode, targetNode, source.NodeName, target.NodeName); AddSourcePathExpressions(source, sourceNode, onError); var targetAsSource = target as ISourceDefinition <T>; if (targetAsSource != null) { AddSourcePathExpressions(targetAsSource, (IValueSource)targetNode, onError); } // Formulas should treat all arguments are directly referenced if (source.NodeType == NodeType.Formula) { var successorsOf = graph.PredecessorsOf(sourceNode); foreach (var edge in successorsOf) { edge.Source.Data.VisualisationInfo.IsDirectlyReferenced = true; } } }
public void AddExpression <T>(ISourceDefinition <T> source, ITargetDefinition <T> target, Action <Exception> onError) { expressionAdder.Add(source, target, onError); }
internal PredefinedEventsCollector Add(ISourceDefinition definition) { SourceDefinitions.Add(definition); return(this); }
IValueSource CreateSourceNode(ISourceDefinition source, Action <Exception> onError) { var method = createSourceInfo.MakeGenericMethod(source.SourceType); return((IValueSource)method.Invoke(this, new object[] { source, onError })); }
internal SourceDefinitionLookup(ISourceDefinition definition, bool isCreatingForLookup) : this(definition.EventSource, definition.EventId.GetValueOrDefault(NULL_EVENTID), isCreatingForLookup) { }