コード例 #1
0
        /// <summary>
        /// Inicializar COMOS para usar banco de dados definido pela conectionstring.
        /// !!! Este methodo se comporta static
        /// </summary>
        /// <param name="connectionstring"></param>
        /// <returns>True é o sucesso, false caso contrário.</returns>
        public bool Open(string connectionstring)
        {
            try
            {
                Console.WriteLine("COMOS.IO Opening : " + connectionstring);
                Log.WriteLog("COMOS.IO Opening : " + connectionstring, System.Diagnostics.EventLogEntryType.Information);

                if (m_ComosSession != null)
                {
                    return(false);
                }
                m_ComosSession = new ComosSession();
                Log.WriteLog("Session Created. Will Call Open in Comos IO", System.Diagnostics.EventLogEntryType.Information);

                if (!m_ComosSession.Open(connectionstring))
                {
                    Console.WriteLine("Invalid <connection string> or <no license> argument: " + connectionstring);
                    Log.WriteLog("Invalid <connection string> or <no license> argument: " + connectionstring, System.Diagnostics.EventLogEntryType.Error);
                    return(false);
                }
                else
                {
                    Log.WriteLog("Success opening COMOS DB:" + connectionstring, System.Diagnostics.EventLogEntryType.Information);
                    m_ComosSession.ReleaseCOMOSObjects();
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog("Exception opening COMOS DB:" + ex.Message, System.Diagnostics.EventLogEntryType.Error);
                //ComosBRWeb.LogHandler.WriteLog(ex.Message + ":Open");
                System.Diagnostics.Debug.Assert(false);
            }
            return(true);
        }
コード例 #2
0
 /// <summary>
 /// Fechar sessão COMOS
 /// </summary>
 /// <param name="doexit">Terminar applicação sim=true/não=false</param>
 public bool Close(bool doexit)
 {
     try
     {
         Log.WriteLog("Closing service and exit app = {0}", doexit);
         if (m_ComosSession == null)
         {
             return(false);
         }
         m_ComosSession.Close();
         m_ComosSession = null;
         if (doexit)
         {
             // Can not imediatky exit as it would close also the service host.
             // We need to delay it.
             //System.Windows.Forms.Application.Exit();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Log.WriteLog(ex.Message + ":Close", System.Diagnostics.EventLogEntryType.Warning);
         System.Diagnostics.Debug.Assert(false);
     }
     return(false);
 }