Updater.Events.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using Update.Core.Events;
  2. namespace Update.Core
  3. {
  4. partial class Updater
  5. {
  6. //错误
  7. private static readonly object EVENT_ERROR = new object();
  8. /// <summary>
  9. /// 错误事件
  10. /// </summary>
  11. public event ErrorEventHandler Error
  12. {
  13. add
  14. {
  15. this.Events.AddHandler(EVENT_ERROR, value);
  16. }
  17. remove
  18. {
  19. this.Events.RemoveHandler(EVENT_ERROR, value);
  20. }
  21. }
  22. /// <summary>
  23. /// 触发错误事件
  24. /// </summary>
  25. /// <param name="e">数据</param>
  26. protected virtual void OnError(ErrorEventArgs e)
  27. {
  28. ErrorEventHandler handler = this.Events[EVENT_ERROR] as ErrorEventHandler;
  29. if (handler != null)
  30. handler(this, e);
  31. }
  32. //通知
  33. private static readonly object EVENT_NOTIFY = new object();
  34. /// <summary>
  35. /// 通知事件
  36. /// </summary>
  37. public event NotifyEventHandler Notify
  38. {
  39. add
  40. {
  41. this.Events.AddHandler(EVENT_NOTIFY, value);
  42. }
  43. remove
  44. {
  45. this.Events.RemoveHandler(EVENT_NOTIFY, value);
  46. }
  47. }
  48. /// <summary>
  49. /// 触发通知事件
  50. /// </summary>
  51. /// <param name="e">数据</param>
  52. protected virtual void OnNotify(NotifyEventArgs e)
  53. {
  54. NotifyEventHandler handler = this.Events[EVENT_NOTIFY] as NotifyEventHandler;
  55. if (handler != null)
  56. handler(this, e);
  57. }
  58. //进度
  59. private static readonly object EVENT_PROGRESS = new object();
  60. /// <summary>
  61. /// 进度事件
  62. /// </summary>
  63. public event ProgressEventHandler Progress
  64. {
  65. add
  66. {
  67. this.Events.AddHandler(EVENT_PROGRESS, value);
  68. }
  69. remove
  70. {
  71. this.Events.RemoveHandler(EVENT_PROGRESS, value);
  72. }
  73. }
  74. /// <summary>
  75. /// 触发进度事件
  76. /// </summary>
  77. /// <param name="e">数据</param>
  78. protected virtual void OnProgress(ProgressEventArgs e)
  79. {
  80. ProgressEventHandler handler = this.Events[EVENT_PROGRESS] as ProgressEventHandler;
  81. if (handler != null)
  82. handler(this, e);
  83. }
  84. //检查开始
  85. private static readonly object EVENT_CHECK_STARTED = new object();
  86. /// <summary>
  87. /// 开始检查
  88. /// </summary>
  89. public event CheckStartedEventHandler CheckStarted
  90. {
  91. add
  92. {
  93. this.Events.AddHandler(EVENT_CHECK_STARTED, value);
  94. }
  95. remove
  96. {
  97. this.Events.RemoveHandler(EVENT_CHECK_STARTED, value);
  98. }
  99. }
  100. /// <summary>
  101. /// 触发检查开始事件
  102. /// </summary>
  103. /// <param name="e">数据</param>
  104. protected virtual void OnCheckStarted(CheckStartedEventArgs e)
  105. {
  106. CheckStartedEventHandler handler = this.Events[EVENT_CHECK_STARTED] as CheckStartedEventHandler;
  107. if (handler != null)
  108. handler(this, e);
  109. }
  110. //检查完成
  111. private static readonly object EVENT_CHECK_COMPLETED = new object();
  112. /// <summary>
  113. /// 检查完成事件
  114. /// </summary>
  115. public event CheckCompletedEventHandler CheckCompleted
  116. {
  117. add
  118. {
  119. this.Events.AddHandler(EVENT_CHECK_COMPLETED, value);
  120. }
  121. remove
  122. {
  123. this.Events.RemoveHandler(EVENT_CHECK_COMPLETED, value);
  124. }
  125. }
  126. /// <summary>
  127. /// 触发检查完成事件
  128. /// </summary>
  129. /// <param name="e">数据</param>
  130. protected virtual void OnCheckCompleted(CheckCompletedEventArgs e)
  131. {
  132. CheckCompletedEventHandler handler = this.Events[EVENT_CHECK_COMPLETED] as CheckCompletedEventHandler;
  133. if (handler != null)
  134. handler(this, e);
  135. }
  136. //更新开始
  137. private static readonly object EVENT_UPDATE_STARTED = new object();
  138. /// <summary>
  139. /// 开始下载
  140. /// </summary>
  141. public event UpdateStartedEventHandler UpdateStarted
  142. {
  143. add
  144. {
  145. this.Events.AddHandler(EVENT_UPDATE_STARTED, value);
  146. }
  147. remove
  148. {
  149. this.Events.RemoveHandler(EVENT_UPDATE_STARTED, value);
  150. }
  151. }
  152. /// <summary>
  153. /// 触发更新开始事件
  154. /// </summary>
  155. /// <param name="e">数据</param>
  156. protected virtual void OnUpdateStarted(UpdateStartedEventArgs e)
  157. {
  158. UpdateStartedEventHandler handler = this.Events[EVENT_UPDATE_STARTED] as UpdateStartedEventHandler;
  159. if (handler != null)
  160. handler(this, e);
  161. }
  162. //更新完成
  163. private static readonly object EVENT_UPDATE_COMPLETED = new object();
  164. /// <summary>
  165. /// 更新完成事件
  166. /// </summary>
  167. public event UpdateCompletedEventHandler UpdateCompleted
  168. {
  169. add
  170. {
  171. this.Events.AddHandler(EVENT_UPDATE_COMPLETED, value);
  172. }
  173. remove
  174. {
  175. this.Events.RemoveHandler(EVENT_UPDATE_COMPLETED, value);
  176. }
  177. }
  178. /// <summary>
  179. /// 触发更新完成事件
  180. /// </summary>
  181. /// <param name="e">数据</param>
  182. protected virtual void OnUpdateCompleted(UpdateCompletedEventArgs e)
  183. {
  184. UpdateCompletedEventHandler handler = this.Events[EVENT_UPDATE_COMPLETED] as UpdateCompletedEventHandler;
  185. if (handler != null)
  186. handler(this, e);
  187. }
  188. }
  189. }