Пример #1
0
 void Shutdown()
 {
     //--- free request sink
     if (_dealSink != null)
     {
         _dealSink.Dispose();
         _dealSink = 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;
     }
 }
Пример #2
0
        public bool Initialize()
        {
            //---
            string    message = string.Empty;
            MTRetCode res     = MTRetCode.MT_RET_OK_NONE;
            uint      version = 0;

            //---
            try
            {
                //--- init CIMTManagerSink native link
                if ((res = RegisterSink()) != MTRetCode.MT_RET_OK)
                {
                    message = string.Format("Register sink failed ({0})", res);
                    return(false);
                }
                //--- loading manager API
                if ((res = SMTManagerAPIFactory.Initialize(@"..\..\..\..\..\..\..\lib\")) != MTRetCode.MT_RET_OK)
                {
                    message = string.Format("Loading manager API failed ({0})", res);
                    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);
                    return(false);
                }
                if (version != SMTManagerAPIFactory.ManagerAPIVersion)
                {
                    message = string.Format("Dealer: wrong Manager API version, version {0} required", SMTManagerAPIFactory.ManagerAPIVersion);
                    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);
                    return(false);
                }
                //--- create request object
                if ((m_request = m_manager.RequestCreate()) == null)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request object failed");
                    return(false);
                }
                //--- create confirmation object
                if ((m_confirm = m_manager.DealerConfirmCreate()) == null)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating confirmation object failed");
                    return(false);
                }
                //--- create requests event
                m_event_request = new EventWaitHandle(false, EventResetMode.ManualReset);
                //--- create requests event
                m_event_answer = new EventWaitHandle(false, EventResetMode.AutoReset);
                //---
                _dealSink = new DealSink();
                if ((res = _dealSink.Initialize()) != MTRetCode.MT_RET_OK)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: creating request sink failed");
                    return(false);
                }
                //--- done
                return(true);
            }
            catch (Exception ex)
            {
                if (m_manager != null)
                {
                    m_manager.LoggerOut(EnMTLogCode.MTLogErr, "Dealer: initialization failed - {0}", ex.Message);
                }
            }
            //--- done with errors
            return(false);
        }