Skip to content

Commit 177dc35

Browse files
committed
Add ExecutionMode support and refactor database initialization
- Introduced ExecutionMode entity and updated related configurations. - Added FlowRunRepository for managing flow runs. - Updated database context to include ExecutionModes DbSet. - Refactored database initialization logic to seed ExecutionModes. - Updated application to use SQLite as the default database provider. - Enhanced error handling and logging in various components.
1 parent 756a9c6 commit 177dc35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1447
-7298
lines changed

.idea/.idea.DidactEngine/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.DidactEngine/.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.DidactEngine/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.DidactEngine/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using DidactCore.Entities;
2+
using DidactEngine.Services.Contexts;
3+
using DidactEngine.Services.Database;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.EntityFrameworkCore;
6+
7+
namespace DidactEngine.Controllers
8+
{
9+
[ApiController]
10+
[Route("api/[controller]")]
11+
public class DatabaseController : ControllerBase
12+
{
13+
private readonly DidactDbContext _dbContext;
14+
private readonly DatabaseInitializer _databaseInitializer;
15+
private readonly ILogger<DatabaseController> _logger;
16+
17+
public DatabaseController(
18+
DidactDbContext dbContext,
19+
DatabaseInitializer databaseInitializer,
20+
ILogger<DatabaseController> logger)
21+
{
22+
_dbContext = dbContext;
23+
_databaseInitializer = databaseInitializer;
24+
_logger = logger;
25+
}
26+
27+
[HttpGet("status")]
28+
public async Task<IActionResult> GetDatabaseStatus()
29+
{
30+
try
31+
{
32+
var isSqlite = _dbContext.Database.ProviderName?.Contains("Sqlite") ?? false;
33+
var databaseExists = await _dbContext.Database.CanConnectAsync();
34+
35+
var status = new
36+
{
37+
Provider = _dbContext.Database.ProviderName,
38+
IsSqlite = isSqlite,
39+
ConnectionString = isSqlite
40+
? _dbContext.Database.GetConnectionString()
41+
: "[REDACTED]", // Don't expose SQL Server connection strings
42+
DatabaseExists = databaseExists,
43+
FlowCount = await _dbContext.Flows.CountAsync(),
44+
FlowRunCount = await _dbContext.FlowRuns.CountAsync(),
45+
OrganizationCount = await _dbContext.Organizations.CountAsync()
46+
};
47+
48+
return Ok(status);
49+
}
50+
catch (Exception ex)
51+
{
52+
_logger.LogError(ex, "Error getting database status");
53+
return StatusCode(500, new { Error = ex.Message });
54+
}
55+
}
56+
57+
[HttpPost("initialize")]
58+
public async Task<IActionResult> InitializeDatabase()
59+
{
60+
try
61+
{
62+
await _databaseInitializer.InitializeAsync();
63+
return Ok(new { Message = "Database initialized successfully" });
64+
}
65+
catch (Exception ex)
66+
{
67+
_logger.LogError(ex, "Error initializing database");
68+
return StatusCode(500, new { Error = ex.Message });
69+
}
70+
}
71+
72+
[HttpPost("seed-test-data")]
73+
public async Task<IActionResult> SeedTestData()
74+
{
75+
try
76+
{
77+
// Create a test organization if needed
78+
if (!await _dbContext.Organizations.AnyAsync(o => o.Name == "Test Organization"))
79+
{
80+
_dbContext.Organizations.Add(new Organization
81+
{
82+
Name = "Test Organization",
83+
Active = true,
84+
Created = DateTime.UtcNow,
85+
CreatedBy = "Test User",
86+
LastUpdated = DateTime.UtcNow,
87+
LastUpdatedBy = "Test User"
88+
});
89+
90+
await _dbContext.SaveChangesAsync();
91+
}
92+
93+
// Get the organization ID
94+
var organization = await _dbContext.Organizations.FirstAsync(o => o.Name == "Test Organization");
95+
96+
// Create some test flows
97+
for (int i = 1; i <= 5; i++)
98+
{
99+
var flowName = $"Test Flow {i}";
100+
101+
if (!await _dbContext.Flows.AnyAsync(f => f.Name == flowName))
102+
{
103+
var flow = new Flow
104+
{
105+
Name = flowName,
106+
OrganizationId = organization.OrganizationId,
107+
Description = $"Test flow {i} description",
108+
AssemblyName = "DidactCore",
109+
TypeName = $"DidactCore.Flows.TestFlow{i}",
110+
ConcurrencyLimit = 1,
111+
Created = DateTime.UtcNow,
112+
CreatedBy = "Test User",
113+
LastUpdated = DateTime.UtcNow,
114+
LastUpdatedBy = "Test User",
115+
Active = true
116+
};
117+
118+
_dbContext.Flows.Add(flow);
119+
}
120+
}
121+
122+
await _dbContext.SaveChangesAsync();
123+
124+
return Ok(new { Message = "Test data seeded successfully" });
125+
}
126+
catch (Exception ex)
127+
{
128+
_logger.LogError(ex, "Error seeding test data");
129+
return StatusCode(500, new { Error = ex.Message });
130+
}
131+
}
132+
}
133+
}

DidactEngine/Controllers/FlowController.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ public async Task<IActionResult> GetFlowByNameAsync()
6161
/// </summary>
6262
/// <returns></returns>
6363
[HttpPost("/flows")]
64-
[SwaggerResponse(StatusCodes.Status202Accepted)]
65-
public async Task<IActionResult> CreateFlowAsync()
64+
[SwaggerResponse(StatusCodes.Status202Accepted)] public async Task<IActionResult> CreateFlowAsync()
6665
{
6766
SomeFlow someFlow = new SomeFlow(_flowLogger, _flowConfigurator, _didactDependencyInjector);
68-
await _flowRepository.SaveConfigurationsAsync(_flowConfigurator);
69-
67+
68+
// Configure the flow first - this populates the _flowConfigurator with actual values
69+
await someFlow.ConfigureAsync();
70+
7071
return Accepted();
7172

7273
// await someFlow.ExecuteAsync("json test string running inside action task block in a flow run");

DidactEngine/Controllers/FlowRunController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DidactCore.Entities;
22
using DidactCore.Flows;
3+
using DidactEngine.Services;
34
using Microsoft.AspNetCore.Mvc;
45
using Swashbuckle.AspNetCore.Annotations;
56

DidactEngine/DidactEngine.csproj

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk.Web">
33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<GenerateDocumentationFile>True</GenerateDocumentationFile>
88
<NoWarn>$(NoWarn);1591</NoWarn>
99
<UserSecretsId>8bccdc4b-2bdb-4817-a72e-bdd5935343db</UserSecretsId>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<!--<Compile Remove="Services\Migrations\**" />
13-
<Content Remove="Services\Migrations\**" />
14-
<EmbeddedResource Remove="Services\Migrations\**" />
15-
<None Remove="Services\Migrations\**" />-->
16-
</ItemGroup>
17-
<ItemGroup>
18-
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
19-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.1" />
20-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
21-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
22-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
23-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
24-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.5" />
25-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.5" />
26-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
12+
<PackageReference Include="Aspire.Hosting" Version="9.0.0" />
13+
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.5" />
15+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
16+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.5" />
17+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5" />
18+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.5" />
19+
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.4" />
20+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.5" />
21+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
</PackageReference>
25+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
26+
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="8.1.4" />
2727
</ItemGroup>
2828
<ItemGroup>
2929

3030
<Content Include="Services\FlowRepository.cs" />
3131
</ItemGroup>
3232
<ItemGroup>
33+
<ProjectReference Include="..\..\Didact\Didact.ServiceDefaults\Didact.ServiceDefaults.csproj" />
34+
</ItemGroup> <ItemGroup>
3335
<Reference Include="DidactCore">
34-
<HintPath>..\..\didact-core\DidactCore\bin\Debug\net8.0\DidactCore.dll</HintPath>
36+
<HintPath>..\..\didact-core\DidactCore\bin\Debug\net9.0\DidactCore.dll</HintPath>
3537
</Reference>
3638
</ItemGroup>
3739
</Project>

0 commit comments

Comments
 (0)