G.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.IO;
  5. namespace Server
  6. {
  7. class G
  8. {
  9. public static NLog.Logger logger = null;
  10. static public uint Random()
  11. {
  12. byte[] buff = Guid.NewGuid().ToByteArray();
  13. int size = buff.Length;
  14. return System.BitConverter.ToUInt32(buff, size - 8);
  15. }
  16. static void Main()
  17. {
  18. long d = DateTime.Now.Ticks;
  19. Console.WriteLine(d);
  20. d = DateTime.Now.AddDays(-1).Ticks;
  21. Console.WriteLine(d);
  22. JObject a = new JObject();
  23. a["last"] = d;
  24. File.WriteAllText("d:\\test.json", a.ToString());
  25. JObject b = JObject.Parse(File.ReadAllText("d:\\test.json"));
  26. Console.WriteLine(b["last"].Value<long>());
  27. Console.ReadLine();
  28. }
  29. public static Settings settings;
  30. static G()
  31. {
  32. try
  33. {
  34. string text = File.ReadAllText("init-cs.json");
  35. G.settings = JsonConvert.DeserializeObject<Settings>(text);
  36. }
  37. catch
  38. {
  39. G.settings = new Settings();
  40. }
  41. var appBasePath = System.IO.Directory.GetCurrentDirectory();
  42. NLog.GlobalDiagnosticsContext.Set("basedir", appBasePath);
  43. logger = NLog.LogManager.GetLogger("G");
  44. }
  45. }
  46. public class Settings
  47. {
  48. public ushort Port;
  49. public string ServerID, ServerName, MessageIP;
  50. public ushort MessagePort;
  51. public string DBURL;
  52. }
  53. }