LiveContainerCommunication.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Controls;
  7. namespace HistoryDLL
  8. {
  9. /// <summary>
  10. /// LiveContainer 事件傳遞與通訊
  11. /// </summary>
  12. public partial class LiveContainer : UserControl
  13. {
  14. //外掛 Delegate event for communicate with CyclicScroller (通知用)
  15. public delegate void LiveContainerBubbleToCyclicScroller(string ProcessCode, int index, int indexofevent, int indexofpic);
  16. public event LiveContainerBubbleToCyclicScroller LiveContainerBubbleToCyclicScrollerEvent;
  17. //外掛 Delegate event for communicate with PlaneRotateMap (通知用)
  18. public delegate void LiveContainerBubbleToPlaneRotateMap(string ProcessCode, int blockIndex);
  19. public event LiveContainerBubbleToPlaneRotateMap LiveContainerBubbleToPlaneRotateEvent;
  20. //通知各 CyclicScroller 函數
  21. private void SendInfoToCyclicScroller(string ProcessCode)
  22. {
  23. if (ProcessCode == "Load Complete")
  24. {
  25. this.Dispatcher.BeginInvoke(LiveContainerBubbleToCyclicScrollerEvent, ProcessCode, ContainerIndex, TriggerEvent, TriggerPicture);
  26. }
  27. else if (this.canControl)
  28. {
  29. this.Dispatcher.BeginInvoke(LiveContainerBubbleToCyclicScrollerEvent, ProcessCode, ContainerIndex, TriggerEvent, TriggerPicture);
  30. }
  31. }
  32. //接收到~來自 CyclicScroller 的通知
  33. void ReceiveFromCyclicScroller(string ProcessCode)
  34. {
  35. if (ProcessCode == "AutoRun")
  36. {
  37. for (int i = 0; i < MainUpSideGrid.Children.Count; i++)
  38. {
  39. ((PlaneRotateMap)MainUpSideGrid.Children[i]).StartCountDownForRatate();
  40. }
  41. }
  42. else if (ProcessCode == "Manual")
  43. {
  44. for (int i = 0; i < MainUpSideGrid.Children.Count; i++)
  45. {
  46. ((PlaneRotateMap)MainUpSideGrid.Children[i]).StopCountDownForRatate();
  47. }
  48. }
  49. TriggerEvent = 0;
  50. }
  51. //接收來自 PlaneRotateMap 通知的通道(確認可顯示的資料是否已經到底)
  52. void ReceiveFromPlaneRotateFileBlankInfo(string ProcessCode, int BlockIndex)
  53. {
  54. if (ProcessCode == "DataEnd")
  55. {
  56. #region 資料到底處理
  57. //被通知到有資料到底後先判斷 buffer 中有沒有可以替換的資料
  58. if (PlaneRotateMapList.Count <= 0)
  59. {
  60. //Buffer 中沒有其他資料~通知繼續循環
  61. this.Dispatcher.BeginInvoke(LiveContainerBubbleToPlaneRotateEvent, "Cycle", BlockIndex);
  62. }
  63. else
  64. {
  65. //有~則通知改變
  66. this.Dispatcher.BeginInvoke(LiveContainerBubbleToPlaneRotateEvent, "Change", BlockIndex);
  67. }
  68. #endregion
  69. }
  70. else if (ProcessCode == "Prepare")
  71. {
  72. int row = 0, column = 0;
  73. //從Buffer中亂數取得要顯示的資料更換
  74. PlaneRotateMap newprm = new PlaneRotateMap();
  75. PlaneRotateMap oldprm = new PlaneRotateMap();
  76. GetRowAndCol(BlockIndex, ref row, ref column);
  77. //從Grid中抽出舊的 prm 處理
  78. oldprm = (PlaneRotateMap)MainUpSideGrid.Children[BlockIndex];
  79. oldprm.BlockIndex = -1;
  80. oldprm.StopCountDownForRatate();
  81. //亂數取得要放入的 PlaneRotateMap (不重複)
  82. int rndIndex = rnd.Next(0, PlaneRotateMapList.Count);
  83. //抽出該PlaneRotateMap 並做設定~完後指到 newprm
  84. newprm = SelectprmToShow(rndIndex, BlockIndex);
  85. MainUpSideGrid.Children.RemoveAt(BlockIndex);
  86. MainUpSideGrid.Children.Insert(BlockIndex, newprm);
  87. newprm.StartCountDownForRatate();
  88. //放入指定的位置
  89. Grid.SetRow(PlaneRotateMapList[rndIndex], row);
  90. Grid.SetColumn(PlaneRotateMapList[rndIndex], column);
  91. //移除該prm在亂數選擇的Buffer當中 (該 Buffer 只存在沒有顯示的事件)
  92. PlaneRotateMapList.RemoveAt(rndIndex);
  93. oldprm.StopCountDownForRatate();
  94. PlaneRotateMapList.Add(oldprm);
  95. //變換資料完成
  96. this.Dispatcher.BeginInvoke(LiveContainerBubbleToPlaneRotateEvent, "Finish", BlockIndex);
  97. }
  98. else if (ProcessCode == "Load Complete")
  99. {
  100. SendInfoToCyclicScroller(ProcessCode);
  101. }
  102. }
  103. private void GetRowAndCol(int source, ref int row, ref int column)
  104. {
  105. switch (source)
  106. {
  107. case 0:
  108. {
  109. row = 5;
  110. column = 1;
  111. break;
  112. }
  113. case 1:
  114. {
  115. row = 5;
  116. column = 3;
  117. break;
  118. }
  119. case 2:
  120. {
  121. row = 3;
  122. column = 1;
  123. break;
  124. }
  125. case 3:
  126. {
  127. row = 3;
  128. column = 3;
  129. break;
  130. }
  131. case 4:
  132. {
  133. row = 1;
  134. column = 1;
  135. break;
  136. }
  137. case 5:
  138. {
  139. row = 1;
  140. column = 3;
  141. break;
  142. }
  143. }
  144. }
  145. }
  146. }