Browse Source

Created simulation library.

pull/975/head
Halil ibrahim Kalkan 7 years ago
parent
commit
20fc53ad9d
  1. 1
      .gitignore
  2. 7
      utils/client-simulation/Volo.ClientSimulation.Web.sln
  3. 3
      utils/client-simulation/src/Volo.ClientSimulation.Web/ClientSimulationWebModule.cs
  4. 22
      utils/client-simulation/src/Volo.ClientSimulation.Web/Pages/SimulationArea.cshtml
  5. 21
      utils/client-simulation/src/Volo.ClientSimulation.Web/Pages/SimulationArea.cshtml.cs
  6. 8
      utils/client-simulation/src/Volo.ClientSimulation.Web/Pages/SimulationArea.js
  7. 31
      utils/client-simulation/src/Volo.ClientSimulation.Web/Program.cs
  8. 10
      utils/client-simulation/src/Volo.ClientSimulation.Web/Volo.ClientSimulation.Web.csproj
  9. 12
      utils/client-simulation/src/Volo.ClientSimulation/Volo.ClientSimulation.csproj
  10. 12
      utils/client-simulation/src/Volo.ClientSimulation/Volo/ClientSimulation/ClientSimulationModule.cs
  11. 26
      utils/client-simulation/src/Volo.ClientSimulation/Volo/ClientSimulation/Simulation.cs
  12. 14
      utils/client-simulation/src/Volo.ClientSimulation/Volo/ClientSimulation/SimulationState.cs

1
.gitignore

@ -294,3 +294,4 @@ samples/MicroserviceDemo/gateways/BackendAdminAppGateway.Host/Logs/logs.txt
samples/MicroserviceDemo/applications/PublicWebSite.Host/Logs/logs.txt samples/MicroserviceDemo/applications/PublicWebSite.Host/Logs/logs.txt
samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Logs/logs.txt samples/MicroserviceDemo/gateways/PublicWebSiteGateway.Host/Logs/logs.txt
samples/MicroserviceDemo/microservices/BloggingService.Host/Logs/logs.txt samples/MicroserviceDemo/microservices/BloggingService.Host/Logs/logs.txt
utils/client-simulation/src/Volo.ClientSimulation.Web/Logs/logs.txt

7
utils/client-simulation/Volo.ClientSimulation.Web.sln

@ -7,6 +7,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{42503D63-D29
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.ClientSimulation.Web", "src\Volo.ClientSimulation.Web\Volo.ClientSimulation.Web.csproj", "{7579B444-3411-4E3B-8DF3-19684C1F34C2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.ClientSimulation.Web", "src\Volo.ClientSimulation.Web\Volo.ClientSimulation.Web.csproj", "{7579B444-3411-4E3B-8DF3-19684C1F34C2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.ClientSimulation", "src\Volo.ClientSimulation\Volo.ClientSimulation.csproj", "{BB780A98-727D-49CF-9A4C-91E6EA7047AD}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -17,12 +19,17 @@ Global
{7579B444-3411-4E3B-8DF3-19684C1F34C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {7579B444-3411-4E3B-8DF3-19684C1F34C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7579B444-3411-4E3B-8DF3-19684C1F34C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {7579B444-3411-4E3B-8DF3-19684C1F34C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7579B444-3411-4E3B-8DF3-19684C1F34C2}.Release|Any CPU.Build.0 = Release|Any CPU {7579B444-3411-4E3B-8DF3-19684C1F34C2}.Release|Any CPU.Build.0 = Release|Any CPU
{BB780A98-727D-49CF-9A4C-91E6EA7047AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB780A98-727D-49CF-9A4C-91E6EA7047AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB780A98-727D-49CF-9A4C-91E6EA7047AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB780A98-727D-49CF-9A4C-91E6EA7047AD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{7579B444-3411-4E3B-8DF3-19684C1F34C2} = {42503D63-D292-4A18-8ECE-8270167DD842} {7579B444-3411-4E3B-8DF3-19684C1F34C2} = {42503D63-D292-4A18-8ECE-8270167DD842}
{BB780A98-727D-49CF-9A4C-91E6EA7047AD} = {42503D63-D292-4A18-8ECE-8270167DD842}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1AF598E1-2012-47B4-A591-ADC9F327600A} SolutionGuid = {1AF598E1-2012-47B4-A591-ADC9F327600A}

3
utils/client-simulation/src/Volo.ClientSimulation.Web/ClientSimulationWebModule.cs

@ -9,7 +9,8 @@ namespace Volo.ClientSimulation.Web
{ {
[DependsOn( [DependsOn(
typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule),
typeof(AbpAutofacModule) typeof(AbpAutofacModule),
typeof(ClientSimulationModule)
)] )]
public class ClientSimulationWebModule : AbpModule public class ClientSimulationWebModule : AbpModule
{ {

22
utils/client-simulation/src/Volo.ClientSimulation.Web/Pages/SimulationArea.cshtml

@ -1,10 +1,22 @@
@page @page "{handler?}"
@{ @{
Layout = null; Layout = null;
} }
@using Volo.Abp @using Volo.ClientSimulation
@model Volo.ClientSimulation.Web.Pages.SimulationAreaModel @model Volo.ClientSimulation.Web.Pages.SimulationAreaModel
<abp-button id="StartButton" button-type="Primary" asp-page-handler="Start">Start</abp-button> <abp-alert alert-type="Primary">
<abp-button id="StopButton" button-type="Primary" abp-button="Primary" asp-page-handler="Stop">Stop</abp-button> <form class="d-inline" id="StartButtonForm" method="post" asp-page-handler="Start" data-ajaxForm="true">
<abp-button button-type="Primary" type="submit" disabled="@(Model.Simulation.State != SimulationState.Stopped)">Start</abp-button>
</form>
<form class="d-inline" id="StopButtonForm" method="post" asp-page-handler="Stop" data-ajaxForm="true">
<abp-button button-type="Primary" type="submit" disabled="@(Model.Simulation.State != SimulationState.Started)">Stop</abp-button>
</form>
<span class="ml-3">
@Model.Simulation.State
</span>
</abp-alert>
<abp-card class="mt-3">
<abp-card-body>
@RandomHelper.GetRandom(1, 111) </abp-card-body>
</abp-card>

21
utils/client-simulation/src/Volo.ClientSimulation.Web/Pages/SimulationArea.cshtml.cs

@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
@ -9,18 +6,28 @@ namespace Volo.ClientSimulation.Web.Pages
{ {
public class SimulationAreaModel : PageModel public class SimulationAreaModel : PageModel
{ {
public async Task OnGetAsync() public Simulation Simulation { get; }
public SimulationAreaModel(Simulation simulation)
{ {
Simulation = simulation;
} }
public async Task PostStartAsync() public Task OnGetAsync()
{ {
return Task.CompletedTask;
} }
public async Task PostStopAsync() public async Task<IActionResult> OnPostStartAsync()
{ {
await Simulation.StartAsync();
return new NoContentResult();
}
public async Task<IActionResult> OnPostStopAsync()
{
await Simulation.StopAsync();
return new NoContentResult();
} }
} }
} }

8
utils/client-simulation/src/Volo.ClientSimulation.Web/Pages/SimulationArea.js

@ -4,17 +4,17 @@
var $mainContainer = null; var $mainContainer = null;
function refreshSimulationArea() { function refreshSimulationArea() {
$.get('/SimulationArea').done( $.get('/SimulationArea')
function (result) { .done(function(result) {
$mainContainer.html(result); $mainContainer.html(result);
}).always(function () { })
.always(function() {
setTimeout(refreshSimulationArea, 1000); setTimeout(refreshSimulationArea, 1000);
}); });
} }
SimulationArea.init = function ($container) { SimulationArea.init = function ($container) {
$mainContainer = $container; $mainContainer = $container;
console.log('Simulation initialized');
setTimeout(refreshSimulationArea, 1000); setTimeout(refreshSimulationArea, 1000);
}; };

31
utils/client-simulation/src/Volo.ClientSimulation.Web/Program.cs

@ -1,14 +1,38 @@
using System.IO; using System;
using System.IO;
using Microsoft.AspNetCore; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Serilog;
using Serilog.Events;
namespace Volo.ClientSimulation.Web namespace Volo.ClientSimulation.Web
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static int Main(string[] args)
{ {
BuildWebHostInternal(args).Run(); Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.File("Logs/logs.txt")
.CreateLogger();
try
{
Log.Information("Starting web host.");
BuildWebHostInternal(args).Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly!");
return 1;
}
finally
{
Log.CloseAndFlush();
}
} }
public static IWebHost BuildWebHostInternal(string[] args) => public static IWebHost BuildWebHostInternal(string[] args) =>
@ -17,6 +41,7 @@ namespace Volo.ClientSimulation.Web
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>() .UseStartup<Startup>()
.UseSerilog()
.Build(); .Build();
} }
} }

10
utils/client-simulation/src/Volo.ClientSimulation.Web/Volo.ClientSimulation.Web.csproj

@ -7,11 +7,21 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\Volo.ClientSimulation\Volo.ClientSimulation.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Logs\**" />
<Content Remove="Logs\**" />
<EmbeddedResource Remove="Logs\**" />
<None Remove="Logs\**" />
</ItemGroup> </ItemGroup>
</Project> </Project>

12
utils/client-simulation/src/Volo.ClientSimulation/Volo.ClientSimulation.csproj

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace></RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj" />
</ItemGroup>
</Project>

12
utils/client-simulation/src/Volo.ClientSimulation/Volo/ClientSimulation/ClientSimulationModule.cs

@ -0,0 +1,12 @@
using Volo.Abp.Http.Client.IdentityModel;
using Volo.Abp.Modularity;
namespace Volo.ClientSimulation
{
[DependsOn(
typeof(AbpHttpClientIdentityModelModule)
)]
public class ClientSimulationModule : AbpModule
{
}
}

26
utils/client-simulation/src/Volo.ClientSimulation/Volo/ClientSimulation/Simulation.cs

@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.ClientSimulation
{
public class Simulation : ISingletonDependency
{
public SimulationState State { get; private set; }
public Task StartAsync()
{
State = SimulationState.Starting;
State = SimulationState.Started;
return Task.CompletedTask;
}
public Task StopAsync()
{
State = SimulationState.Stopping;
State = SimulationState.Stopped;
return Task.CompletedTask;
}
}
}

14
utils/client-simulation/src/Volo.ClientSimulation/Volo/ClientSimulation/SimulationState.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.ClientSimulation
{
public enum SimulationState
{
Stopped,
Starting,
Started,
Stopping
}
}
Loading…
Cancel
Save