-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataTableGeneration.cs
75 lines (65 loc) · 2.23 KB
/
DataTableGeneration.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
67
68
69
70
71
72
73
74
75
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace APPID
{
public class DataTableGeneration
{
public static DataTable dataTable;
public static DataTable dt;
public DataTableGeneration() { }
public static string RemoveSpecialCharacters(string str)
{
str = str.Replace(":", " -").Replace("'", "").Replace("&", "and");
return Regex.Replace(str, "[^a-zA-Z0-9._0 -]+", "", RegexOptions.Compiled);
}
public async Task<DataTable> GetDataTableAsync(DataTableGeneration dataTableGeneration) {
HttpClient httpClient = new HttpClient();
string content = await httpClient.GetStringAsync("https://api.steampowered.com/ISteamApps/GetAppList/v2/");
SteamGames steamGames = JsonConvert.DeserializeObject<SteamGames>(content);
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(String));
dt.Columns.Add("AppId", typeof(int));
foreach (var item in steamGames.Applist.Apps)
{
string ItemWithoutTroubles = RemoveSpecialCharacters(item.Name);
dt.Rows.Add(ItemWithoutTroubles, item.Appid);
}
dataTableGeneration.DataTableToGenerate = dt;
return dt;
}
#region Get and Set
public DataTable DataTableToGenerate{
get { return dataTable; } // get method
set { dataTable = value; } // set method
}
#endregion
#region JSON Properties
public partial class SteamGames
{
[JsonProperty("applist")]
public Applist Applist { get; set; }
}
public partial class Applist
{
[JsonProperty("apps")]
public App[] Apps { get; set; }
}
public partial class App
{
[JsonProperty("appid")]
public long Appid { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
#endregion
}
}