Skip to content

Commit 37bccbd

Browse files
committed
Add SimulationService sample
1 parent 64f8039 commit 37bccbd

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

backend/ServiceSimulation/Bll.Domain/Bll.Domain.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
<ItemGroup>
1010
<Folder Include="Entities\" />
11-
<Folder Include="Services\" />
1211
</ItemGroup>
1312

1413
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Bll.Domain.Interfaces;
2+
3+
namespace Bll.Domain.Entities;
4+
5+
public class TimeProvider : ITimeProvider
6+
{
7+
public DateTime Now { get; } = DateTime.Now;
8+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Api.enums;
2+
using Bll.Domain.Interfaces;
3+
4+
namespace Bll.Domain.Services;
5+
6+
public class SimulationService : ISimulationService
7+
{
8+
private readonly ISource _source;
9+
private readonly IBuffer _buffer;
10+
private readonly IDevice _device;
11+
12+
public SimulationService(ISource source, IBuffer buffer, IDevice device)
13+
{
14+
_source = source;
15+
_buffer = buffer;
16+
_device = device;
17+
}
18+
19+
public void StartSimulation(SimulationType simulationType)
20+
{
21+
// TODO CHOSE NUMBER OF SOURCES, SIZE OF BUFFER, NUMBER OF DEVICES.
22+
23+
// TODO ALGORITHM OF CHOOSING REQUEST FROM SOURCE AND PUT IT ON DEVICE
24+
var request =_source.GetNewRequest();
25+
26+
_buffer.Push(request);
27+
28+
var requestFromBuffer = _buffer.Pop();
29+
30+
if (requestFromBuffer == null) return;
31+
32+
_device.TakeRequest(requestFromBuffer);
33+
34+
// TODO MAKE SOME KIND OF JSON ANSWER.
35+
}
36+
}

backend/ServiceSimulation/WebApplication2/Program.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
using Bll.Domain.Entities;
2+
using Bll.Domain.Factories;
3+
using Bll.Domain.Interfaces;
4+
using Bll.Domain.Services;
5+
using Buffer = Bll.Domain.Entities.Buffer;
6+
17
var builder = WebApplication.CreateBuilder(args);
28

39
builder.Services.AddControllers();
410
builder.Services.AddEndpointsApiExplorer();
511
builder.Services.AddSwaggerGen();
612

13+
#region servicesDI
14+
builder.Services.AddTransient<ISimulationService, SimulationService>();
15+
16+
builder.Services.AddTransient<ITimeProvider, TimeProvider>();
17+
builder.Services.AddTransient<IBuffer, Buffer>();
18+
builder.Services.AddTransient<IBufferManager, StandardBufferManager>();
19+
builder.Services.AddTransient<IBufferManagerFactory, BufferManagerFactory>();
20+
builder.Services.AddTransient<IDevice, Device>();
21+
builder.Services.AddTransient<ISource, Source>();
22+
23+
#endregion
24+
725
var app = builder.Build();
826

927
if (app.Environment.IsDevelopment())

0 commit comments

Comments
 (0)