Exemple #1
0
        private static int InsertGraphsFromFilesToDatabase()
        {
            // Variable
            string reader;
            bool   writer, clearFile;

            Console.Clear();
            Console.WriteLine("Insert graphs from files to database");

            Console.WriteLine("Info: the files will be found in " + GenerateGraphs.GenerateGraphsFile.GetPathFolder() + "*." + GenerateGraphs.GenerateGraphsFile.GetFileNameExtension());

            Console.Write("Write report to console [true | false]: ");
            reader = Console.ReadLine();
            bool.TryParse(reader, out writer);

            Console.Write("Clear database [true | false]: ");
            reader = Console.ReadLine();
            bool.TryParse(reader, out clearFile);

            if (dataSource == null)
            {
                GetDatabaseInformations();
            }

            try
            {
                GenerateGraphs.GenerateGraphsDatabase generateGraphsDatabase = new GenerateGraphs.GenerateGraphsDatabase(dataSource, database, userName, password, writer, clearFile);

                Console.WriteLine();
                Console.WriteLine("Start inserting... ");
                Console.WriteLine();

                generateGraphsDatabase.SaveDataFromFileToDB();

                Console.WriteLine();
                Console.WriteLine("Graphs were inserted.");
                Console.WriteLine();
            }
            catch (MyException.DatabaseException.GenerateGraphsDatabaseNotOpenException)
            {
                dataSource = null;
                Console.WriteLine("Something wrong with database connection!");
                return(1);
            }
            catch (SqlException ex)
            {
                dataSource = null;
                Console.WriteLine("Something wrong: " + ex.GetType());
                return(1);
            }
            catch (IOException ex)
            {
                Console.WriteLine("Something wrong: " + ex.GetType());
                return(1);
            }

            return(0);
        }
Exemple #2
0
        private static int GenerateGraphsToDatabase()
        {
            // Variable
            string reader;
            bool   writer, clearDatabase, useGeneticAlgorithm2, useInterchangeExtendedK3;
            int    constant = 0, exponent = 0;
            int    minCount = 0, maxCount = 0;

            Console.Clear();
            Console.WriteLine("Generate graphs to database");

            Console.Write("Write report to console [true | false]: ");
            reader = Console.ReadLine();
            bool.TryParse(reader, out writer);

            Console.Write("Clear database [true | false]: ");
            reader = Console.ReadLine();
            bool.TryParse(reader, out clearDatabase);

            Console.Write("Use genetic algorithm (exponent: 2) [true | false]: ");
            reader = Console.ReadLine();
            bool.TryParse(reader, out useGeneticAlgorithm2);

            Console.Write("Use algorithms with interchangeExtended with K3 [true | false]: ");
            reader = Console.ReadLine();
            bool.TryParse(reader, out useInterchangeExtendedK3);

            do
            {
                Console.Write("Minimum number of vertices [positive int]: ");
                reader = Console.ReadLine();
                int.TryParse(reader, out minCount);
            }while (minCount <= 0);

            do
            {
                Console.Write("Maximum number of vertices [positive int]: ");
                reader = Console.ReadLine();
                int.TryParse(reader, out maxCount);
            }while (maxCount <= 0);

            do
            {
                Console.Write("Number of generated graphs - constant (constant * (number of vertices)^(exponent)) [positive int]: ");
                reader = Console.ReadLine();
                int.TryParse(reader, out constant);
            }while (constant <= 0);

            do
            {
                Console.Write("Number of generated graphs - exponent (constant * (number of vertices)^(exponent)) [positive int]: ");
                reader = Console.ReadLine();
                int.TryParse(reader, out exponent);
            }while (exponent <= 0);

            if (dataSource == null)
            {
                GetDatabaseInformations();
            }

            try
            {
                GenerateGraphs.GenerateGraphs generateGraphs = new GenerateGraphs.GenerateGraphsDatabase(dataSource, database, userName, password, writer, clearDatabase, constant, exponent, useGeneticAlgorithm2, useInterchangeExtendedK3);

                Console.WriteLine();
                Console.WriteLine("Start generating... ");
                Console.WriteLine();

                generateGraphs.Generate(minCount, maxCount);

                Console.WriteLine();
                Console.WriteLine("Graphs were generated and saved.");
                Console.WriteLine();
            }
            catch (MyException.DatabaseException.GenerateGraphsDatabaseNotOpenException)
            {
                dataSource = null;
                Console.WriteLine("Something wrong with database connection!");
                return(1);
            }
            catch (SqlException ex)
            {
                dataSource = null;
                Console.WriteLine("Something wrong: " + ex.GetType());
                return(1);
            }

            return(0);
        }