Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. namespace FF_AccessLib
  2. {
  3. public class FF_Properties
  4. {
  5. //Main Class Implimentation
  6. FF_Properties()
  7. {
  8. //if (!File.Exists("Settings.json"))
  9. // CreateFile();
  10. //LoadJson();
  11. Properties = new PropData();
  12. Properties.DB_Host = "127.0.0.1";
  13. Properties.DB_Port = "3311";
  14. Properties.DB_User = "root";
  15. Properties.DB_Password = "root";
  16. }
  17. private void CreateFile()
  18. {
  19. List<PropData> _data = new List<PropData>();
  20. _data.Add(new PropData()
  21. {
  22. DB_Host = "127.0.0.1",
  23. DB_Port = "3311",
  24. DB_User = "root",
  25. DB_Password = "root"
  26. });
  27. string json = JsonConvert.SerializeObject(_data.ToArray());
  28. System.IO.File.WriteAllText("../../../Settings.json", json);
  29. }
  30. private void LoadJson()
  31. {
  32. if (!File.Exists("../../../Settings.json"))
  33. CreateFile();
  34. using (StreamReader r = new StreamReader("../../../Settings.json"))
  35. {
  36. string json = r.ReadToEnd();
  37. List<PropData> items = JsonConvert.DeserializeObject<List<PropData>>(json);
  38. Properties = items[0];
  39. }
  40. }
  41. private PropData Properties { get; set; }
  42.  
  43. //Class Data
  44. public class PropData
  45. {
  46. public string DB_Host { get; set; }
  47. public string DB_Port { get; set; }
  48. public string DB_User { get; set; }
  49. public string DB_Password { get; set; }
  50. }
  51.  
  52. //Singleton Functions
  53. private static FF_Properties instance;
  54. public static string Get(string propName)
  55. {
  56. if (instance == null)
  57. {
  58. instance = new FF_Properties();
  59. }
  60. string temp = "";
  61. try
  62. {
  63. temp = (string)instance.Properties.GetType().GetProperty(propName).GetValue(instance.Properties);
  64. }
  65. catch { }
  66. return temp;
  67. }
  68.  
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement