File tree Expand file tree Collapse file tree
LessonsSamples/LessonsSamples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+ using System . Threading . Tasks ;
6+
7+ namespace LessonsSamples . Lesson5
8+ {
9+ interface IDoor
10+ {
11+ void Open ( ) ;
12+ void Close ( ) ;
13+ bool IsOpened ( ) ;
14+ }
15+
16+ class TimedDoor : IDoor
17+ {
18+ private readonly Timer timer = new Timer ( ) ;
19+ private Guid lastRegisteredTimerId ;
20+
21+ public void Open ( )
22+ {
23+ this . lastRegisteredTimerId = Guid . NewGuid ( ) ;
24+ DoorTimerAdapter doorTimerAdapter = new DoorTimerAdapter ( this ) ;
25+ timer . Register ( 3 , doorTimerAdapter , lastRegisteredTimerId ) ;
26+
27+ // open
28+ }
29+
30+ public void Close ( )
31+ {
32+ throw new NotImplementedException ( ) ;
33+ }
34+
35+ public bool IsOpened ( )
36+ {
37+ throw new NotImplementedException ( ) ;
38+ }
39+
40+ public void Timeout ( Guid timerId )
41+ {
42+ if ( timerId == lastRegisteredTimerId )
43+ {
44+ // ring the alarm
45+ }
46+ }
47+
48+ class DoorTimerAdapter : ITimerClient
49+ {
50+ private TimedDoor door ;
51+
52+ public DoorTimerAdapter ( TimedDoor door )
53+ {
54+ this . door = door ;
55+ }
56+
57+ public void Timeout ( Guid timerId )
58+ {
59+ door . Timeout ( timerId ) ;
60+ }
61+ }
62+ }
63+
64+ class Timer
65+ {
66+ public void Register ( int timeout , ITimerClient client , Guid timerId )
67+ {
68+ // register timer
69+ // start clock ->
70+
71+ client . Timeout ( timerId ) ;
72+ }
73+ }
74+
75+ interface ITimerClient
76+ {
77+ void Timeout ( Guid timerId ) ;
78+ }
79+ }
Original file line number Diff line number Diff line change 131131 </ItemGroup >
132132 <ItemGroup >
133133 <Compile Include =" Customer.cs" />
134+ <Compile Include =" Lesson5\TimedDoorAdapter.cs" />
134135 <Compile Include =" Lesson7\GoodClasses\DataModel\Repository.cs" />
135136 <Compile Include =" Lesson7\GoodClasses\DataModel\SalesOrder.cs" />
136137 <Compile Include =" Lesson5\ImageScale.cs" />
You can’t perform that action at this time.
0 commit comments