Skip to content

Commit

Permalink
Simplified source generation using attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Oct 6, 2024
1 parent 952e0b1 commit e118cf2
Show file tree
Hide file tree
Showing 59 changed files with 130 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cleipnir.Flows.Tests.AspNet/TestFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleipnir.Flows.Tests.AspNet;

[GenerateFlows]
public class TestFlow : Flow<string, string>
{
public override Task<string> Run(string param)
Expand Down
3 changes: 3 additions & 0 deletions Cleipnir.Flows.Tests/Flows/FlowsWithStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public async Task FuncFlowWithStateCanBeFetchedAfterExecution()
}
}

[GenerateFlows]
public class ActionWithStateFlow : Flow<string>, IExposeState<ActionWithStateFlow.WorkflowState>
{
public required WorkflowState State { get; init; }
Expand All @@ -109,6 +110,7 @@ public class WorkflowState : FlowState
}
}

[GenerateFlows]
public class FuncWithStateFlow : Flow<string, string>, IExposeState<FuncWithStateFlow.WorkflowState>
{
public required WorkflowState State { get; init; }
Expand All @@ -125,6 +127,7 @@ public class WorkflowState : FlowState
}
}

[GenerateFlows]
public class ParamlessWithStateFlow : Flow, IExposeState<ParamlessWithStateFlow.WorkflowState>
{
public required WorkflowState State { get; init; }
Expand Down
3 changes: 3 additions & 0 deletions Cleipnir.Flows.Tests/Flows/OptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public async Task FlowNameCanBeSpecifiedFromTheOutside()
}
}

[GenerateFlows]
public class OptionsTestWithOverriddenOptionsFlow : Flow
{
public override async Task Run()
Expand All @@ -85,6 +86,7 @@ public override async Task Run()
}
}

[GenerateFlows]
public class OptionsTestWithDefaultProvidedOptionsFlow : Flow
{
public override async Task Run()
Expand All @@ -93,6 +95,7 @@ public override async Task Run()
}
}

[GenerateFlows]
public class SimpleFlow : Flow
{
public override Task Run() => Task.CompletedTask;
Expand Down
4 changes: 4 additions & 0 deletions Cleipnir.Flows/GenerateFlowsAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Cleipnir.Flows;

[System.AttributeUsage(System.AttributeTargets.Class)]
public class GenerateFlowsAttribute : System.Attribute;
1 change: 1 addition & 0 deletions Samples/Cleipnir.Flows.Sample.AspNet/Flows/OrderFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Flows;

[GenerateFlows]
public class OrderFlow : Flow<Order>
{
private readonly IPaymentProviderClient _paymentProviderClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven.Other;
using Cleipnir.ResilientFunctions.Helpers;
using Cleipnir.ResilientFunctions.Reactive.Extensions;

namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven;

[GenerateFlows]
public class MessageDrivenOrderFlow(Bus bus) : Flow<Order>
{
public override async Task Run(Order order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven.Solution;

[GenerateFlows]
public class MessageDrivenOrderFlow(Bus bus) : Flow<Order>
{
public override async Task Run(Order order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.Rpc;

[GenerateFlows]
public class OrderFlow(
IPaymentProviderClient paymentProviderClient,
IEmailClient emailClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.Rpc.Solution;

[GenerateFlows]
public class OrderFlow(
IPaymentProviderClient paymentProviderClient,
IEmailClient emailClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cleipnir.Flows.Sample.Presentation.A_OrderFlowRpc;

[GenerateFlows]
public class OrderFlow : Flow<Order>
{
private readonly IPaymentProviderClient _paymentProviderClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cleipnir.Flows.Sample.Presentation.A_OrderFlowRpc.Solution;

[GenerateFlows]
public class OrderFlow : Flow<Order>
{
private readonly IPaymentProviderClient _paymentProviderClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleipnir.Flows.Sample.Presentation.B_OrderFlow_Messaging;

[GenerateFlows]
public class OrderFlow : Flow<Order>
{
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Cleipnir.Flows.Sample.Presentation.B_OrderFlow_Messaging.Solution;

[GenerateFlows]
public class OrderFlow(MessageBroker messageBroker) : Flow<Order>
{
private ILogger Logger { get; } = Log.Logger.ForContext<OrderFlow>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Cleipnir.Flows.Sample.Presentation.C_NewsletterSender.Distributed;

[GenerateFlows]
public class NewsletterChildFlow(NewsletterParentFlows parentFlows, int child) : Flow<NewsletterChildWork>
{
public override async Task Run(NewsletterChildWork work)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Presentation.C_NewsletterSender.Distributed;

[GenerateFlows]
public class NewsletterParentFlow(NewsletterChildFlows childFlows) : Flow<MailAndRecipients>
{
public override async Task Run(MailAndRecipients param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Presentation.C_NewsletterSender;

[GenerateFlows]
public class NewsletterFlow : Flow<MailAndRecipients>
{
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Cleipnir.Flows.Sample.Presentation.C_NewsletterSender.Solution;

[GenerateFlows]
public class NewsletterFlow : Flow<MailAndRecipients>, IExposeState<NewsletterFlow.NewsletterState>
{
public required NewsletterState State { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleipnir.Flows.Sample.Presentation.D_LoanApplication;

[GenerateFlows]
public class LoanApplicationFlow : Flow<LoanApplication>
{
public override async Task Run(LoanApplication loanApplication)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleipnir.Flows.Sample.Presentation.D_LoanApplication.Solution;

[GenerateFlows]
public class LoanApplicationFlow : Flow<LoanApplication>
{
public override async Task Run(LoanApplication loanApplication)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cleipnir.Flows.Sample.Presentation.E_CustomerSignup;

[GenerateFlows]
public class SignupFlow : Flow<string>
{
public override async Task Run(string customerEmail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleipnir.Flows.Sample.Presentation.E_CustomerSignup.Solution;

[GenerateFlows]
public class SignupFlow : Flow<string>
{
public override async Task Run(string customerEmail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cleipnir.Flows.Sample.Presentation.F_SmsVerificationFlow;

[GenerateFlows]
public class SmsFlow : Flow<string>, IExposeState<SmsFlow.SmsState>
{
public required SmsState State { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleipnir.Flows.Sample.Presentation.G_SupportTicket.Solution;

[GenerateFlows]
public class SupportTicketFlow : Flow<SupportTicketRequest>
{
public override async Task Run(SupportTicketRequest request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cleipnir.Flows.Sample.Presentation.G_SupportTicket;

[GenerateFlows]
public class SupportTicketFlow : Flow<SupportTicketRequest>
{
public override async Task Run(SupportTicketRequest request)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Cleipnir.ResilientFunctions.PostgreSQL;

namespace Cleipnir.Flows.Sample.Presentation.H_BankTransfer;

public static class Example
{
public static async Task Perform()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<TransferFlow>();

var connStr = "Server=localhost;Database=presentation;User Id=postgres;Password=Pa55word!; Include Error Detail=true;";
await DatabaseHelper.CreateDatabaseIfNotExists(connStr);
var store = new PostgreSqlFunctionStore(connStr);
await store.Initialize();

var flowsContainer = new FlowsContainer(
store,
serviceCollection.BuildServiceProvider(),
Options.Default
);

var transferFlows = new TransferFlows(flowsContainer);
var transactionId = Guid.NewGuid();
await transferFlows.Run(
transactionId.ToString(), new Transfer(transactionId, "FROM_ACC123", "TO_ACC456", Amount: 100)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Cleipnir.ResilientFunctions.PostgreSQL;

namespace Cleipnir.Flows.Sample.Presentation.H_BankTransfer.Solution;

public static class Example
{
public static async Task Perform()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<TransferFlow>();

var connStr = "Server=localhost;Database=presentation;User Id=postgres;Password=Pa55word!; Include Error Detail=true;";
await DatabaseHelper.CreateDatabaseIfNotExists(connStr);
var store = new PostgreSqlFunctionStore(connStr);
await store.Initialize();

var flowsContainer = new FlowsContainer(
store,
serviceCollection.BuildServiceProvider(),
Options.Default
);

var transferFlows = new TransferFlows(flowsContainer);
var transactionId = Guid.NewGuid();
await transferFlows.Run(
transactionId.ToString(), new Transfer(transactionId, "FROM_ACC123", "TO_ACC456", Amount: 100)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cleipnir.Flows.Sample.Presentation.H_BankTransfer.Solution;

[GenerateFlows]
public sealed class TransferFlow : Flow<Transfer>
{
public TransferFlow(IBankCentralClient bankCentralClient) => BankCentralClient = bankCentralClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cleipnir.Flows.Sample.Presentation.H_BankTransfer;

[GenerateFlows]
public sealed class TransferFlow : Flow<Transfer>
{
public TransferFlow(IBankCentralClient bankCentralClient) => BankCentralClient = bankCentralClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cleipnir.Flows.Sample.Presentation.OutBoxPattern;

[GenerateFlows]
public class OutboxFlow(IBus bus) : Flow<Order>
{
public override async Task Run(Order order)
Expand Down
3 changes: 2 additions & 1 deletion Samples/Cleipnir.Flows.Sample.Presentation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ private static async Task Main(string[] args)
.Enrich.FromLogContext()
.CreateLogger();

await C_NewsletterSender.Distributed.Example.Perform();
//await C_NewsletterSender.Distributed.Example.Perform();
await H_BankTransfer.Example.Perform();

Console.ReadLine();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cleipnir.Flows.Sample.Presentation.Solutions.A_OrderFlowRpc;

[GenerateFlows]
public class OrderFlow0 : Flow<Order>
{
private readonly IPaymentProviderClient _paymentProviderClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Cleipnir.Flows.Sample.Presentation.Solutions.A_OrderFlowRpc;

[GenerateFlows]
public class OrderFlow1 : Flow<Order>
{
private readonly IPaymentProviderClient _paymentProviderClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Cleipnir.ResilientFunctions.Domain;
using Serilog;
using ILogger = Serilog.ILogger;

namespace Cleipnir.Flows.Sample.Presentation.Solutions.A_OrderFlowRpc;

[GenerateFlows]
public class OrderFlow2 : Flow<Order>
{
private readonly IPaymentProviderClient _paymentProviderClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Presentation.Solutions.B_OrderFlowMessaging;

[GenerateFlows]
public class OrderFlow(Bus bus) : Flow<Order>
{
public override async Task Run(Order order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Presentation.Solutions.C_NewsletterSender;

[GenerateFlows]
public class NewsletterFlow0 : Flow<MailAndRecipients>
{
public override async Task Run(MailAndRecipients mailAndRecipients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Presentation.Solutions.C_NewsletterSender;

[GenerateFlows]
public class NewsletterFlow1 : Flow<MailAndRecipients>
{
public override async Task Run(MailAndRecipients mailAndRecipients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Presentation.Solutions.C_NewsletterSender;

[GenerateFlows]
public class NewsletterFlow_Parallelized : Flow<MailAndRecipients>
{
public override async Task Run(MailAndRecipients mailAndRecipients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Cleipnir.Flows.Sample.Presentation.Solutions.C_NewsletterSender;

[GenerateFlows]
public class NewsletterFlow_SpaceOptimized : Flow<MailAndRecipients>
{
public override async Task Run(MailAndRecipients mailAndRecipients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cleipnir.Flows.Sample.Presentation.Solutions.D_LoanApplication;

[GenerateFlows]
public class LoanApplicationFlow0 : Flow<LoanApplication>
{
public override async Task Run(LoanApplication loanApplication)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Cleipnir.Flows.Sample.Presentation.Solutions.D_LoanApplication;

[GenerateFlows]
public class LoanApplicationFlow1 : Flow<LoanApplication>
{
public override async Task Run(LoanApplication loanApplication)
Expand Down
Loading

0 comments on commit e118cf2

Please sign in to comment.