ascnet/AscNet.Common/Common.cs

69 lines
2.5 KiB
C#
Raw Normal View History

2024-04-11 05:21:06 +00:00
using Config.Net;
2023-10-18 14:45:13 +00:00
using MongoDB.Driver;
2023-10-06 13:29:27 +00:00
namespace AscNet.Common
{
public static class Common
{
public static readonly IConfig config;
2023-10-18 08:49:36 +00:00
private static readonly MongoClient mongoClient;
2023-10-06 13:29:27 +00:00
public static readonly IMongoDatabase db;
static Common()
{
config = new ConfigurationBuilder<IConfig>().UseJsonFile("Configs/config.json").Build();
2023-10-19 07:07:48 +00:00
2023-10-06 13:29:27 +00:00
mongoClient = new(
new MongoClientSettings
{
Server = new MongoServerAddress(config.Database.Host, config.Database.Port),
// Credential = MongoCredential.CreateCredential("admin", config.Database.Username, config.Database.Password)
}
);
db = mongoClient.GetDatabase(config.Database.Name);
}
2023-10-18 14:45:13 +00:00
2024-04-11 05:21:06 +00:00
/*
2023-10-18 14:45:13 +00:00
public static void DumpTables()
{
IEnumerable<Type> tableTypes = Assembly.GetAssembly(typeof(Table.V2.client.activity.ActivityGroupTable))!.GetTypes().Where(t => typeof(ITable).IsAssignableFrom(t));
2023-10-18 14:45:13 +00:00
string baseSavePath = "/PGR_Data/";
Console.WriteLine($"Found {tableTypes.Count()} types!");
2023-10-18 14:45:13 +00:00
foreach (Type type in tableTypes)
{
try
{
object? values = typeof(TableReaderV2).GetMethod("Parse")?.MakeGenericMethod(type).Invoke(null, null);
2023-10-18 14:45:13 +00:00
if (values is not null)
{
// this will create the folder on ur drive root sorry
string savePath = baseSavePath + string.Join("/", type.FullName!.Split(".").Skip(3));
2023-10-18 14:45:13 +00:00
if (!Directory.Exists(Path.GetDirectoryName(savePath)))
Directory.CreateDirectory(Path.GetDirectoryName(savePath)!);
File.WriteAllText(new string(savePath.Take(savePath.Length - 5).ToArray()) + ".json", JsonConvert.SerializeObject(values, Formatting.Indented));
2023-10-18 14:45:13 +00:00
Console.WriteLine(type.FullName);
}
}
catch (Exception ex)
{
Console.WriteLine($"{type.FullName} failed!, {ex.Message}");
}
}
}
2024-04-11 05:21:06 +00:00
*/
2023-10-06 13:29:27 +00:00
}
2024-04-11 05:21:06 +00:00
public class ServerCodeException : Exception
{
public int Code { get; set; }
public ServerCodeException(string message, int code)
: base(message)
{
Code = code;
}
}
2023-10-06 13:29:27 +00:00
}