-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalWay.cs
More file actions
121 lines (106 loc) · 3 KB
/
NormalWay.cs
File metadata and controls
121 lines (106 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
namespace TestTdd
{
internal class NormalData
{
private int _energyCostPerAdd;
public int EnergyCostPerAdd { get { return _energyCostPerAdd; } }
public NormalData(string filePath)
{
// Fake read and fill data
_energyCostPerAdd = 2;
}
}
internal class NormalStore
{
private int _energy = 0;
public int Energy
{
get { return _energy; }
set
{
_energy = Math.Max(0, value);
Console.WriteLine(string.Format("Energy log: {0}", _energy));
}
}
}
internal class NormalService
{
public void Add(int a, int b, Action<bool, int> handler)
{
handler(true, a + b);
}
public void WhatTimeIsIt(Action<bool, long> handler)
{
handler(true, 123);
}
}
internal class NormalUi
{
private readonly NormalData _data;
private readonly NormalStore _store;
private readonly NormalService _service;
private bool _available = false;
public NormalUi(NormalData data, NormalStore store, NormalService service)
{
_data = data;
_store = store;
_service = service;
if (_data == null || _store == null || _service == null)
{
throw new ArgumentNullException("Something");
}
init();
}
public void Add(int a, int b)
{
if (_available)
{
if (_store.Energy >= _data.EnergyCostPerAdd)
{
Console.WriteLine("Please wait...");
_service.Add(a, b, (ok, added) =>
{
if (ok)
{
_store.Energy -= _data.EnergyCostPerAdd;
Console.WriteLine(string.Format("Sum is {0}", added));
}
else
{
Console.WriteLine("Error receive result from service");
}
});
}
else
{
Console.WriteLine("Not enough energy");
}
}
else
{
Console.WriteLine("Can not connect to service");
}
}
private void init()
{
Console.WriteLine("Please wait...");
_service.WhatTimeIsIt((ok, time) =>
{
if (ok)
{
_available = true;
Console.WriteLine("Please do something");
}
else
{
_available = false;
Console.WriteLine("Can not connect to service");
}
});
}
}
internal class NormalWay
{
}
}