mirror of https://github.com/abpframework/abp.git
17 changed files with 347 additions and 36 deletions
@ -0,0 +1,5 @@ |
|||||
|
.simulation-client { |
||||
|
border: 1px solid #008000; |
||||
|
background-color: #d6ffce; |
||||
|
margin: 3px; |
||||
|
padding: 5px; } |
||||
@ -0,0 +1 @@ |
|||||
|
.simulation-client{border:1px solid #008000;background-color:#d6ffce;margin:3px;padding:5px;} |
||||
@ -0,0 +1,6 @@ |
|||||
|
.simulation-client { |
||||
|
border: 1px solid #008000; |
||||
|
background-color: #d6ffce; |
||||
|
margin: 3px; |
||||
|
padding: 5px; |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
[ |
||||
|
{ |
||||
|
"outputFile": "Pages/SimulationArea.css", |
||||
|
"inputFile": "Pages/SimulationArea.scss" |
||||
|
} |
||||
|
] |
||||
@ -0,0 +1,63 @@ |
|||||
|
{ |
||||
|
"compilers": { |
||||
|
"less": { |
||||
|
"autoPrefix": "", |
||||
|
"cssComb": "none", |
||||
|
"ieCompat": true, |
||||
|
"strictMath": false, |
||||
|
"strictUnits": false, |
||||
|
"relativeUrls": true, |
||||
|
"rootPath": "", |
||||
|
"sourceMapRoot": "", |
||||
|
"sourceMapBasePath": "", |
||||
|
"sourceMap": false |
||||
|
}, |
||||
|
"sass": { |
||||
|
"autoPrefix": "", |
||||
|
"includePath": "", |
||||
|
"indentType": "space", |
||||
|
"indentWidth": 2, |
||||
|
"outputStyle": "nested", |
||||
|
"Precision": 5, |
||||
|
"relativeUrls": true, |
||||
|
"sourceMapRoot": "", |
||||
|
"lineFeed": "", |
||||
|
"sourceMap": false |
||||
|
}, |
||||
|
"stylus": { |
||||
|
"sourceMap": false |
||||
|
}, |
||||
|
"babel": { |
||||
|
"sourceMap": false |
||||
|
}, |
||||
|
"coffeescript": { |
||||
|
"bare": false, |
||||
|
"runtimeMode": "node", |
||||
|
"sourceMap": false |
||||
|
}, |
||||
|
"handlebars": { |
||||
|
"root": "", |
||||
|
"noBOM": false, |
||||
|
"name": "", |
||||
|
"namespace": "", |
||||
|
"knownHelpersOnly": false, |
||||
|
"forcePartial": false, |
||||
|
"knownHelpers": [], |
||||
|
"commonjs": "", |
||||
|
"amd": false, |
||||
|
"sourceMap": false |
||||
|
} |
||||
|
}, |
||||
|
"minifiers": { |
||||
|
"css": { |
||||
|
"enabled": true, |
||||
|
"termSemicolons": true, |
||||
|
"gzip": false |
||||
|
}, |
||||
|
"javascript": { |
||||
|
"enabled": true, |
||||
|
"termSemicolons": true, |
||||
|
"gzip": false |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using Volo.ClientSimulation.Scenarios; |
||||
|
|
||||
|
namespace Volo.ClientSimulation |
||||
|
{ |
||||
|
public class ClientSimulationOptions |
||||
|
{ |
||||
|
public List<IScenario> Scenarios { get; } |
||||
|
|
||||
|
public ClientSimulationOptions() |
||||
|
{ |
||||
|
Scenarios = new List<IScenario>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.ClientSimulation.Scenarios; |
||||
|
|
||||
|
namespace Volo.ClientSimulation.Clients |
||||
|
{ |
||||
|
public interface IClientFactory |
||||
|
{ |
||||
|
IDisposableClientHandler Create(IScenario scenario); |
||||
|
} |
||||
|
|
||||
|
public class DefaultClientFactory : IClientFactory, ISingletonDependency |
||||
|
{ |
||||
|
public IDisposableClientHandler Create(IScenario scenario) |
||||
|
{ |
||||
|
return new DisposableClientHandler(new Client(scenario)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.ClientSimulation.Clients |
||||
|
{ |
||||
|
public interface IDisposableClientHandler : IDisposable |
||||
|
{ |
||||
|
IClient Client { get; } |
||||
|
} |
||||
|
|
||||
|
public class DisposableClientHandler : IDisposableClientHandler |
||||
|
{ |
||||
|
public IClient Client { get; } |
||||
|
|
||||
|
public DisposableClientHandler(IClient client) |
||||
|
{ |
||||
|
Client = client; |
||||
|
} |
||||
|
|
||||
|
public virtual void Dispose() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,122 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Collections.Immutable; |
||||
|
using System.Text; |
||||
|
using System.Threading; |
||||
|
|
||||
|
namespace Volo.ClientSimulation.Scenarios |
||||
|
{ |
||||
|
public abstract class Scenario : IScenario |
||||
|
{ |
||||
|
public IReadOnlyList<IScenarioStep> Steps => StepList.ToImmutableList(); |
||||
|
protected List<IScenarioStep> StepList { get; } |
||||
|
|
||||
|
public IScenarioStep CurrentStep |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
CheckStepCount(); |
||||
|
return StepList[CurrentStepIndex]; |
||||
|
} |
||||
|
} |
||||
|
public int CurrentStepIndex { get; protected set; } |
||||
|
|
||||
|
protected Scenario() |
||||
|
{ |
||||
|
StepList = new List<IScenarioStep>(); |
||||
|
} |
||||
|
|
||||
|
public virtual string GetDisplayText() |
||||
|
{ |
||||
|
return GetType() |
||||
|
.Name |
||||
|
.RemovePostFix(nameof(Scenario)); |
||||
|
} |
||||
|
|
||||
|
public virtual void Proceed() |
||||
|
{ |
||||
|
CheckStepCount(); |
||||
|
|
||||
|
StepList[CurrentStepIndex].Run(); |
||||
|
|
||||
|
CurrentStepIndex++; |
||||
|
|
||||
|
if (CurrentStepIndex >= StepList.Count) |
||||
|
{ |
||||
|
CurrentStepIndex = 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void CheckStepCount() |
||||
|
{ |
||||
|
if (StepList.Count <= 0) |
||||
|
{ |
||||
|
throw new ApplicationException( |
||||
|
$"No Steps defined for the scenario '{GetDisplayText()}'" |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected void AddStep(IScenarioStep step) |
||||
|
{ |
||||
|
StepList.Add(step); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public interface IScenario |
||||
|
{ |
||||
|
IReadOnlyList<IScenarioStep> Steps { get; } |
||||
|
|
||||
|
IScenarioStep CurrentStep { get; } |
||||
|
|
||||
|
int CurrentStepIndex { get; } |
||||
|
|
||||
|
string GetDisplayText(); |
||||
|
|
||||
|
void Proceed(); |
||||
|
} |
||||
|
|
||||
|
public interface IScenarioStep |
||||
|
{ |
||||
|
void Run(); |
||||
|
|
||||
|
string GetDisplayText(); |
||||
|
} |
||||
|
|
||||
|
public abstract class ScenarioStep : IScenarioStep |
||||
|
{ |
||||
|
public abstract void Run(); |
||||
|
|
||||
|
public virtual string GetDisplayText() |
||||
|
{ |
||||
|
return GetType() |
||||
|
.Name |
||||
|
.RemovePostFix(nameof(ScenarioStep)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class DemoScenario : Scenario |
||||
|
{ |
||||
|
public DemoScenario() |
||||
|
{ |
||||
|
AddStep(new SleepScenarioStep()); |
||||
|
AddStep(new SleepScenarioStep(3000)); |
||||
|
AddStep(new SleepScenarioStep()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class SleepScenarioStep : ScenarioStep |
||||
|
{ |
||||
|
public int Duration { get; } |
||||
|
|
||||
|
public SleepScenarioStep(int duration = 1000) |
||||
|
{ |
||||
|
Duration = duration; |
||||
|
} |
||||
|
|
||||
|
public override void Run() |
||||
|
{ |
||||
|
Thread.Sleep(Duration); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue