Created
February 3, 2011 21:15
-
-
Save PJK/810212 to your computer and use it in GitHub Desktop.
DESF usage exaple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using DESF; | |
using DESF.Flow.Event; | |
using DESF.Flow.Calendar; | |
using DESF.Tools; | |
namespace CalendarTest | |
{ | |
class PisekContext : SimulationContext | |
{ | |
public Hromada Hromada = new Hromada(20); | |
} | |
class Auto : DESF.Flow.Event.IEventHandler, IContextConsumer, DESF.Subject.Logger.ILogContributor | |
{ | |
const uint AB = 5; | |
const uint BA = 7; | |
const uint nosnost = 2; | |
public string UniqueName | |
{ | |
get; | |
set; | |
} | |
protected PisekContext _context; | |
public void setContext(SimulationContext cont) | |
{ | |
_context = (PisekContext)cont; | |
} | |
public void Notify(DESF.Flow.Event.Event ev, IEventEmmiter source) | |
{ | |
ReflectiveEventDispatcher.Notify(this, ev, source); | |
} | |
public void HandleSimulationStarted(Event ev, IEventEmmiter sender) | |
{ | |
_context.Logger.Log(this, "Recieved SimulationStarted signal, jedu do B", 6); | |
_context.Calendar.AddTerm(new Term(_context.Calendar.Time+AB,this,"DojelDoB",null)); | |
} | |
public void HandleDojelDoA(Event ev, IEventEmmiter sender) | |
{ | |
_context.Logger.Log(this, "Jsem v A, jedu do B", 6); | |
_context.Calendar.AddTerm(new Term(_context.Calendar.Time+AB,this,"DojelDoB",null)); | |
} | |
public void HandleDojelDoB(Event ev, IEventEmmiter sender) | |
{ | |
_context.Logger.Log(this, "Jsem v B, nakladam pisek a jedu do A", 6); | |
_context.Calendar.AddTerm(new Term(_context.Calendar.Time+BA,this,"DojelDoA",null)); | |
_context.Hromada.Odebrat(nosnost); | |
} | |
public void HandleSimulationStopped(Event ev, IEventEmmiter sender) | |
{ | |
_context.Logger.Log(this, "Moje prace tady je hotova!", 6); | |
} | |
} | |
class Hromada : DESF.Subject.Logger.ILogContributor, IContextConsumer | |
{ | |
protected int _hmotnost; | |
protected SimulationContext _context; | |
protected string _name = "Kopec pisku"; | |
public string UniqueName | |
{ | |
get | |
{ | |
return _name; | |
} | |
} | |
public Hromada(uint velikost) | |
{ | |
_hmotnost = (int)velikost; | |
} | |
public void Odebrat(uint kolik) | |
{ | |
_hmotnost -= (int)kolik; | |
_context.Logger.Log(this, String.Format("Z hromady bylo odebrano {0}, zbyva {1}", kolik,_hmotnost), 5); | |
if (_hmotnost <= 0) | |
{ | |
_context.Logger.Log(this, "Hromada je prazdna, ukoncuji simulaci", 1); | |
_context.Calendar.StopSimulation(); | |
} | |
} | |
public void setContext(SimulationContext cont) | |
{ | |
_context = cont; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
PisekContext context = new PisekContext(); | |
context.Hromada.setContext(context); | |
context.Calendar = new Calendar(context); | |
context.Logger = new DESF.Subject.Logger.ConsoleLogger(10); | |
((DESF.Subject.Logger.ConsoleLogger)context.Logger).setContext(context); | |
Auto tatra = new Auto(); | |
tatra.setContext(context); | |
tatra.UniqueName = "Tatra TZG 12-48"; | |
context.Calendar.AttachHandler(tatra); | |
context.Calendar.StartSimulation(); | |
while (context.Calendar.HasNextTerm()) | |
{ | |
context.Calendar.Procceed(); | |
} | |
Console.Read(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 [Calendar]-> Attached a new handler: Tatra TZG 12-48 | |
0 [Calendar]-> Starting up the simulation | |
0 [Tatra TZG 12-48]-> Recieved SimulationStarted signal, jedu do B | |
0 [Calendar]-> Adding a new term (time: 5, state DojelDoB, owner Tatra TZG 12-48) | |
5 [Calendar]-> Invoking a term (time: 5, state DojelDoB, owner Tatra TZG 12-48) | |
5 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
5 [Calendar]-> Adding a new term (time: 12, state DojelDoA, owner Tatra TZG 12-48) | |
5 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 18 | |
12 [Calendar]-> Invoking a term (time: 12, state DojelDoA, owner Tatra TZG 12-48) | |
12 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
12 [Calendar]-> Adding a new term (time: 17, state DojelDoB, owner Tatra TZG 12-48) | |
17 [Calendar]-> Invoking a term (time: 17, state DojelDoB, owner Tatra TZG 12-48) | |
17 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
17 [Calendar]-> Adding a new term (time: 24, state DojelDoA, owner Tatra TZG 12-48) | |
17 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 16 | |
24 [Calendar]-> Invoking a term (time: 24, state DojelDoA, owner Tatra TZG 12-48) | |
24 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
24 [Calendar]-> Adding a new term (time: 29, state DojelDoB, owner Tatra TZG 12-48) | |
29 [Calendar]-> Invoking a term (time: 29, state DojelDoB, owner Tatra TZG 12-48) | |
29 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
29 [Calendar]-> Adding a new term (time: 36, state DojelDoA, owner Tatra TZG 12-48) | |
29 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 14 | |
36 [Calendar]-> Invoking a term (time: 36, state DojelDoA, owner Tatra TZG 12-48) | |
36 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
36 [Calendar]-> Adding a new term (time: 41, state DojelDoB, owner Tatra TZG 12-48) | |
41 [Calendar]-> Invoking a term (time: 41, state DojelDoB, owner Tatra TZG 12-48) | |
41 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
41 [Calendar]-> Adding a new term (time: 48, state DojelDoA, owner Tatra TZG 12-48) | |
41 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 12 | |
48 [Calendar]-> Invoking a term (time: 48, state DojelDoA, owner Tatra TZG 12-48) | |
48 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
48 [Calendar]-> Adding a new term (time: 53, state DojelDoB, owner Tatra TZG 12-48) | |
53 [Calendar]-> Invoking a term (time: 53, state DojelDoB, owner Tatra TZG 12-48) | |
53 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
53 [Calendar]-> Adding a new term (time: 60, state DojelDoA, owner Tatra TZG 12-48) | |
53 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 10 | |
60 [Calendar]-> Invoking a term (time: 60, state DojelDoA, owner Tatra TZG 12-48) | |
60 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
60 [Calendar]-> Adding a new term (time: 65, state DojelDoB, owner Tatra TZG 12-48) | |
65 [Calendar]-> Invoking a term (time: 65, state DojelDoB, owner Tatra TZG 12-48) | |
65 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
65 [Calendar]-> Adding a new term (time: 72, state DojelDoA, owner Tatra TZG 12-48) | |
65 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 8 | |
72 [Calendar]-> Invoking a term (time: 72, state DojelDoA, owner Tatra TZG 12-48) | |
72 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
72 [Calendar]-> Adding a new term (time: 77, state DojelDoB, owner Tatra TZG 12-48) | |
77 [Calendar]-> Invoking a term (time: 77, state DojelDoB, owner Tatra TZG 12-48) | |
77 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
77 [Calendar]-> Adding a new term (time: 84, state DojelDoA, owner Tatra TZG 12-48) | |
77 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 6 | |
84 [Calendar]-> Invoking a term (time: 84, state DojelDoA, owner Tatra TZG 12-48) | |
84 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
84 [Calendar]-> Adding a new term (time: 89, state DojelDoB, owner Tatra TZG 12-48) | |
89 [Calendar]-> Invoking a term (time: 89, state DojelDoB, owner Tatra TZG 12-48) | |
89 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
89 [Calendar]-> Adding a new term (time: 96, state DojelDoA, owner Tatra TZG 12-48) | |
89 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 4 | |
96 [Calendar]-> Invoking a term (time: 96, state DojelDoA, owner Tatra TZG 12-48) | |
96 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
96 [Calendar]-> Adding a new term (time: 101, state DojelDoB, owner Tatra TZG 12-48) | |
101 [Calendar]-> Invoking a term (time: 101, state DojelDoB, owner Tatra TZG 12-48) | |
101 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
101 [Calendar]-> Adding a new term (time: 108, state DojelDoA, owner Tatra TZG 12-48) | |
101 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 2 | |
108 [Calendar]-> Invoking a term (time: 108, state DojelDoA, owner Tatra TZG 12-48) | |
108 [Tatra TZG 12-48]-> Jsem v A, jedu do B | |
108 [Calendar]-> Adding a new term (time: 113, state DojelDoB, owner Tatra TZG 12-48) | |
113 [Calendar]-> Invoking a term (time: 113, state DojelDoB, owner Tatra TZG 12-48) | |
113 [Tatra TZG 12-48]-> Jsem v B, nakladam pisek a jedu do A | |
113 [Calendar]-> Adding a new term (time: 120, state DojelDoA, owner Tatra TZG 12-48) | |
113 [Kopec pisku]-> Z hromady bylo odebrano 2, zbyva 0 | |
113 [Kopec pisku]-> Hromada je prazdna, ukoncuji simulaci | |
113 [Calendar]-> Sending SimulationSopped signal | |
113 [Tatra TZG 12-48]-> Moje prace tady je hotova! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment