Skip to content

Commit 6b89ff2

Browse files
committed
[Samples][L7] Add client code for Cohesion refactoring example
1 parent 63e7f67 commit 6b89ff2

5 files changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
3+
namespace LessonsSamples.Lesson7.CohesionCoupling
4+
{
5+
class PageXmlExportClient
6+
{
7+
public void Func(IEnumerable<string> customers)
8+
{
9+
var exporter = new PageXmlExport();
10+
11+
foreach (var customer in customers)
12+
{
13+
exporter.ExportCustomerPage("{0}_{1}_{2}", true, customer, 10, true);
14+
}
15+
}
16+
}
17+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using CommonServiceLocator;
3+
4+
namespace LessonsSamples.Lesson7.CohesionCoupling
5+
{
6+
class PageXmlExportClient_1
7+
{
8+
public void ExportDataForCustomers(IEnumerable<string> customers)
9+
{
10+
var exporter = new PageXmlExport_1("{0}_{1}_{2}", true, 10, true);
11+
12+
foreach (var customer in customers)
13+
{
14+
exporter.ExportCustomerPage(customer);
15+
}
16+
}
17+
}
18+
19+
class PageXmlExportClient_12
20+
{
21+
public void ExportDataForCustomers(IEnumerable<string> customers)
22+
{
23+
var exporter = new PageXmlExport_1("{0}_{1}_{2}", true, 10, true);
24+
ICrmService crmService = ServiceLocator.Current.GetInstance<ICrmService>();
25+
ILocationService locationService = ServiceLocator.Current.GetInstance<ILocationService>();
26+
27+
foreach (var customer in customers)
28+
{
29+
PageData userInput = GetUserInput(customer);
30+
exporter.ExportCustomerPageWithExternalData(customer, userInput, crmService, locationService);
31+
}
32+
}
33+
34+
private PageData GetUserInput(string customer)
35+
{
36+
// TODO: take this data from a view model
37+
return new PageData();
38+
}
39+
}
40+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using CommonServiceLocator;
3+
4+
namespace LessonsSamples.Lesson7.CohesionCoupling
5+
{
6+
class PageXmlExportClient_2
7+
{
8+
public void ExportDataForCustomers(IEnumerable<string> customers)
9+
{
10+
ICrmService crmService = ServiceLocator.Current.GetInstance<ICrmService>();
11+
ILocationService locationService = ServiceLocator.Current.GetInstance<ILocationService>();
12+
var exporter = new PageXmlExport_2("{0}_{1}_{2}", true, 10, true, crmService, locationService);
13+
14+
foreach (var customer in customers)
15+
{
16+
PageData userInput = GetUserInput(customer);
17+
exporter.ExportCustomerPageWithExternalData(customer, userInput);
18+
}
19+
}
20+
21+
private PageData GetUserInput(string customer)
22+
{
23+
// TODO: take this data from a view model
24+
return new PageData();
25+
}
26+
}
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using CommonServiceLocator;
3+
4+
namespace LessonsSamples.Lesson7.CohesionCoupling
5+
{
6+
class PageXmlExportClient_3
7+
{
8+
public void ExportDataForCustomers(IEnumerable<string> customers)
9+
{
10+
ICrmService crmService = ServiceLocator.Current.GetInstance<ICrmService>();
11+
ILocationService locationService = ServiceLocator.Current.GetInstance<ILocationService>();
12+
IPageFileWriter pageWriter = ServiceLocator.Current.GetInstance<IPageFileWriter>();
13+
14+
var exporter = new PageXmlExport_3(pageWriter, 10, true, crmService, locationService);
15+
16+
foreach (var customer in customers)
17+
{
18+
PageData userInput = GetUserInput(customer);
19+
exporter.ExportCustomerPageWithExternalData(customer, userInput);
20+
}
21+
}
22+
23+
private PageData GetUserInput(string customer)
24+
{
25+
// TODO: take this data from a view model
26+
return new PageData();
27+
}
28+
}
29+
}

LessonsSamples/LessonsSamples/LessonsSamples.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@
198198
<Compile Include="Lesson7\CohesionCoupling\PageData.cs" />
199199
<Compile Include="Lesson7\CohesionCoupling\PageXml.cs" />
200200
<Compile Include="Lesson7\CohesionCoupling\01_PageXmlExport.cs" />
201+
<Compile Include="Lesson7\CohesionCoupling\10_PageXmlExportClient.cs" />
202+
<Compile Include="Lesson7\CohesionCoupling\11_PageXmlExportClient.cs" />
203+
<Compile Include="Lesson7\CohesionCoupling\12_PageXmlExportClientcs.cs" />
204+
<Compile Include="Lesson7\CohesionCoupling\13_PageXmlExportClient.cs" />
201205
<Compile Include="Lesson7\ErrorHandling\DeviceController.cs" />
202206
<Compile Include="Lesson7\ErrorHandling\CodeSnippet.cs" />
203207
<Compile Include="Lesson7\InheritanceComposition\Account.cs" />

0 commit comments

Comments
 (0)