ISystemInformationService.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. namespace SRDebugger
  2. {
  3. using System;
  4. using Services;
  5. using SRF;
  6. public sealed class InfoEntry
  7. {
  8. public string Title { get; set; }
  9. public object Value
  10. {
  11. get
  12. {
  13. try
  14. {
  15. return _valueGetter();
  16. }
  17. catch (Exception e)
  18. {
  19. return "Error ({0})".Fmt(e.GetType().Name);
  20. }
  21. }
  22. }
  23. public bool IsPrivate { get; private set; }
  24. private Func<object> _valueGetter;
  25. /// <summary>
  26. /// Create an <see cref="InfoEntry"/> instance with a getter function for the value.
  27. /// </summary>
  28. /// <param name="name">Name to display to the user.</param>
  29. /// <param name="getter">Getter method to acquire the latest value.</param>
  30. /// <param name="isPrivate">If true, will be excluded from the bug reporter system.</param>
  31. /// <returns>The created <see cref="InfoEntry"/> object.</returns>
  32. public static InfoEntry Create(string name, Func<object> getter, bool isPrivate = false)
  33. {
  34. return new InfoEntry
  35. {
  36. Title = name,
  37. _valueGetter = getter,
  38. IsPrivate = isPrivate
  39. };
  40. }
  41. /// <summary>
  42. /// Create an <see cref="InfoEntry"/> instance with a fixed value.
  43. /// </summary>
  44. /// <param name="name">Name to display to the user.</param>
  45. /// <param name="value">The value of the entry.</param>
  46. /// <param name="isPrivate">If true, will be excluded from the bug reporter system.</param>
  47. /// <returns>The created <see cref="InfoEntry"/> object.</returns>
  48. public static InfoEntry Create(string name, object value, bool isPrivate = false)
  49. {
  50. return new InfoEntry
  51. {
  52. Title = name,
  53. _valueGetter = () => value,
  54. IsPrivate = isPrivate
  55. };
  56. }
  57. }
  58. }
  59. namespace SRDebugger.Services
  60. {
  61. using System.Collections.Generic;
  62. public interface ISystemInformationService
  63. {
  64. /// <summary>
  65. /// Get an IEnumerable with the available data categories for this system
  66. /// </summary>
  67. IEnumerable<string> GetCategories();
  68. /// <summary>
  69. /// Get a list of information for a category
  70. /// </summary>
  71. /// <param name="category">Category name to fetch (get a list of these from GetCategories())</param>
  72. /// <returns></returns>
  73. IList<InfoEntry> GetInfo(string category);
  74. /// <summary>
  75. /// Add a piece of system information.
  76. /// </summary>
  77. /// <param name="category"></param>
  78. /// <param name="info"></param>
  79. void Add(InfoEntry info, string category = "Default");
  80. /// <summary>
  81. /// Generate a report from all available system data (useful for sending with bug reports)
  82. /// </summary>
  83. /// <param name="includePrivate">Set to true to include identifying private information (usually you don't want this)</param>
  84. /// <returns>The generated report</returns>
  85. Dictionary<string, Dictionary<string, object>> CreateReport(bool includePrivate = false);
  86. }
  87. }