//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ public CIMTRequest RequestCreate() { if (m_manager == null) { return(null); } //--- return(m_manager.RequestCreate()); }
//+------------------------------------------------------------------+ //| Initialize library | //+------------------------------------------------------------------+ public bool Initialize(CDealerExampleDlg parent) { //--- string message = string.Empty; MTRetCode res = MTRetCode.MT_RET_OK_NONE; uint version = 0; //--- check if (parent == null) { return(false); } m_parent = parent; //--- try { //--- init CIMTManagerSink native link if ((res = RegisterSink()) != MTRetCode.MT_RET_OK) { message = string.Format("Register sink failed ({0})", res); MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- loading manager API if ((res = SMTManagerAPIFactory.Initialize(@"..\..\..\API\")) != MTRetCode.MT_RET_OK) { message = string.Format("Loading manager API failed ({0})", res); MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- check Manager API version if ((res = SMTManagerAPIFactory.GetVersion(out version)) != MTRetCode.MT_RET_OK) { message = string.Format("Dealer: getting version failed ({0})", res); MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (version != SMTManagerAPIFactory.ManagerAPIVersion) { message = string.Format("Dealer: wrong Manager API version, version {0} required", SMTManagerAPIFactory.ManagerAPIVersion); MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- create manager interface if ((m_manager = SMTManagerAPIFactory.CreateManager(SMTManagerAPIFactory.ManagerAPIVersion, out res)) == null || res != MTRetCode.MT_RET_OK) { message = string.Format("Dealer: creating manager interface failed ({0})", res); MessageBox.Show(message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- create request object if ((m_request = m_manager.RequestCreate()) == null) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request object failed"); MessageBox.Show("Dealer: creating request object failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- create confirmation object if ((m_confirm = m_manager.DealerConfirmCreate()) == null) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating confirmation object failed"); MessageBox.Show("Dealer: creating confirmation object failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- create requests event m_event_request = new EventWaitHandle(false, EventResetMode.ManualReset); //--- create requests event m_event_answer = new EventWaitHandle(false, EventResetMode.AutoReset); //--- m_request_sink = new CRequestSink(); if ((res = m_request_sink.Initialize(m_manager, m_event_request)) != MTRetCode.MT_RET_OK) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request sink failed"); MessageBox.Show("Dealer: creating request sink failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- m_order_sink = new COrderSink(); if ((res = m_order_sink.Initialize(m_manager)) != MTRetCode.MT_RET_OK) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request sink failed"); MessageBox.Show("Dealer: creating request sink failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //--- done return(true); } catch (Exception ex) { if (m_manager != null) { m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: initialization failed - {0}", ex.Message); } //--- MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } //--- done with errors return(false); }