초기 커밋.
This commit is contained in:
139
lck_cl_data_solution/RiotKeyChecker/Form1.cs
Normal file
139
lck_cl_data_solution/RiotKeyChecker/Form1.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json;
|
||||
using System.Net;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace RiotKeyChecker
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
listBox1.Items.Clear();
|
||||
GameListUpdateWorker(true);
|
||||
}
|
||||
|
||||
|
||||
internal const string 라이엇_게임리스트_REQUEST_URL = "https://raw-stats-api.ewp.gg/livestatsRaw/v1/";
|
||||
|
||||
internal Dictionary<string, string> GameListUpdateWorker(bool isTest)
|
||||
{
|
||||
|
||||
//string bufRequestURL = DEFINE.라이엇_게임리스트_REQUEST_URL + (isTest ? "platformGames" : "esportsGames") + "?state=in_progress";;
|
||||
string bufRequestURL = 라이엇_게임리스트_REQUEST_URL + (isTest ? "platformGames" : "esportsGames") + "?state=in_progress"; ;
|
||||
//string bufRequestURL = DEFINE.라이엇_게임리스트_REQUEST_URL + "esportsGames" + "?state=finished"; ;
|
||||
string result = null;
|
||||
|
||||
///20210809 SSL접속문제로 인해 서버인증기능을 끈 부분을 추가한다 이거 이래도 되나?
|
||||
//ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
|
||||
///가져온 URL에 맞춰 리퀘스트를 만든다.
|
||||
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(bufRequestURL);
|
||||
req.Method = "GET";
|
||||
WebHeaderCollection hd = new WebHeaderCollection();
|
||||
|
||||
hd.Add("x-api-key:" + textBox1.Text);
|
||||
|
||||
req.Headers = hd;
|
||||
WebResponse rsp = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
rsp = req.GetResponse();
|
||||
|
||||
|
||||
///가져온 데이터를 문자열화 하고, Bson형태로 파싱해서 리턴한다.
|
||||
using (var reader = new StreamReader(rsp.GetResponseStream()))
|
||||
{
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
IEnumerable<BsonValue> bufGameList = null;
|
||||
|
||||
List<string> updateRoomList = new List<string>();
|
||||
|
||||
Dictionary<String, string> rtnValue = new Dictionary<string, string>();
|
||||
|
||||
///가져온 데이터가 null이 아니라면 데이터를 Game단위(Document)로 짤라서 Enumarable화 하고, 아니면 빈 결과를 리턴한다.
|
||||
if (result != null)
|
||||
{
|
||||
bufGameList = BsonSerializer.Deserialize<BsonArray>(result).Select(p => p.AsBsonDocument);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//가져온 데이터에서 방제와 플랫폼게임ID를 파싱해서 KV페어로 만든다.
|
||||
foreach (BsonValue item in bufGameList)
|
||||
{
|
||||
string bufString = "";
|
||||
|
||||
///20210615테스트할부분 방을 새로만든부분이 있을경우 Document 순서에서 나중에 들어오므로 과거에 들어왔던 데이터를 버린다.
|
||||
///혹시 모르니 안버린다.
|
||||
//if (rtnValue.ContainsValue(item["gameName"].ToString()))
|
||||
//{
|
||||
// rtnValue.Remove(rtnValue.FirstOrDefault(x => x.Value == item["gameName"].ToString()).Key);
|
||||
//}
|
||||
|
||||
if (isTest)
|
||||
{
|
||||
rtnValue.Add(item["platformGameId"].ToString(), item["gameName"].ToString());
|
||||
|
||||
bufString = item["platformGameId"].ToString() + "_" + item["gameName"].ToString();
|
||||
|
||||
updateRoomList.Add(bufString);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
BsonDocument itemDocument = item.AsBsonDocument["platformGames"].AsBsonArray.Last().ToBsonDocument();
|
||||
|
||||
rtnValue.Add(itemDocument["platformGameId"].ToString(), itemDocument["gameName"].ToString());
|
||||
|
||||
bufString = itemDocument["platformGameId"].ToString() + "_" + itemDocument["gameName"].ToString();
|
||||
|
||||
updateRoomList.Add(bufString);
|
||||
}
|
||||
|
||||
#if (DEBUG)
|
||||
{
|
||||
Console.WriteLine(bufString);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
///완성된 방 정보를 UI에 업데이트한다.
|
||||
///
|
||||
this.Invoke(new MethodInvoker(() => {
|
||||
|
||||
foreach (string item in updateRoomList)
|
||||
{
|
||||
listBox1.Items.Add(item);
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
return rtnValue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user