public void ConnectNodeByJoin(TaskNode start, TaskNode end, int outNr) { if (end.StreamIn == null) { throw new InvalidOperationException("Use ConnectNodeByJoin only after connecting the main connection"); } start.ConnectOutStream((IWritableQueue)end.StreamIn, outNr, end.InType); }
/// <summary> /// Add a node to the flow. Nodes may only be included once per flow /// </summary> /// <param name="newNode"></param> public void AddNode(TaskNode newNode, Position position) { _nodes.Add(newNode); if (String.IsNullOrEmpty(newNode.Name)) { newNode.Name = "node " + _nodes.Count.ToString(); } newNode.OwningFlow = this; newNode.Position = position; }
public QueueEntryIntercept(TaskNode sender, IWritableQueue queue) { _innerQueue = queue; _innerTask = sender; lock (_writersByQueue) { if (!_writersByQueue.ContainsKey(queue)) { _writersByQueue[queue] = new List <TaskNode>(); } _writersByQueue[queue].Add(sender); } }
/// <summary> /// /// </summary> /// <param name="publisher"></param> /// <param name="reader"></param> /// <param name="streamNumber"></param> public BoundedBlockingQueue ConnectNodes(TaskNode publisher, TaskNode reader, int streamNumber, int queueSize) { if (!reader.InType.IsAssignableFrom(publisher.OutTypes[streamNumber])) { throw new InvalidOperationException(String.Format("The in-stream of the reader ({1}) cannot be assigned from the publisher of type ({0})", publisher.OutTypes[streamNumber].Name, reader.InType.Name)); } Type bbOfT = typeof(BoundedBlockingQueue <>).MakeGenericType(new Type[] { reader.InType }); BoundedBlockingQueue stream = (BoundedBlockingQueue)Activator.CreateInstance(bbOfT, queueSize); publisher.ConnectOutStream(stream, streamNumber, reader.InType); reader.ConnectInStream(stream); if (String.IsNullOrEmpty(stream.Name)) { stream.Name = String.Format("from '{0}' to '{1}'", publisher.Name, reader.Name); } _streams.Add(stream); stream.OwningFlow = this; return(stream); }
/// <summary> /// Returns a task that passes on everything it receives, but only once. If the same value is /// passed twice, only the first one is passed on. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static TaskNode <T, T> GetUniqueFilter <T>() { Dictionary <T, bool> alreadySeen = new Dictionary <T, bool>(); TaskNode <T, T> result = new TaskNode <T, T>( (T input, IWritableQueue <T> output) => { lock (alreadySeen) { if (!alreadySeen.ContainsKey(input)) { alreadySeen.Add(input, true); output.Send(input); } } } ); return(result); }
internal void OnError(TaskNode node, Exception exc, object item, ref bool stopProcessing) { if (Error != null) { ErrorEventArgs args = new ErrorEventArgs() { Error = exc, ProcessedItem = item, StopProcessing = stopProcessing, Node = node }; Error(this, args); stopProcessing = args.StopProcessing; } else { stopProcessing = true; } if (stopProcessing) { _stoppingException = exc; } }
public static TaskNode <T, T> GetSortingFilter <T>() { List <T> collect = new List <T>(); TaskNode <T, T> result = new TaskNode <T, T>( (T input, IWritableQueue <T> output) => { collect.Add(input); } ); result.AfterComplete += (IList <IWritableQueue> outputs) => { collect.Sort(); foreach (var item in collect) { outputs[0].SendInner(item); } }; return(result); }
public BoundedBlockingQueue ConnectNodes(TaskNode publisher, TaskNode reader, int streamNumber) { return(ConnectNodes(publisher, reader, streamNumber, DefaultStreamSize)); }
public void AddNode(TaskNode newNode) { AddNode(newNode, Position.Origin); }
public QueueEntryOrderKeeper(TaskNode owner, IWritableQueue queue) { _innerQueue = queue; _innerTask = owner; }