UEvent.xaml.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using SecsGem.Core;
  2. using SecsGem.Core.EnumData;
  3. using SecsGem.Core.Hsms;
  4. using SecsGem.Core.ItemModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace EapClientSimulator
  20. {
  21. /// <summary>
  22. /// UReport.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class UEvent : UserControl
  25. {
  26. public UEvent()
  27. {
  28. InitializeComponent();
  29. }
  30. public event EventHandler<string> OnSendMessage;
  31. private void EnableEvent(bool enable)
  32. {
  33. string[] strAry = txtCeId.Text.Split(';');
  34. SecsHsmsMessageHeader secsMessageHeader = new SecsHsmsMessageHeader()
  35. {
  36. Stream = 0x02,
  37. Function = 37,
  38. SType = SType.DataMessage,
  39. TransactionId = IdGenerator.GenerateTransactionId(),
  40. ReplyFlag = true,
  41. };
  42. Item item = new SecsGem.Core.ItemModel.ListItem();
  43. Item ceedItem = new BooleanItem(enable);
  44. item.AddItem(ceedItem);
  45. Item ceidsItem = new SecsGem.Core.ItemModel.ListItem();
  46. for(int i=0;i<strAry.Length;i++)
  47. {
  48. if (!string.IsNullOrEmpty(strAry[i]))
  49. {
  50. if (int.TryParse(strAry[i], out int ceidValue))
  51. {
  52. Item ceItem = new IntItem(ceidValue);
  53. ceidsItem.AddItem(ceItem);
  54. }
  55. else
  56. {
  57. return;
  58. }
  59. }
  60. }
  61. item.AddItem(ceidsItem);
  62. SecsMessage secsMessage = new SecsMessage(secsMessageHeader, item);
  63. if(GlobalData.Client!=null)
  64. {
  65. GlobalData.Client.SendMessage(secsMessage);
  66. if (OnSendMessage != null)
  67. {
  68. OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
  69. }
  70. }
  71. }
  72. private void btnEnable_Click(object sender, RoutedEventArgs e)
  73. {
  74. EnableEvent(true);
  75. }
  76. private void btnDisEnable_Click(object sender, RoutedEventArgs e)
  77. {
  78. EnableEvent(false);
  79. }
  80. }
  81. }