-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoCustomerProvider.cs
58 lines (53 loc) · 1.83 KB
/
DemoCustomerProvider.cs
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
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
namespace DataVirtualization
{
/// <summary>
/// Demo implementation of IItemsProvider returning dummy customer items after
/// a pause to simulate network/disk latency.
/// </summary>
public class DemoCustomerProvider : IItemsProvider<Customer>
{
private readonly int _count;
private readonly int _fetchDelay;
/// <summary>
/// Initializes a new instance of the <see cref="DemoCustomerProvider"/> class.
/// </summary>
/// <param name="count">The count.</param>
/// <param name="fetchDelay">The fetch delay.</param>
public DemoCustomerProvider(int count, int fetchDelay)
{
_count = count;
_fetchDelay = fetchDelay;
}
/// <summary>
/// Fetches the total number of items available.
/// </summary>
/// <returns></returns>
public int FetchCount()
{
Trace.WriteLine("FetchCount");
Thread.Sleep(_fetchDelay);
return _count;
}
/// <summary>
/// Fetches a range of items.
/// </summary>
/// <param name="startIndex">The start index.</param>
/// <param name="count">The number of items to fetch.</param>
/// <returns></returns>
public IList<Customer> FetchRange(int startIndex, int count)
{
Trace.WriteLine("FetchRange: "+startIndex+","+count);
Thread.Sleep(_fetchDelay);
List<Customer> list = new List<Customer>();
for( int i=startIndex; i<startIndex+count; i++ )
{
Customer customer = new Customer {Id = i+1, Name = "Customer " + (i+1)};
list.Add(customer);
}
return list;
}
}
}