TelemetryHelper.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //using Newtonsoft.Json;
  2. //using System;
  3. //using System.Net.Http;
  4. //using System.Net.Http.Headers;
  5. //using System.Text;
  6. //using System.Threading.Tasks;
  7. //namespace Optimizer
  8. //{
  9. // internal static class TelemetryHelper
  10. // {
  11. // const string GEO_LOOKUP_URL = "http://ip-api.com/json/";
  12. // static TelemetryData telemetryEntry = new TelemetryData();
  13. // internal static HttpClient TelemetryClient;
  14. // internal const string TELEMETRY_API_URL = "";
  15. // internal const string TELEMETRY_KEY = @"{OPTIMIZER-0EFC7B8A-D1FC-467F-B4B1-0117C643FE19-TELEMETRY}";
  16. // internal static async void EnableTelemetryService()
  17. // {
  18. // TelemetryClient = new HttpClient();
  19. // TelemetryClient.BaseAddress = new Uri(TELEMETRY_API_URL);
  20. // TelemetryClient.DefaultRequestHeaders.Add("Optimizertelemetrykey", TELEMETRY_KEY);
  21. // TelemetryClient.DefaultRequestHeaders
  22. // .Accept
  23. // .Add(new MediaTypeWithQualityHeaderValue("application/json"));
  24. // await CacheTelemetryData();
  25. // }
  26. // internal static async Task<string> GetSessionCountry()
  27. // {
  28. // try
  29. // {
  30. // string result = await TelemetryClient.GetStringAsync(GEO_LOOKUP_URL);
  31. // GeoLookupResult x = JsonConvert.DeserializeObject<GeoLookupResult>(result);
  32. // if (x.status == "success")
  33. // {
  34. // return x.country;
  35. // }
  36. // else
  37. // {
  38. // return "Unknown";
  39. // }
  40. // }
  41. // catch
  42. // {
  43. // return "Unknown";
  44. // }
  45. // }
  46. // internal static async Task CacheTelemetryData()
  47. // {
  48. // telemetryEntry.Country = await GetSessionCountry();
  49. // telemetryEntry.WindowsVersion = Utilities.GetWindowsDetails();
  50. // telemetryEntry.DotNetVersion = Utilities.GetNETFramework();
  51. // telemetryEntry.OptimizerVersion = Program.GetCurrentVersionTostring();
  52. // telemetryEntry.UnsafeMode = Program.UNSAFE_MODE.ToString();
  53. // telemetryEntry.ExperimentalBuild = Program.EXPERIMENTAL_BUILD.ToString();
  54. // telemetryEntry.TelemetryID = Options.CurrentOptions.TelemetryClientID;
  55. // }
  56. // internal static void GenerateTelemetryData(string functionName, string errorMessage, string errorStackTrace)
  57. // {
  58. // telemetryEntry.Timestamp = string.Format("{0:yyyy-MM-ddTHH:mm:ss.FFFZ}", DateTime.UtcNow);
  59. // telemetryEntry.LanguageCode = Enum.GetName(typeof(LanguageCode), Options.CurrentOptions.LanguageCode);
  60. // telemetryEntry.SavedOptions = JsonConvert.SerializeObject(Options.CurrentOptions, Formatting.Indented);
  61. // telemetryEntry.FunctionName = functionName;
  62. // telemetryEntry.ErrorMessage = errorMessage;
  63. // telemetryEntry.StackTrace = errorStackTrace;
  64. // SendTelemetryData(telemetryEntry);
  65. // }
  66. // internal static void SendTelemetryData(TelemetryData entry)
  67. // {
  68. // try
  69. // {
  70. // StringContent bodyContent = new StringContent(JsonConvert.SerializeObject(telemetryEntry, Formatting.Indented), Encoding.UTF8, "application/json");
  71. // TelemetryClient.PostAsync(TelemetryClient.BaseAddress, bodyContent);
  72. // }
  73. // catch { }
  74. // }
  75. // }
  76. //}