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 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 bufGameList = null; List updateRoomList = new List(); Dictionary rtnValue = new Dictionary(); ///°¡Á®¿Â µ¥ÀÌÅͰ¡ nullÀÌ ¾Æ´Ï¶ó¸é µ¥ÀÌÅ͸¦ Game´ÜÀ§(Document)·Î ©¶ó¼­ EnumarableÈ­ Çϰí, ¾Æ´Ï¸é ºó °á°ú¸¦ ¸®ÅÏÇÑ´Ù. if (result != null) { bufGameList = BsonSerializer.Deserialize(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; } } }