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. for (int i = 0; i < 5; i++)
  25. {
  26. ConnectionInfo info = ConnectionInfo.Parse((key.GetValue(string.Format("connection{0}", i), null) as string));
  27. if (info != null)
  28. {
  29. lastConnections.Add(info);
  30. }
  31. }
  32. key.Close();
  33. managerKey.Close();
  34. return lastConnections;
  35. }
  36. public static void AddConnection(ConnectionInfo info)
  37. {
  38. RegistryKey managerKey = Registry.CurrentUser.CreateSubKey("QuartzNetManager");
  39. RegistryKey key = null;
  40. if (managerKey == null)
  41. {
  42. return;
  43. }
  44. key = managerKey.CreateSubKey("MRUList");
  45. if (key == null)
  46. {
  47. return;
  48. }
  49. //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
  50. //for (int i = 4; i > 0; i--)
  51. //{
  52. // var previous = key.GetValue(string.Format("connection{0}", i - 1), null);
  53. // if (previous != null)
  54. // {
  55. // key.SetValue(string.Format("connection{0}", i), previous);
  56. // }
  57. //}
  58. key.SetValue("connection0", info, RegistryValueKind.String);
  59. }
  60. private static object lockObject = new object();
  61. }
  62. }