BugReportApiService.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. namespace SRDebugger.Services.Implementation
  2. {
  3. using System;
  4. using Internal;
  5. using SRF.Service;
  6. using UnityEngine;
  7. [Service(typeof (IBugReportService))]
  8. class BugReportApiService : IBugReportService
  9. {
  10. private IBugReporterHandler _handler = new InternalBugReporterHandler();
  11. public bool IsUsable
  12. {
  13. get
  14. {
  15. return _handler != null && _handler.IsUsable;
  16. }
  17. }
  18. public void SetHandler(IBugReporterHandler handler)
  19. {
  20. Debug.LogFormat("[SRDebugger] Bug Report handler set to {0}", handler);
  21. _handler = handler;
  22. }
  23. public void SendBugReport(BugReport report, BugReportCompleteCallback completeHandler,
  24. IProgress<float> progress = null)
  25. {
  26. if (_handler == null)
  27. {
  28. throw new InvalidOperationException("No bug report handler has been configured.");
  29. }
  30. if (!_handler.IsUsable)
  31. {
  32. throw new InvalidOperationException("Bug report handler is not usable.");
  33. }
  34. if (report == null)
  35. {
  36. throw new ArgumentNullException("report");
  37. }
  38. if (completeHandler == null)
  39. {
  40. throw new ArgumentNullException("completeHandler");
  41. }
  42. if (Application.internetReachability == NetworkReachability.NotReachable)
  43. {
  44. completeHandler(false, "No Internet Connection");
  45. return;
  46. }
  47. _handler.Submit(report, result => completeHandler(result.IsSuccessful, result.ErrorMessage), progress);
  48. }
  49. }
  50. }