-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuggestionProvider.cs
66 lines (56 loc) · 1.76 KB
/
SuggestionProvider.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
59
60
61
62
63
64
65
66
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WpfAutoCompleteControls.Editors;
namespace Covid19_Tracker
{
internal sealed class SuggestionProvider : ISuggestionProvider
{
public readonly List<CountryListData> countriesList = new List<CountryListData>();
private readonly TimeSpan Delay = TimeSpan.FromSeconds(0);
public SuggestionProvider()
{
dataFetch();
}
public async void dataFetch()
{
try
{
RootObject covidData = await CovidStatsData.GetCovidStatsData();
covidData.Countries.ForEach(country => countriesList.Add(new CountryListData(country.Country)));
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public IEnumerable GetSuggestions(string filter)
{
Thread.Sleep(Delay);
if (string.IsNullOrWhiteSpace(filter))
{
return countriesList;
}
filter = filter.Trim();
return countriesList.Where(x => x.Name.StartsWith(filter, StringComparison.OrdinalIgnoreCase));
/*.Where(x => x.Name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0);*/
}
IEnumerable ISuggestionProvider.GetSuggestions(string filter)
{
IEnumerable suggestions = GetSuggestions(filter);
return suggestions;
}
}
public class CountryListData
{
public string Name { get; set; }
public CountryListData(string country)
{
this.Name = country;
}
}
}