using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using GSG.NET.Logging; using GSG.NET.Quartz; using OHVConnector; namespace OHVProtocolClient { /// /// MainWindow.xaml에 대한 상호 작용 논리 /// public partial class MainWindow : Window { static Logger logger = Logger.GetLogger("Client"); Manager manager = null; public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { string basePath = AppDomain.CurrentDomain.BaseDirectory; LogUtils.Configure(basePath + "/log4net.xml"); QuartzUtils.Init( 10 ); manager = new Manager(); manager.Config = new Config() {IpAddress="192.168.127.20", Port=5000, ID = "S0", HostID="V0002" }; manager.Connect(true); manager.OnRecd += Cn_OnRecd; manager.OnContd += Cn_OnContd; manager.OnDiscontd += Cn_OnDiscontd; manager.OnLog += Cn_OnLog; manager.OnT3Timeout += Cn_OnT3Timeout; manager.OnSent += Cn_OnSent; } private void Cn_OnSent(OCSMessage msg) { logger.I("[Send] : " + msg.LogFormat()); } private void Cn_OnT3Timeout(OCSMessage msg) { logger.E($"[T3TimeOut] - {msg.LogFormat()}"); } private void Cn_OnLog(string id, string log) { logger.I(log); } private void Cn_OnDiscontd(string id, Exception e) { this.lblState.Background = Brushes.Gray; QuartzUtils.StopSchedule( "Scode" ); } private void Cn_OnContd(string id) { this.lblState.Background = Brushes.Green; QuartzUtils.Invoke( "Scode", QuartzUtils.GetExpnMinute( 3 ), RequestScode ); RequestBcode(); } private void Cn_OnRecd(OCSMessage msg) { logger.I("[Received] : " + msg.LogFormat()); switch ( msg.Kind ) { case eKind.Unknown: break; case eKind.E: break; case eKind.S: case eKind.B: case eKind.H: case eKind.F: case eKind.I: case eKind.O: case eKind.P: case eKind.L: case eKind.U: ReplyMessage( msg ); break; case eKind.T: break; case eKind.C: break; case eKind.A: break; case eKind.M: break; case eKind.R: break; case eKind.Z: break; default: break; } } void ReplyMessage(OCSMessage msg ) { var reply = new OCSMessage(); reply.Kind = msg.Kind; reply.Tag = msg.Tag; reply.SubCode = msg.SubCode; this.manager.Reply( reply ); } void RequestScode() { var msg = new OCSMessage(); msg.Kind = eKind.R; msg.Tag = "0000"; msg.SubCode = "100"; this.manager.Send( msg ); } void RequestBcode() { var msg = new OCSMessage(); msg.Kind = eKind.R; msg.Tag = "0000"; msg.SubCode = "010"; this.manager.Send( msg ); } private void btnSend_Click( object sender, RoutedEventArgs e ) { var om = new OCSMessage(); om.Id = "S0"; om.Kind = eKind.A; //om.RevID = "V0001"; //om.SendID = om.Id; om.Tag = DateTime.Now.ToString( "mmss" ); om.SubCode = DateTime.Now.ToString( "fff" ); this.manager.Send( om ); } private void Button_Click( object sender, RoutedEventArgs e ) { OCSMessage meg = new OCSMessage(); meg.RevID = "V0001"; meg.SendID = "A0"; meg.Kind = (eKind)Enum.ToObject( typeof( eKind ), this.comboMessageKind.SelectedItem ); meg.Tag = this.txtTag.Text; meg.SubCode = this.txtSubCode.Text; this.manager.Send( meg ); } } }