284 lines
10 KiB
C#
284 lines
10 KiB
C#
using MySql.Data.MySqlClient;
|
|
using Newtonsoft.Json;
|
|
using PoEco.Net.DB;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static PoEco.Net.JSON.Classes.Divination;
|
|
|
|
namespace PoEco.Net.Web
|
|
{
|
|
internal class PoENinja
|
|
{
|
|
public static void SaveData(string url, string path)
|
|
{
|
|
WebClient webClient = new WebClient();
|
|
webClient.Encoding = Encoding.UTF8;
|
|
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
|
try
|
|
{
|
|
Uri address = new Uri(url);
|
|
string contents = webClient.DownloadString(address);
|
|
System.IO.File.AppendAllText(path, contents, Encoding.UTF8);
|
|
}
|
|
catch (WebException ex)
|
|
{
|
|
Utilities.Message.CMW(ex.Message, true, 3);
|
|
Utilities.Message.CMW("URL: " + url, true, 3);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utilities.Message.CMW(ex.Message, true, 3);
|
|
}
|
|
}
|
|
|
|
public static void GenCurrency()
|
|
{
|
|
DeleteCurrencies();
|
|
int curID = 1;
|
|
double divineValue = 0;
|
|
string cmdText = "";
|
|
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/currency.json", Encoding.UTF8));
|
|
foreach (var c in rcur.lines)
|
|
{
|
|
if (c.currencyTypeName == "Divine Orb") { divineValue = Convert.ToInt32(Math.Round(c.chaosEquivalent)); }
|
|
}
|
|
foreach (LineCurrency line in JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/currency.json", Encoding.UTF8)).lines)
|
|
{
|
|
string curType = line.currencyTypeName;
|
|
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
cmdText = $"INSERT INTO poeco_currency(curid,name,vchaos,vdivine) VALUES ('{curID}','{MySql.Data.MySqlClient.MySqlHelper.EscapeString(line.currencyTypeName)}','{Math.Round(line.chaosEquivalent,10)}','{Math.Round(line.chaosEquivalent / divineValue, 2, MidpointRounding.AwayFromZero)}')";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
curID++;
|
|
}
|
|
}
|
|
|
|
public static void GenDivination()
|
|
{
|
|
DeleteDivinations();
|
|
int divID = 1;
|
|
string cmdText = "";
|
|
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/divination.json", Encoding.UTF8));
|
|
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/divination.json", Encoding.UTF8)).lines)
|
|
{
|
|
string curType = line.name;
|
|
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
cmdText = $"INSERT INTO poeco_divination(divid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue,2)}','{line.divineValue}')";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
divID++;
|
|
}
|
|
}
|
|
|
|
public static void GenEssence()
|
|
{
|
|
DeleteEssences();
|
|
int divID = 1;
|
|
string cmdText = "";
|
|
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/essence.json", Encoding.UTF8));
|
|
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/essence.json", Encoding.UTF8)).lines)
|
|
{
|
|
string curType = line.name;
|
|
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
cmdText = $"INSERT INTO poeco_essence(essid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
divID++;
|
|
}
|
|
}
|
|
|
|
public static void GenFragment()
|
|
{
|
|
DeleteFragments();
|
|
int divID = 1;
|
|
string cmdText = "";
|
|
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/scarab.json", Encoding.UTF8));
|
|
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/scarab.json", Encoding.UTF8)).lines)
|
|
{
|
|
string curType = line.name;
|
|
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
cmdText = $"INSERT INTO poeco_fragment(fraid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
divID++;
|
|
}
|
|
}
|
|
|
|
public static void GenFossil()
|
|
{
|
|
DeleteFossils();
|
|
int divID = 1;
|
|
string cmdText = "";
|
|
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/fossil.json", Encoding.UTF8));
|
|
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/fossil.json", Encoding.UTF8)).lines)
|
|
{
|
|
string curType = line.name;
|
|
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
cmdText = $"INSERT INTO poeco_fossil(fosid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
divID++;
|
|
}
|
|
}
|
|
|
|
public static void DeleteCurrencies()
|
|
{
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
string cmdText = $"DELETE FROM poeco_currency";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
}
|
|
|
|
public static void DeleteDivinations()
|
|
{
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
string cmdText = $"DELETE FROM poeco_divination";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
}
|
|
|
|
public static void DeleteEssences()
|
|
{
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
string cmdText = $"DELETE FROM poeco_essence";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
}
|
|
|
|
public static void DeleteFragments()
|
|
{
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
string cmdText = $"DELETE FROM poeco_fragment";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
}
|
|
|
|
public static void DeleteFossils()
|
|
{
|
|
MySqlConnection con = DB.User.MxPoEDB();
|
|
string cmdText = $"DELETE FROM poeco_fossil";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
}
|
|
}
|
|
|
|
public class CurrencyDetail
|
|
{
|
|
public int id { get; set; }
|
|
public string icon { get; set; }
|
|
public string name { get; set; }
|
|
public string tradeId { get; set; }
|
|
}
|
|
|
|
public class LanguageCurrency
|
|
{
|
|
public string name { get; set; }
|
|
public TranslationsCurrency translations { get; set; }
|
|
}
|
|
|
|
public class LineCurrency
|
|
{
|
|
public string currencyTypeName { get; set; }
|
|
public Pay pay { get; set; }
|
|
public Receive receive { get; set; }
|
|
public double chaosEquivalent { get; set; }
|
|
public LowConfidencePaySparkLine lowConfidencePaySparkLine { get; set; }
|
|
public LowConfidenceReceiveSparkLine lowConfidenceReceiveSparkLine { get; set; }
|
|
public string detailsId { get; set; }
|
|
}
|
|
|
|
public class LowConfidencePaySparkLine
|
|
{
|
|
public List<object> data { get; set; }
|
|
public double totalChange { get; set; }
|
|
}
|
|
|
|
public class LowConfidenceReceiveSparkLine
|
|
{
|
|
public List<double?> data { get; set; }
|
|
public double totalChange { get; set; }
|
|
}
|
|
|
|
public class Pay
|
|
{
|
|
public int id { get; set; }
|
|
public int league_id { get; set; }
|
|
public int pay_currency_id { get; set; }
|
|
public int get_currency_id { get; set; }
|
|
public DateTime sample_time_utc { get; set; }
|
|
public int count { get; set; }
|
|
public double value { get; set; }
|
|
public int data_point_count { get; set; }
|
|
public bool includes_secondary { get; set; }
|
|
public int listing_count { get; set; }
|
|
}
|
|
|
|
public class PaySparkLine
|
|
{
|
|
public List<object> data { get; set; }
|
|
public double totalChange { get; set; }
|
|
}
|
|
|
|
public class Receive
|
|
{
|
|
public int id { get; set; }
|
|
public int league_id { get; set; }
|
|
public int pay_currency_id { get; set; }
|
|
public int get_currency_id { get; set; }
|
|
public DateTime sample_time_utc { get; set; }
|
|
public int count { get; set; }
|
|
public double value { get; set; }
|
|
public int data_point_count { get; set; }
|
|
public bool includes_secondary { get; set; }
|
|
public int listing_count { get; set; }
|
|
}
|
|
|
|
public class ReceiveSparkLine
|
|
{
|
|
public List<double> data { get; set; }
|
|
public double totalChange { get; set; }
|
|
}
|
|
|
|
public class RootCurrency
|
|
{
|
|
public List<LineCurrency> lines { get; set; }
|
|
public List<CurrencyDetail> currencyDetails { get; set; }
|
|
public LanguageCurrency language { get; set; }
|
|
}
|
|
|
|
public class TranslationsCurrency
|
|
{
|
|
}
|
|
}
|
|
|