aceryansoft.codeflow 1.24.5.15

dotnet add package aceryansoft.codeflow --version 1.24.5.15
NuGet\Install-Package aceryansoft.codeflow -Version 1.24.5.15
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="aceryansoft.codeflow" Version="1.24.5.15" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add aceryansoft.codeflow --version 1.24.5.15
#r "nuget: aceryansoft.codeflow, 1.24.5.15"
#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.
// Install aceryansoft.codeflow as a Cake Addin
#addin nuget:?package=aceryansoft.codeflow&version=1.24.5.15

// Install aceryansoft.codeflow as a Cake Tool
#tool nuget:?package=aceryansoft.codeflow&version=1.24.5.15

aceryansoft.codeflow

.Net

aceryansoft.codeflow is a C# simple, fluent and feature driven programming framework targeting .Net standard 2.0 and .Net framework 4.5.2 . It helps design and write complex and long running processes by features.

First think about your process as an ordered collection of features, then decompose each feature into smaller and less complex sub-features , finally decompose each sub-feature into loosely-coupled activities small enough to be delivered during few days. By designing your code with this mind set and using our fluent api combined with dependency injection, you should write code easier to read, reuse and test.

Showcase

let's read this sample code written with aceryansoft.codeflow to compute some financial indicator (CVAR: Credit value at risk).

public class CvarCodeFlow
{
	private readonly Func<Type, string, object> _serviceResolver;

	public CvarCodeFlow(string computeEngine = "")
	{
		var kernel = BuildDiContainer(computeEngine);
		_serviceResolver = (typ, str) => string.IsNullOrEmpty(str) 
									   ? kernel.Get(typ) : kernel.Get(typ, str);
	}

	public void Run(string requestId="", bool rerunMode=false,string restorePoint="")
	{            
		var cvarcodeFlow = new CodeFlow();
		cvarcodeFlow.StartNew(cfg => {
			cfg.WithContext(() =>
			{
				var context = new CvarContext() { Criteria = new SearchCriteria() { Filter = "otc trades" } };
				context.RequestId = string.IsNullOrEmpty(requestId) ? context.RequestId : requestId;
				return context;
			})
			.UseMiddleware<IExceptionHandlingMiddleware>()
			.UseActivityFilter<IAppLogActivityFilter>()
			.RerunMode(rerunMode).RestorePointId(restorePoint).WithServiceResolver(_serviceResolver);
		})
		.Do<ICodeFlowActivity>("LoadTrades")
		.If((ctx,inputs)=> ctx.GetCollection<Trade>("Trades").Any(x=>x.IsOption))
			.Do<ILoadTradesVolatility>()
		.Close()
		.Do<IExportOptimalProgramsForExoticDeals>()
		.Do<IComputeMatchingBetweenTradesAndContracts>()
		.Parallel()
			.CallCodeFlow(ExportLegalEntitiesInfos)
			.Do<IExportStaticData>()
			.Do<IExportUnderlyings>()
			.Do<IExportFixings>()
		.Close()
		.RestorePoint("restore.after.export", SaveRestorePointContextState, LoadRestorePointContextState)
		.Switch((ctx, inputs) => ctx.GetValue<string>("SimulationAlgorithm"))
			.Case((val, inputs) => val?.ToString()== "MonteCarlo")
				.Call((ctx, inputs) =>
				{
					//Compute diffusion on each riskfactor, default date, scenario with MonteCarlo algorithm
				})
			.Case((val, inputs) => val?.ToString() == "LossCalculation")
				.Call((ctx, inputs) =>
				{
					//Compute diffusion on each riskfactor, default date, scenario with LossCalculation algorithm
				})
		.CloseSwitch()
		.RestorePoint("restore.after.diffusion", SaveRestorePointContextState, LoadRestorePointContextState)
		.ForEach((ctx, inputs)=> ctx.GetCollection<CtyComputeParameter>("CtyComputeParameter").OfType<object>().ToList(),packetSize:10)
			.AsParallel()
				.Function<ICodeFlowActivityFunction>("CvarComputerFunction")
					.WithArg<ConcurrentBag<SharedComputeInputs>>("shareinputs",(ctx, inputs) => ctx.As<CvarContext>().SharedInputs)
					.WithArg<string>("Currency",(ctx, inputs) => "EUR")
					.WithArg<decimal>("Threshold",(ctx, inputs) => 0.95M)
					.WithResult<CtyComputeResult>((ctx, inputs,res) => ctx.GetCollection<CtyComputeResult>("CtyResults").Add(res))
				.Close()
			.Close()
		.CloseForEach()
		.Call((ctx, inputs) =>
		{
			//Save computation results to database ... 
		})
		.Close();

		cvarcodeFlow.Execute(); 
	}

	private StandardKernel BuildDiContainer(string computeEngine = "")
	{
		var kernel = new StandardKernel();
		kernel.Bind<IExceptionHandlingMiddleware>().To<ExceptionHandlingMiddleware>();
		kernel.Bind<IAppLogActivityFilter>().To<AppLogActivityFilter>();

		kernel.Bind<IMarkToMarketService>().To<MarkToMarketService>();
		kernel.Bind<ITradeSearchService>().To<TradeSearchService>();
		kernel.Bind<ICodeFlowActivity>().To<LoadTradesActivity>().Named("LoadTrades");
		// register all activities, services and functions ... 

		kernel.Bind<ICodeFlowActivityFunction>().To<LegacyCvarComputerFunction>()
			  .When(req => computeEngine == "legacy").Named("CvarComputerFunction");

		kernel.Bind<ICodeFlowActivityFunction>().To<NewCvarComputerFunction>()
			  .When(req => computeEngine != "legacy").Named("CvarComputerFunction");

		return kernel;
	}

	private void ExportLegalEntitiesInfos(ICallFlowApi blockPath)
	{
		blockPath
			.Do<ICodeFlowActivity>("ExportLegalEntities")
			.Do<ICodeFlowActivity>("ExportCreditLimits")
			.Do<ICodeFlowActivity>("ExportContracts")
			.Do<ICodeFlowActivity>("ExportMarginCalls")
		.Close();
	}
	
	private void SaveRestorePointContextState(string reqId, string pointId, object[] inputs, ICodeFlowContext ctx)
	{ 
		//save execution context to any persistent store
	}

	private ICodeFlowContext LoadRestorePointContextState(string reqId, string pointId)
	{
		//load execution context from any persistent store
		return new CvarContext();
	}      
}

Don't you think that this code is simple and clear ?

Don't you want to join projects were legacy code is written as this showcase ?

Contributing

All contribution are welcome, please read the Code of conduct and contact the author.

Documentation

Please read wiki.

License

This project is licensed under the terms of the Apache-2.0 License. Please read LICENSE file for license rights and limitations.

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. 
.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 net452 is compatible.  net46 was computed.  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.
  • .NETFramework 4.5.2

    • No dependencies.
  • .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
1.24.5.15 63 5/15/2024
1.21.4.19 470 4/19/2021
1.21.1.18 384 1/18/2021

Initial package release