Exemplo n.º 1
0
 //+------------------------------------------------------------------+
 //| Manager API shutdown                                             |
 //+------------------------------------------------------------------+
 void Shutdown()
 {
     //--- free request sink
     if (m_request_sink != null)
     {
         m_request_sink.Dispose();
         m_request_sink = null;
     }
     //--- free order sink
     if (m_order_sink != null)
     {
         m_order_sink.Dispose();
         m_order_sink = null;
     }
     //--- close answer event
     if (m_event_answer != null)
     {
         m_event_answer.Close();
         m_event_answer = null;
     }
     //--- close requests event
     if (m_event_request != null)
     {
         m_event_request.Close();
         m_event_request = null;
     }
     //--- release request objects
     if (m_request != null)
     {
         m_request.Dispose();
         m_request = null;
     }
     //--- release confirmation objects
     if (m_confirm != null)
     {
         m_confirm.Dispose();
         m_confirm = null;
     }
     //--- if manager interface was created
     if (m_manager != null)
     {
         //--- release manager interface
         m_manager.Dispose();
         m_manager = null;
     }
     //--- parent
     m_parent = null;
 }
Exemplo n.º 2
0
        //+------------------------------------------------------------------+
        //| 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);
        }