Skip to content

Commit

Permalink
Preview release for GA
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Nov 6, 2023
1 parent 34c1b23 commit df2aa31
Show file tree
Hide file tree
Showing 54 changed files with 1,786 additions and 1,236 deletions.
22 changes: 15 additions & 7 deletions PipeAndFilter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{0EE631D9-C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PipeAndFilter", "Src\PipeAndFilter.csproj", "{27DC4458-EAEB-4C93-ACAF-25F25C404DBC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PipeAndFilterSamples", "Samples\PipeAndFilterSamples.csproj", "{B8DB50CE-1D00-4FDC-B99C-F943AF0A8918}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PipeAndFilterSampleConsole", "Samples\SampleConsole\PipeAndFilterSampleConsole.csproj", "{9D70D715-9911-46B0-86D2-DB08AF72DE1D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PipeAndFilterSampleApi", "Samples\SampleApi\PipeAndFilterSampleApi.csproj", "{6696533B-7288-4B59-ADBC-919D875DA5F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -32,12 +34,18 @@ Global
{27DC4458-EAEB-4C93-ACAF-25F25C404DBC}.local|Any CPU.Build.0 = local|Any CPU
{27DC4458-EAEB-4C93-ACAF-25F25C404DBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27DC4458-EAEB-4C93-ACAF-25F25C404DBC}.Release|Any CPU.Build.0 = Release|Any CPU
{B8DB50CE-1D00-4FDC-B99C-F943AF0A8918}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8DB50CE-1D00-4FDC-B99C-F943AF0A8918}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8DB50CE-1D00-4FDC-B99C-F943AF0A8918}.local|Any CPU.ActiveCfg = Debug|Any CPU
{B8DB50CE-1D00-4FDC-B99C-F943AF0A8918}.local|Any CPU.Build.0 = Debug|Any CPU
{B8DB50CE-1D00-4FDC-B99C-F943AF0A8918}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8DB50CE-1D00-4FDC-B99C-F943AF0A8918}.Release|Any CPU.Build.0 = Release|Any CPU
{9D70D715-9911-46B0-86D2-DB08AF72DE1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D70D715-9911-46B0-86D2-DB08AF72DE1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D70D715-9911-46B0-86D2-DB08AF72DE1D}.local|Any CPU.ActiveCfg = Debug|Any CPU
{9D70D715-9911-46B0-86D2-DB08AF72DE1D}.local|Any CPU.Build.0 = Debug|Any CPU
{9D70D715-9911-46B0-86D2-DB08AF72DE1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D70D715-9911-46B0-86D2-DB08AF72DE1D}.Release|Any CPU.Build.0 = Release|Any CPU
{6696533B-7288-4B59-ADBC-919D875DA5F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6696533B-7288-4B59-ADBC-919D875DA5F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6696533B-7288-4B59-ADBC-919D875DA5F3}.local|Any CPU.ActiveCfg = Debug|Any CPU
{6696533B-7288-4B59-ADBC-919D875DA5F3}.local|Any CPU.Build.0 = Debug|Any CPU
{6696533B-7288-4B59-ADBC-919D875DA5F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6696533B-7288-4B59-ADBC-919D875DA5F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
153 changes: 56 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,127 +70,86 @@ dotnet run --project [name of sample]
## Usage
[**Top**](#table-of-contents)

The controls use **fluent interface**; an object-oriented API whose design relies extensively on method chaining. Its goal is to increase code legibility. The term was coined in 2005 by Eric Evans and Martin Fowler.
```csharp
public class MyClass
{
public int MyProperty { get; set; }
}
```
The **PipeAndFilter** use **fluent interface**; an object-oriented API whose design relies extensively on method chaining. Its goal is to increase code legibility. The term was coined in 2005 by Eric Evans and Martin Fowler.

```csharp
var contract = new MyClass { MyProperty = 10 };
### Sample-Console Usage

var result = await PipeAndFilter
.Create<MyClass>()
.Init(contract)
.MaxDegreeProcess(4)
.CorrelationId(null)
.Logger(null)
```csharp
var result = await PipeAndFilter.New<MyClass>()
.AddPipe(ExecPipe1)
.AddPipe(ExecPipe2)
.WithCondition(CondFalse, "LastPipe")
.WithCondition(CondTrue, null)
.WithCondition(CondTrue, null)
.AddPipeTasks(AgregateTask)
.AddPipe(ExecPipe2)
.AddPipe(ExecPipe3)
.AddPipeTasks(AgregateTask)
.WithCondition(CondTrue, null)
.AddTask(Task50)
.AddTaskCondition(Task100, CondFalse)
.AddTask(Task150)
.AddPipe(ExecPipe, "LastPipe")
.Run();

Console.WriteLine($"Contract value : {contract.MyProperty}");
foreach (var item in pl.Status)
{
Console.WriteLine($"{item.Alias ?? item.Id}:{item.Status.Value} => {item.Status.Elapsedtime}");
foreach (var det in item.StatusDetails)
{
Console.WriteLine($"\t{det.TypeExec}:{det.GotoAlias ?? det.Alias}:{det.Condition} => :{det.Value}:{det.Elapsedtime}");
}
}
.MaxDegreeProcess(4)
.AddTask(Task1)
.AddTaskCondition(Task2, CondFalse)
.AddTask(Task3)
.AddPipe(ExecPipe5, "LastPipe")
.BuildAndCreate()
.Init(contract)
.CorrelationId(null)
.Logger(null)
.Run();
```

### Sample-api/webUsage
[**Top**](#table-of-contents)

```csharp
private static async Task Task50(EventPipe<MyClass> pipe, CancellationToken token)
{
pipe.ChangeContract((contract) =>
{
contract.MyProperty++;
});
try
{
await Task.Delay(50, token);
pipe.SaveValue(50);
}
catch (TaskCanceledException)
{
//none
}
}
private static async Task Task100(EventPipe<MyClass> pipe, CancellationToken token)
{
pipe.ChangeContract((contract) =>
{
contract.MyProperty++;
});
try
{
await Task.Delay(100, token);
pipe.SaveValue(100);
}
catch (TaskCanceledException)
{
//none
}
}
private static async Task Task150(EventPipe<MyClass> pipe, CancellationToken token)
builder.Services
.AddPipeAndFilter(
PipeAndFilter.New<WeatherForecast>()
.AddPipe(ExecPipe)
.Build());

```

```csharp
private static Task ExecPipe(EventPipe<WeatherForecast> pipe, CancellationToken token)
{
pipe.ChangeContract((contract) =>
{
contract.MyProperty++;
contract.TemperatureC += 10;
});
try
{
await Task.Delay(150, token);
pipe.SaveValue(150);
}
catch (TaskCanceledException)
{
//none
}
}
private static Task ExecPipe(EventPipe<MyClass> pipe, CancellationToken token)
{
pipe.SaveValue("Saved");
return Task.CompletedTask;
}
private static Task AgregateTask(EventPipe<MyClass> pipe, CancellationToken token)
{
return Task.CompletedTask;
}
private static async Task ExecPipe100(EventPipe<MyClass> pipe, CancellationToken token)
```

```csharp
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
pipe.SaveValue("Saved0");
try
private readonly ILogger<WeatherForecastController> _logger;
private readonly IPipeAndFilterServiceBuild<WeatherForecast> _mypipe;

public WeatherForecastController(ILogger<WeatherForecastController> logger, IPipeAndFilterServiceBuild<WeatherForecast> pipeAndFilter)
{
await Task.Delay(100, token);
_logger = logger;
_mypipes = pipeAndFilter;
}
catch (TaskCanceledException)

[HttpGet(Name = "GetWeatherForecast")]
public async Task<WeatherForecast> Get(CancellationToken cancellation)
{
//none
var cid = Guid.NewGuid().ToString();

var pipe = await _mypipes.First(x => x.ServiceId == "opc1")
.Create()
.Logger(_logger)
.CorrelationId(cid)
.Init(new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now), Summary = "PipeAndFilter-Opc1", TemperatureC = 0 })
.Run(cancellation);
return pipe.Result.Value!
}
}
private static async ValueTask<bool> CondFalse(EventPipe<MyClass> pipe, CancellationToken token)
{
return await Task.FromResult(false);
}
private static ValueTask<bool> CondTrue(EventPipe<MyClass> pipe, CancellationToken token)
{
ValueTask.FromResult(true);
}
```


## Code of Conduct
[**Top**](#table-of-contents)

Expand Down
42 changes: 42 additions & 0 deletions Samples/SampleApi/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Mvc;
using PipeFilterCore;

namespace WebApplication1.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{

private readonly ILogger<WeatherForecastController> _logger;
private readonly IEnumerable<IPipeAndFilterServiceBuild<WeatherForecast>> _mypipes;

public WeatherForecastController(ILogger<WeatherForecastController> logger, IEnumerable<IPipeAndFilterServiceBuild<WeatherForecast>> pipeAndFilter)
{
_logger = logger;
_mypipes = pipeAndFilter;
}

[HttpGet(Name = "GetWeatherForecast")]
public async Task<IEnumerable<WeatherForecast>> Get(CancellationToken cancellation)
{
var cid = Guid.NewGuid().ToString();

var pipe1 = await _mypipes.First(x => x.ServiceId == "opc1")
.Create()
.Logger(_logger)
.CorrelationId(cid)
.Init(new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now), Summary = "PipeAndFilter-Opc1", TemperatureC = 0 })
.Run();

var pipe2 = await _mypipes.First(x => x.ServiceId == "opc2")
.Create()
.Logger(_logger)
.CorrelationId(cid)
.Init(new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now), Summary = "PipeAndFilter-Opc2", TemperatureC = 100 })
.Run(cancellation);

return new WeatherForecast[] { pipe1.Value!, pipe2.Value! };
}
}
}
18 changes: 18 additions & 0 deletions Samples/SampleApi/PipeAndFilterSampleApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.13" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\PipeAndFilter.csproj" />
</ItemGroup>

</Project>
59 changes: 59 additions & 0 deletions Samples/SampleApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

using System;
using PipeFilterCore;

namespace WebApplication1
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddPipeAndFilter(
PipeAndFilter.New<WeatherForecast>()
.AddPipe(ExecPipe)
.Build("opc1"));

builder.Services.AddPipeAndFilter(
PipeAndFilter.New<WeatherForecast>()
.AddPipe(ExecPipe)
.AddPipe(ExecPipe)
.Build("opc2"));

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();


app.MapControllers();

app.Run();
}

private static Task ExecPipe(EventPipe<WeatherForecast> pipe, CancellationToken token)
{
pipe.ChangeContract((contract) =>
{
contract.TemperatureC += 10;
});
return Task.CompletedTask;
}
}
}
41 changes: 41 additions & 0 deletions Samples/SampleApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49906",
"sslPort": 44341
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5223",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7072;http://localhost:5223",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading

0 comments on commit df2aa31

Please sign in to comment.