MainWindow.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using GSG.NET.Logging;
  16. using OHVConnector;
  17. namespace OHVProtocolClient
  18. {
  19. /// <summary>
  20. /// MainWindow.xaml에 대한 상호 작용 논리
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. static Logger logger = Logger.GetLogger("Client");
  25. public MainWindow()
  26. {
  27. InitializeComponent();
  28. }
  29. private void Window_Loaded(object sender, RoutedEventArgs e)
  30. {
  31. string basePath = AppDomain.CurrentDomain.BaseDirectory;
  32. LogUtils.Configure(basePath + "/log4net.xml");
  33. var cn = new Manager();
  34. cn.Config = new Config() { ID = "V0001" };
  35. cn.Connect(true);
  36. cn.OnRecd += Cn_OnRecd;
  37. cn.OnContd += Cn_OnContd;
  38. cn.OnDiscontd += Cn_OnDiscontd;
  39. cn.OnLog += Cn_OnLog;
  40. cn.OnT3Timeout += Cn_OnT3Timeout;
  41. cn.OnSent += Cn_OnSent;
  42. }
  43. private void Cn_OnSent(OCSMessage msg)
  44. {
  45. logger.I("[Send] : " + msg.LogFormat());
  46. }
  47. private void Cn_OnT3Timeout(OCSMessage msg)
  48. {
  49. logger.E($"[T3TimeOut] - {msg.LogFormat()}");
  50. }
  51. private void Cn_OnLog(string id, string log)
  52. {
  53. logger.I(log);
  54. }
  55. private void Cn_OnDiscontd(string id, Exception e)
  56. {
  57. this.lblState.Background = Brushes.Gray;
  58. }
  59. private void Cn_OnContd(string id)
  60. {
  61. this.lblState.Background = Brushes.Green;
  62. }
  63. private void Cn_OnRecd(OCSMessage msg)
  64. {
  65. logger.I("[Received] : " + msg.LogFormat());
  66. }
  67. }
  68. }