/// <summary>
 /// Function to add the company specified by LegalName to the database, along with all the
 /// tables required for basic company functionality
 /// </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)
 {
     if (!manipulator.AddCompany(LegalName))
     {
         Console.WriteLine("Failed to add company " + string.Join(" ", LegalName));
         Console.WriteLine("Failed because of error " + manipulator.LastException.Message);
         return;
     }
     Console.WriteLine("Successfully added company " + string.Join(" ", LegalName));
 }
Example #2
0
        public static bool InitializeDatabaseSchema()
        {
            if (DatabaseInitialized)
            {
                return(true);
            }
            MySqlDataManipulator manipulator = new MySqlDataManipulator();

            using (manipulator)
            {
                if (!manipulator.Connect(TestingConstants.DatabaselessConnectionString))
                {
                    Console.WriteLine("Encountered an error opening the global configuration connection");
                    Console.WriteLine(manipulator.LastException.Message);
                    return(false);
                }
                if (!manipulator.ValidateDatabaseIntegrity(TestingConstants.DatabaselessConnectionString, "db_test"))
                {
                    Console.WriteLine("Encountered an error opening the global configuration connection");
                    Console.WriteLine(manipulator.LastException.Message);
                    return(false);
                }
                if (!manipulator.Connect(TestingConstants.ConnectionString))
                {
                    Console.WriteLine("Encountered an error opening the global configuration connection");
                    Console.WriteLine(manipulator.LastException.Message);
                    return(false);
                }
                if (manipulator.GetCompanyById(1) == null)
                {
                    if (!manipulator.AddCompany(TestingCompanyStorage.ValidCompany1))
                    {
                        Console.WriteLine("Encountered an error adding the first valid company");
                        Console.WriteLine(manipulator.LastException.Message);
                        return(false);
                    }
                }
                if (manipulator.GetCompanyById(2) == null)
                {
                    if (!manipulator.AddCompany(TestingCompanyStorage.ValidCompany2))
                    {
                        Console.WriteLine("Encountered an error adding the second valid company");
                        Console.WriteLine(manipulator.LastException.Message);
                        return(false);
                    }
                }
                DatabaseInitialized = true;
                if (!InitializeUsers())
                {
                    return(false);
                }
                if (!InitializeJoinRequests())
                {
                    return(false);
                }
                if (!InitializePartCatelogueEntries())
                {
                    return(false);
                }
                if (!InitializePartsRequests())
                {
                    return(false);
                }
                if (!GlobalModelHelper.LoadOrTrainGlobalModels(ReflectionHelper.GetAllKeywordPredictors()))
                {
                    return(false);
                }
            }
            MySqlDataManipulator.GlobalConfiguration.Connect(TestingConstants.ConnectionString);
            MySqlDataManipulator.GlobalConfiguration.Close();
            return(true);
        }