StatisticsTask.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Reflection;
  2. using MediaBrowser.Common.Configuration;
  3. using MediaBrowser.Common.Net;
  4. using MediaBrowser.Common.ScheduledTasks;
  5. using MediaBrowser.Model.Logging;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
  11. {
  12. /// <summary>
  13. /// Class ReloadLoggerFileTask
  14. /// </summary>
  15. public class StatisticsTask : IScheduledTask, IConfigurableScheduledTask
  16. {
  17. /// <summary>
  18. /// Gets or sets the log manager.
  19. /// </summary>
  20. /// <value>The log manager.</value>
  21. private ILogManager LogManager { get; set; }
  22. /// <summary>
  23. /// Gets or sets the app host
  24. /// </summary>
  25. /// <value>The application host.</value>
  26. private IApplicationHost ApplicationHost { get; set; }
  27. /// <summary>
  28. /// The network manager
  29. /// </summary>
  30. private INetworkManager NetworkManager { get; set; }
  31. /// <summary>
  32. /// The http client
  33. /// </summary>
  34. private IHttpClient HttpClient { get; set; }
  35. /// <summary>
  36. /// Initializes a new instance of the <see cref="ReloadLoggerFileTask" /> class.
  37. /// </summary>
  38. /// <param name="logManager">The logManager.</param>
  39. /// <param name="appHost"></param>
  40. /// <param name="httpClient"></param>
  41. public StatisticsTask(ILogManager logManager, IApplicationHost appHost, INetworkManager networkManager, IHttpClient httpClient)
  42. {
  43. LogManager = logManager;
  44. ApplicationHost = appHost;
  45. NetworkManager = networkManager;
  46. HttpClient = httpClient;
  47. }
  48. /// <summary>
  49. /// Gets the default triggers.
  50. /// </summary>
  51. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  52. public IEnumerable<ITaskTrigger> GetDefaultTriggers()
  53. {
  54. var trigger = new DailyTrigger { TimeOfDay = TimeSpan.FromHours(20) }; //8pm - when the system is most likely to be active
  55. var trigger2 = new StartupTrigger(); //and also at system start
  56. return new ITaskTrigger[] { trigger, trigger2 };
  57. }
  58. /// <summary>
  59. /// Executes the internal.
  60. /// </summary>
  61. /// <param name="cancellationToken">The cancellation token.</param>
  62. /// <param name="progress">The progress.</param>
  63. /// <returns>Task.</returns>
  64. public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  65. {
  66. cancellationToken.ThrowIfCancellationRequested();
  67. progress.Report(0);
  68. var mac = NetworkManager.GetMacAddress();
  69. var data = new Dictionary<string, string> { { "feature", ApplicationHost.Name }, { "mac", mac }, { "ver", ApplicationHost.ApplicationVersion.ToString() }, { "platform", Environment.OSVersion.VersionString } };
  70. await HttpClient.Post(Constants.Constants.MbAdminUrl + "service/registration/ping", data, CancellationToken.None).ConfigureAwait(false);
  71. progress.Report(100);
  72. }
  73. /// <summary>
  74. /// Gets the name.
  75. /// </summary>
  76. /// <value>The name.</value>
  77. public string Name
  78. {
  79. get { return "Collect stats"; }
  80. }
  81. /// <summary>
  82. /// Gets the description.
  83. /// </summary>
  84. /// <value>The description.</value>
  85. public string Description
  86. {
  87. get { return "Pings the admin site just so we know how many folks are out there and what version they are on."; }
  88. }
  89. /// <summary>
  90. /// Gets the category.
  91. /// </summary>
  92. /// <value>The category.</value>
  93. public string Category
  94. {
  95. get { return "Application"; }
  96. }
  97. public bool IsHidden
  98. {
  99. get { return true; }
  100. }
  101. public bool IsEnabled
  102. {
  103. get { return true; }
  104. }
  105. }
  106. }