ClientIdentity.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // -
  2. // <copyright file="ClientIdentity.cs" company="Microsoft Corporation">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // -
  6. namespace Microsoft.Hawaii
  7. {
  8. using System;
  9. using System.Text;
  10. /// <summary>
  11. /// ClientIdentity represents a client identity for the purposes of communicating with the server.
  12. /// </summary>
  13. public abstract class ClientIdentity
  14. {
  15. /// <summary>
  16. /// Initializes a new instance of the ClientIdentity class.
  17. /// </summary>
  18. public ClientIdentity() :
  19. this(string.Empty, string.Empty)
  20. {
  21. }
  22. /// <summary>
  23. /// Initializes a new instance of the ClientIdentity class.
  24. /// </summary>
  25. /// <param name="registrationId">Specifies a registration id.</param>
  26. /// <param name="secretKey">Specifies a secret key.</param>
  27. public ClientIdentity(string registrationId, string secretKey)
  28. {
  29. this.RegistrationId = registrationId;
  30. this.SecretKey = secretKey;
  31. }
  32. /// <summary>
  33. /// The delegate of RetriveAccessTokenEvent event.
  34. /// </summary>
  35. /// <param name="accessToken">The access token string.</param>
  36. /// <param name="ex">Coressponding exception if failed to get the access token.</param>
  37. public delegate void RetriveAccessTokenComplete(string accessToken, Exception ex);
  38. /// <summary>
  39. /// Gets or sets the registration id.
  40. /// </summary>
  41. public string RegistrationId { get; set; }
  42. /// <summary>
  43. /// Gets or sets the secret key.
  44. /// </summary>
  45. public string SecretKey { get; set; }
  46. /// <summary>
  47. /// Gets the identity token that is used when communicating with the server.
  48. /// </summary>
  49. /// <param name="callback">callback from event</param>
  50. public abstract void RetriveAccessToken(RetriveAccessTokenComplete callback);
  51. /// <summary>
  52. /// Derived class provides implementation.
  53. /// </summary>
  54. /// <returns>Returns the client identity</returns>
  55. public abstract ClientIdentity Copy();
  56. /// <summary>
  57. /// Helper method to fire the RetriveAccessTokenCompleteEvent event.
  58. /// </summary>
  59. /// <param name="accessToken">The accesss token string</param>
  60. /// <param name="ex">Coressponding exception if failed to get the access token.</param>
  61. /// <param name="callback">callback from event</param>
  62. protected virtual void OnRetriveAccessTokenComplete(string accessToken, Exception ex, RetriveAccessTokenComplete callback)
  63. {
  64. callback(accessToken, ex);
  65. }
  66. }
  67. }