You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegistryStore.cs 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Win32;
  6. namespace ClickForensics.Quartz.Manager
  7. {
  8. public class RegistryStore
  9. {
  10. public static List<ConnectionInfo> GetLastConnections()
  11. {
  12. List<ConnectionInfo> lastConnections = new List<ConnectionInfo>();
  13. RegistryKey managerKey = Registry.CurrentUser.CreateSubKey("QuartzNetManager");
  14. RegistryKey key = null;
  15. if (managerKey == null)
  16. {
  17. return lastConnections;
  18. }
  19. key = managerKey.CreateSubKey("MRUList");
  20. if (key == null)
  21. {
  22. return lastConnections;
  23. }
  24. //TODO: show more than one server in dropdown
  25. for (int i = 0; i < 1; i++)
  26. {
  27. ConnectionInfo info = ConnectionInfo.Parse((key.GetValue(string.Format("connection{0}", i), null) as string));
  28. if (info != null)
  29. {
  30. lastConnections.Add(info);
  31. }
  32. }
  33. key.Close();
  34. managerKey.Close();
  35. return lastConnections;
  36. }
  37. public static void AddConnection(ConnectionInfo info)
  38. {
  39. RegistryKey managerKey = Registry.CurrentUser.CreateSubKey("QuartzNetManager");
  40. RegistryKey key = null;
  41. if (managerKey == null)
  42. {
  43. return;
  44. }
  45. key = managerKey.CreateSubKey("MRUList");
  46. if (key == null)
  47. {
  48. return;
  49. }
  50. //TODO: check that the key doesn't exist before trying to add. if it exists, move it to the top, but don't add it
  51. //for (int i = 4; i > 0; i--)
  52. //{
  53. // var previous = key.GetValue(string.Format("connection{0}", i - 1), null);
  54. // if (previous != null)
  55. // {
  56. // key.SetValue(string.Format("connection{0}", i), previous);
  57. // }
  58. //}
  59. key.SetValue("connection0", info, RegistryValueKind.String);
  60. }
  61. private static object lockObject = new object();
  62. }
  63. }