Nagornev.Graph 1.0.2

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Nagornev.Graph --version 1.0.2
                    
NuGet\Install-Package Nagornev.Graph -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nagornev.Graph" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nagornev.Graph" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Nagornev.Graph" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nagornev.Graph --version 1.0.2
                    
#r "nuget: Nagornev.Graph, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nagornev.Graph@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nagornev.Graph&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Nagornev.Graph&version=1.0.2
                    
Install as a Cake Tool

Nagornev.Graph

Information

This library creates a node graph to manage a complex business process. The principle of graph creation is based on the "Chain of responsibility" pattern. If you know this pattern, then you can easily work with this library.

Installation

Install the current version with dotnet:

dotnet add package Nagornev.Graph

Usage

Quick start

Use this code to write console lines:

using Nagornev.Graph.Commands;
using Nagornev.Graph.Invokers;
using Nagornev.Graph.Nodes;

AutomaticInvoker invoker = new AutomaticInvoker();

//Init
ConsistentNode startNode = new ConsistentNode(() =>
                                   FunctionalConsistentCommand.Create(async () =>
                                       {
                                           Console.WriteLine("Handling start node.");
                                       }));

ConditionNode middleNode = new ConditionNode(() =>
                                    FunctionalConditionCommand.Create(async () =>
                                        {
                                            Random random = new Random();

                                            int number = random.Next(10);

                                            bool response = number % 2 == 0;

                                            Console.WriteLine($"Handling middle node. Response {response}.");

                                            return response;
                                        }));

ConsistentNode firstEndNode = new ConsistentNode(() =>
                                    FunctionalConsistentCommand.Create(async () =>
                                        {
                                            Console.WriteLine("Handling first end node.");
                                        }));

ConsistentNode secondEndNode = new ConsistentNode(() =>
                                    FunctionalConsistentCommand.Create(async () =>
                                    {
                                        Console.WriteLine("Handling second end node.");
                                    }));
//Connecting
startNode.SetSuccessor(middleNode);

middleNode.SetSuccessor(true, firstEndNode);
middleNode.SetSuccessor(false, secondEndNode);

//Invoke
invoker.SetStart(startNode);
await invoker.Start();

How to use it?

This library has 3 main components:

  • *Node - used for connecting between nodes;
  • *Command - used to set up the next handling node;
  • *Invoker - used to invoke the node handling;
Nodes:

This library has 4 main nodes:

  • ConsistentNode - has one successor. Command type is ConsistentCommand;
  • ConditionNode - has two successors (true/false). Command type is ConditionCommand;
  • ConvertibleNode<T> - has an unknown number of successors (the number of successors depends on the type T). Command type is ConvertibleCommand<T>;
  • ExceptionNode - has one successor. Also this node can repeat parent node (the parent node is the node where catched unhandled exception). Command type is ExceptionCommand;

Each of the 3 types of main nodes (ConsistentNode, ConditionNode, ConvertibleNode<T>) has additional nodes:

  • Oneway*Node - the command is executed once. After executing the command, the node will return the successor it returned the first time;
  • Interval*Node - the command is executed after skipping the set call interval;
  • Delayed*Node - the command is executed after a period of time;

Each node has methods:

  • SetSuccessor(Node successor) / SetSuccessor(TConvertibleType key, Node successor) - sets the node successor;
  • SetExceptionSuccessor(ExceptionNode successor) - sets the exception node successor;
  • SetDelay(int delay) - sets the delay after execution;
  • SetSingle(bool single) - sets the parameter that controls the command creation;
  • SetTag(string tag) - sets the tag that used the node handling;

Exception node has specific methods:

-SetRepeat(int count) - sets the repetition count of the parent node;

Commands:

This library has 4 main commands:

  • ConsistentCommand - the execution method has the signature: Func<Task>;
  • ConditionCommand - the execution method has the signature: Func<Task<bool>>;
  • ConvertibleCommand<T> - the execution method has the signature: Func<Task<T>>, where T: struct, IConvertible;
  • ExceptionCommand - the execution method has the signature: Func<Task>;

Each main commands has additional commands:

  • Functional*Command - the constructor accept the * delegate;
  • Callback*Command<T> - the command has a special method T Call(), which invoke the acepted callback;
Invokers

This library has 2 main invokers:

  • AutomaticInvoker
  • HandInvoker

To start handling nodes, you need call method SetStart(Node node) and call method Task Start() (AutomaticInvoker) or call method Task Execute() (HandInvoker).

Sample

Let's calculate and get the factorial of the number:

public class FactorialCommand : CallbackConsistentCommand<int>
{
    private readonly int _number;

    private int _factorial;

    public FactorialCommand(int number,
                            params CommandCallbackDelegate<int>[] callbacks) 
        : base(callbacks)
    {
        _number = number;
    }

    protected override async Task Execute()
    {
        _factorial = Factorial(_number);
    }

    private int Factorial(int number)
    {
        if (number == 1) return 1;

        return number * Factorial(number - 1);
    }

    protected override int Call()
    {
        return _factorial;
    }
}

Let's create a graph and call it for handling.

using Nagornev.Graph.Commands;
using Nagornev.Graph.Invokers;
using Nagornev.Graph.Nodes;

int number = int.Parse(Console.ReadLine());

int result = 0;

AutomaticInvoker invoker = new AutomaticInvoker();

//Init
ConsistentNode calculateFactorialNode = new ConsistentNode(() =>
                                            new FactorialCommand(number,
                                                                 (factorial) => result = factorial));


ConsistentNode printFactorialNode = new ConsistentNode(() =>
                                        FunctionalConsistentCommand.Create(async () =>
                                            {
                                                Console.WriteLine($"Factorial {number} is {result}.");
                                            }));
//Connecting
calculateFactorialNode.SetSuccessor(printFactorialNode);

//Invoke
invoker.SetStart(calculateFactorialNode);
await invoker.Start();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated