Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

sunsided/Graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graph / Dataflow

Graph is a .NET library for parallel filter-based pipeline/dataflow processing.


🧀 Please note that like any good cheese, this library too is old and smells a bit. It was written in the years 2011 and 2012 and while still functional it is by no means actively developed or maintained, nor do I intend to change that. The code was updated to target .NET 6 and use more modern C# language constructs, but that's about it. — That said, feel free to play around!

💡 For any serious use, please have a look at the System.Threading.Tasks.Dataflow package first, as it provides the Dataflow (Task Parallel Library) functionality. Unlike this library, TPL Dataflow supports async actions.


Usage example

  1. Create a data source

    ISource source = new LogicEmitter();
  2. Create a processor

    IFilter filter = new NotGate();
  3. Create a data sink

    ISink sink = new ActionInvoker<bool>(value => Trace.WriteLine("The value is: " + value));
  4. Build the processing graph

    source.AttachOutput(filter);
    filter.AttachOutput(sink);
  5. Start all sources

    source.StartProcessing();

    (Note: For the LogicEmitter to actually do something you would have to call one of its EmitXXX() methods. This is just an example though.)

  6. ???

  7. Profit

Example filters

Data processor with a single input

/// <summary>
/// Produces a logical NOT (inversion) of the input
/// </summary>
public sealed class NotGate : DataFilter<bool, bool>
{
    protected override bool ProcessData(bool input, out bool output)
    {
        output = !input;
        return true;
    }
}

Data processor with two identical inputs

/// <summary>
/// Produces a logical AND of two values
/// </summary>
public sealed class AndGate : DualInFilter<bool, bool>
{
    protected override bool ProcessData(bool input1, bool input2, out bool output)
    {
        output = input1 && input2;
        return true;
    }
}

Data converter

/// <summary>
/// Casts <see cref="System.String"/> to <see cref="System.Int32"/>
/// </summary>
public sealed class TypeCastFilter : DataFilter<string, int>
{
    protected override bool ProcessData(string input, out int output)
    {
        return Int32.TryParse(input, out output);
    }
}

About

.NET pipeline/dataflow data processing framework written in C#

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages