/// <summary>
        /// Function to renew HTTPS certification.
        /// </summary>
        /// <param name="manipulator"><see cref="MySqlDataManipulator"/> used to add the company to the database</param>
        /// <remarks>As this is a command to be used by the developers on the project, error output is minimal</remarks>
        public override void PerformFunction(MySqlDataManipulator manipulator)
        {
            var server = ApiLoader.LoadApiAndListen(16384);

            Console.WriteLine("Attempting to retrieve new certificate");
            CertificateRenewer.GetFirstCert(false);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Now.ToLocalTime().ToString());
            DatabaseConfigurationFileContents config;

            try
            {
                config = RetrieveConfiguration();
            } catch (ThreadInterruptedException)
            {
                return;
            }
            if (config == null)
            {
                Console.WriteLine("Failed to retrieve or restore database configuration file. Exiting");
                return;
            }
            bool res = MySqlDataManipulator.GlobalConfiguration.Connect(new MySqlConnectionString(config.Host, config.Database, config.User).ConstructConnectionString(config.Pass.ConvertToString()));

            if (!res && MySqlDataManipulator.GlobalConfiguration.LastException.Number != 1049 && MySqlDataManipulator.GlobalConfiguration.LastException.Number != 0)
            {
                Console.WriteLine("Encountered an error opening the global configuration connection");
                Console.WriteLine(MySqlDataManipulator.GlobalConfiguration.LastException.Message);
                return;
            }
            if (!MySqlDataManipulator.GlobalConfiguration.ValidateDatabaseIntegrity(new MySqlConnectionString(config.Host, null, config.User).ConstructConnectionString(config.Pass.ConvertToString()), config.Database))
            {
                Console.WriteLine("Encountered an error opening the global configuration connection");
                Console.WriteLine(MySqlDataManipulator.GlobalConfiguration.LastException.Message);
                return;
            }
            MySqlDataManipulator.GlobalConfiguration.Close();
            CommandLineArgumentParser parser = new CommandLineArgumentParser(args);

            MySqlDataManipulator.GlobalConfiguration.Connect(new MySqlConnectionString(config.Host, config.Database, config.User).ConstructConnectionString(config.Pass.ConvertToString()));
            config.Pass.Dispose();
            config = null;
            bool exit = DatabaseEntityCreationUtilities.PerformRequestedCreation(MySqlDataManipulator.GlobalConfiguration, parser);

            MySqlDataManipulator.GlobalConfiguration.Close();
            if (exit)
            {
                return;
            }
            if (!GlobalModelHelper.LoadOrTrainGlobalModels(ReflectionHelper.GetAllKeywordPredictors()))
            {
                throw new NullReferenceException("One or more global models failed to load. Server cannot start.");
            }
            else if (AveragedPerceptronTagger.GetTagger() == null)
            {
                throw new NullReferenceException("Failed to load the Averaged Perceptron Tagger");
            }
            Logger.GetLogger(Logger.LoggerDefaultFileLocations.DEFAULT).Log(Logger.LogLevel.INFO, "Server is starting up");
            using (Logger.Disposer)
            {
                Thread t = new Thread(RenewCertificate);
                t.Start();
                Thread train = new Thread(PerformTraining);
                train.Start();
                var server = ApiLoader.LoadApiAndListen(16384);
                while (server.IsAlive)
                {
                    Thread.Sleep(100);
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo key = Console.ReadKey(true);
                        if (key.Key == ConsoleKey.Enter)
                        {
                            server.Close();
                        }
                    }
                }
                t.Interrupt();
                train.Interrupt();
            }
            //QueryProcessor processor = new QueryProcessor(QueryProcessorSettings.GenerateDefaultSettings());
            //processor.ProcessQuery(new Util.MechanicQuery("autocar", "xpeditor", null, null, "runs rough"));
        }