StatisticsTask.cs 4.1 KB

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