Пример #1
0
        static void Main(string[] args)
        {
            Server.cfg = new ConfigurationReader();

            // Check for log directory
            DirectoryInfo dinfo = new DirectoryInfo(Server.cfg.LOG_DIRECTORY);
            if (!dinfo.Exists)
            {
                dinfo.Create();
            }
            dinfo = null;

            Server.shared = new SharedState();
            Server.logger = new FileLogger();

            foreach (string arg in args)
            {
                if (arg.ToLower().Equals("--help"))
                {
                    string usage = "\n";
                    usage       += "Usage:\n";
                    usage       += "-----------------------------------------------------------------\n";
                    usage       += "AstCtiServer.exe [--debug] [--dumpconfig]\n";
                    usage       += "-----------------------------------------------------------------\n";
                    usage       += "--debug      : enables extensive debug on console                \n";
                    usage       += "--dumpconfig : enables dump of main asterisk configuration       \n";
                    usage       += "               (extensions.conf, sip.conf and queues.conf) files \n";
                    Console.WriteLine(usage);
                    return;
                }
                if (arg.ToLower().Equals("--debug"))
                {
                    Server.debug = true;
                }

                if (arg.ToLower().Equals("--dumpconfig"))
                {
                    Server.dumpconf = true;
                }

            }

            Server.logger.WriteLine(LogType.Info, "Testing database connection");
            try
            {
                Server.logger.WriteLine(LogType.Debug, "Connecting to database on: " + cfg.MYSQL_HOST);
                Server.cn = new MySqlConnection(cfg.MYSQL_CONNSTR);
                Server.cn.Open();

                Server.MySqlVersion = (string)MySqlHelper.ExecuteScalar(Server.cn, "SELECT VERSION()");
                Server.MySqlWaitTime= GetWaitTimeout();

                // La connessione al database è ok
                Server.logger.WriteLine(LogType.Debug, "Database connection successful");
                if (Server.debug) Console.WriteLine("Database connection successful");

                Server.logger.WriteLine(LogType.Debug, "Database version: " + Server.MySqlVersion);
                if (Server.debug) Console.WriteLine("Database version: " + Server.MySqlVersion);

                Server.logger.WriteLine(LogType.Debug, "Wait timeout is: " + Server.MySqlWaitTime.ToString());
                if (Server.debug) Console.WriteLine("Wait timeout is: " + Server.MySqlWaitTime.ToString());

                Server.logger.WriteLine(LogType.Debug, "Server can start");

            }
            catch (Exception ex)
            {
                // Il test non è riuscito. Chiudiamo il programma
                if (Server.debug) Console.WriteLine(ex.ToString());
                Server.logger.WriteLine(LogType.Error, "Database connection is not avaiable. Exiting");
                Environment.Exit(0);
            }

            Server.logger.WriteLine(LogType.Notice, "Starting MainServer");
            AstCTI = new MainServer();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Server.cfg = new ConfigurationReader();

            // Check for log directory
            DirectoryInfo dinfo = new DirectoryInfo(Server.cfg.LOG_DIRECTORY);

            if (!dinfo.Exists)
            {
                dinfo.Create();
            }
            dinfo = null;

            Server.shared = new SharedState();
            Server.logger = new FileLogger();

            foreach (string arg in args)
            {
                if (arg.ToLower().Equals("--help"))
                {
                    string usage = "\n";
                    usage += "Usage:\n";
                    usage += "-----------------------------------------------------------------\n";
                    usage += "AstCtiServer.exe [--debug] [--dumpconfig]\n";
                    usage += "-----------------------------------------------------------------\n";
                    usage += "--debug      : enables extensive debug on console                \n";
                    usage += "--dumpconfig : enables dump of main asterisk configuration       \n";
                    usage += "               (extensions.conf, sip.conf and queues.conf) files \n";
                    Console.WriteLine(usage);
                    return;
                }
                if (arg.ToLower().Equals("--debug"))
                {
                    Server.debug = true;
                }

                if (arg.ToLower().Equals("--dumpconfig"))
                {
                    Server.dumpconf = true;
                }
            }

            Server.logger.WriteLine(LogType.Info, "Testing database connection");
            try
            {
                Server.logger.WriteLine(LogType.Debug, "Connecting to database on: " + cfg.MYSQL_HOST);
                Server.cn = new MySqlConnection(cfg.MYSQL_CONNSTR);
                Server.cn.Open();


                Server.MySqlVersion  = (string)MySqlHelper.ExecuteScalar(Server.cn, "SELECT VERSION()");
                Server.MySqlWaitTime = GetWaitTimeout();

                // La connessione al database è ok
                Server.logger.WriteLine(LogType.Debug, "Database connection successful");
                if (Server.debug)
                {
                    Console.WriteLine("Database connection successful");
                }

                Server.logger.WriteLine(LogType.Debug, "Database version: " + Server.MySqlVersion);
                if (Server.debug)
                {
                    Console.WriteLine("Database version: " + Server.MySqlVersion);
                }

                Server.logger.WriteLine(LogType.Debug, "Wait timeout is: " + Server.MySqlWaitTime.ToString());
                if (Server.debug)
                {
                    Console.WriteLine("Wait timeout is: " + Server.MySqlWaitTime.ToString());
                }

                Server.logger.WriteLine(LogType.Debug, "Server can start");
            }
            catch (Exception ex)
            {
                // Il test non è riuscito. Chiudiamo il programma
                if (Server.debug)
                {
                    Console.WriteLine(ex.ToString());
                }
                Server.logger.WriteLine(LogType.Error, "Database connection is not avaiable. Exiting");
                Environment.Exit(0);
            }

            Server.logger.WriteLine(LogType.Notice, "Starting MainServer");
            AstCTI = new MainServer();
        }