RealWorldTerrainTextWebServiceBase.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* INFINITY CODE 2013-2019 */
  2. /* http://www.infinity-code.com */
  3. using System;
  4. using InfinityCode.RealWorldTerrain.ExtraTypes;
  5. namespace InfinityCode.RealWorldTerrain.Webservices.Base
  6. {
  7. /// <summary>
  8. /// The base class for working with the web services returns text response.
  9. /// </summary>
  10. public abstract class RealWorldTerrainTextWebServiceBase : RealWorldTerrainWebServiceBase
  11. {
  12. /// <summary>
  13. /// Event that occurs when a response is received from webservice.
  14. /// </summary>
  15. public Action<string> OnComplete;
  16. protected string _response;
  17. /// <summary>
  18. /// Gets a response from webservice.
  19. /// </summary>
  20. /// <value>
  21. /// The response.
  22. /// </value>
  23. public string response
  24. {
  25. get { return _response; }
  26. }
  27. public override void Destroy()
  28. {
  29. if (OnDispose != null) OnDispose(this);
  30. www = null;
  31. _response = string.Empty;
  32. _status = RequestStatus.disposed;
  33. customData = null;
  34. OnComplete = null;
  35. OnFinish = null;
  36. }
  37. /// <summary>
  38. /// Checks whether the response from webservice.
  39. /// </summary>
  40. protected void OnRequestComplete(RealWorldTerrainWWW www)
  41. {
  42. if (www != null && www.isDone)
  43. {
  44. _status = string.IsNullOrEmpty(www.error) ? RequestStatus.success : RequestStatus.error;
  45. _response = _status == RequestStatus.success ? www.text : www.error;
  46. if (OnComplete != null) OnComplete(_response);
  47. if (OnFinish != null) OnFinish(this);
  48. _status = RequestStatus.disposed;
  49. _response = null;
  50. this.www = null;
  51. customData = null;
  52. }
  53. }
  54. }
  55. }