コード例 #1
0
        // Function to use SuperView once initialised
        public static void useSuperView()
        {
            Console.WriteLine("");

            // Get all of the mappings we have produced
            DataTable mappings = MappingEngine.getMappings();

            // Display the mappings
            foreach (DataRow mapping in mappings.Rows)
            {
                string dataSourceName = Utilities.getDataSourceName((int)mapping["sourceDataSource"]);
                string tableName      = Utilities.getTableName((int)mapping["sourceTable"]);
                Console.WriteLine(mapping["targetName"].ToString() + " (Data Source: " + dataSourceName + "| Table: " + tableName + ")");
            }

            Console.WriteLine("");

            Console.Write("Enter query: ");
            Dictionary <Wrapper, DataTable> results = QueryEngine.query(Console.ReadLine().ToString());
            DataTable output = QueryEngine.joinData(results);
        }
コード例 #2
0
        //Function to display all the mappings
        public static void showMappings()
        {
            //Loop through all of the wrappers and output their names
            Console.WriteLine("Wrappers...");

            foreach (KeyValuePair <string, Wrapper> dataSource in dataSources)
            {
                Console.WriteLine(dataSource.Key.ToString());
            }

            Console.WriteLine("");
            Console.WriteLine("Mappings...");

            // Get all of the mappings we have produced
            DataTable mappings = MappingEngine.getMappings();

            // Display the mappings (along with their ID)
            foreach (DataRow mapping in mappings.Rows)
            {
                string dataSourceName = Utilities.getDataSourceName((int)mapping["sourceDataSource"]);
                string tableName      = Utilities.getTableName((int)mapping["sourceTable"]);
                Console.WriteLine("ID: " + mapping["ID"].ToString() + " Name: " + mapping["targetName"].ToString() + " (Data Source: " + dataSourceName + "| Table: " + tableName + " Table ID: " + mapping["sourceTable"] + ")");
            }
        }
コード例 #3
0
        // Function to start the SuperView system including initialising and mapping all defined data sources
        static void startSuperView()
        {
            string response;

            Console.WriteLine("Loading data source configurations...");

            // Load the data source definitions and create the required objects
            loadDataSourceDefinitions();
            createDataSourceObjects();
            Console.WriteLine(dataSources.Count().ToString() + " data source(s) loaded");

            Console.WriteLine("");

            // Loop through each of the data sources
            foreach (KeyValuePair <string, Wrapper> dataSource in dataSources)
            {
                Wrapper wrapper = dataSource.Value;

                Console.WriteLine("Data Source: " + wrapper.getName() + " (ID: " + wrapper.getID().ToString() + ")");
                Console.Write("Would you like to configure mappings for this data source? (Y/N): ");

                string reponse = Console.ReadLine();

                // Perform the mappings
                if (reponse.ToString().ToLower() == "y")
                {
                    // Map the tables
                    Console.WriteLine("Mapping tables...");

                    // Give the user the option to preserve table mappings
                    if (MappingEngine.getMappedTables(wrapper).Rows.Count > 0)
                    {
                        Console.WriteLine("Table mappings already exist for '" + wrapper.getName() + "'");
                    }
                    else
                    {
                        // Loop through the tables
                        foreach (string table in wrapper.getTables())
                        {
                            // Ask the user if they want to map the table
                            Console.Write("Would you like to map the '" + table + "' table? (Y/N): ");
                            response = Console.ReadLine().ToString();

                            // If they do then map the table
                            if (response.ToLower() == "y")
                            {
                                MappingEngine.mapTable(wrapper, table);
                                Console.WriteLine(table);
                            }
                        }

                        // Display how many tables we have mapped in this data source
                        Console.WriteLine(MappingEngine.getMappedTables(wrapper).Rows.Count.ToString() + " table(s) mapped");
                    }

                    Console.WriteLine("");

                    // Map the fields
                    Console.WriteLine("Mapping fields...");

                    // Loop through every table that we have mapped for this data source
                    foreach (DataRow mapping in MappingEngine.getMappedTables(wrapper).Rows)
                    {
                        int    tableID = (int)mapping["ID"];
                        string table   = mapping["Name"].ToString();

                        // Check if there are any mappings for this table, if there are then we can't change them
                        if (MappingEngine.getMappings(wrapper, tableID).Rows.Count > 0)
                        {
                            Console.WriteLine("Mappings already exist for the '" + table + "' table.");
                        }
                        else
                        {
                            // Loop through each column in the data source
                            foreach (KeyValuePair <string, Dictionary <string, string> > column in wrapper.getColumns(table))
                            {
                                Console.WriteLine("Column Name: " + column.Key.ToString() + " | Data Type: " + column.Value["data_type"].ToString());
                                Console.Write("Enter a mapping name for this column (leave blank to ignore): ");
                                string mappingName = Console.ReadLine().ToString();

                                // If we entered a mapping name then add the mapping to the database
                                if (mappingName != "")
                                {
                                    MappingEngine.mapField(wrapper, table, column.Key.ToString(), column.Value.ToString(), mappingName);
                                }

                                Console.WriteLine("");
                            }
                            Console.WriteLine(MappingEngine.getMappings(wrapper, tableID).Rows.Count.ToString() + " field(s) mapped");
                        }
                    }
                }
            }

            Console.WriteLine("");

            // Set up relations
            Console.WriteLine("Creating relations...");

            Console.Write("Would you like to add a relation? (Y/N): ");
            response = Console.ReadLine();

            // While the user wants to add more relations
            while (response.ToString().ToLower() == "y")
            {
                // Get all of the mappings we have produced
                DataTable mappings = MappingEngine.getMappings();

                // Display the mappings (along with their ID)
                foreach (DataRow mapping in mappings.Rows)
                {
                    string dataSourceName = Utilities.getDataSourceName((int)mapping["sourceDataSource"]);
                    string tableName      = Utilities.getTableName((int)mapping["sourceTable"]);
                    Console.WriteLine("ID: " + mapping["ID"].ToString() + " Name: " + mapping["targetName"].ToString() + " (Data Source: " + dataSourceName + "| Table: " + tableName + " Table ID: " + mapping["sourceTable"] + ")");
                }

                Console.Write("Enter table 1 ID: ");
                int table1 = Int32.Parse(Console.ReadLine().ToString());
                Console.Write("Enter table 2 ID: ");
                int table2 = Int32.Parse(Console.ReadLine().ToString());
                Console.Write("Enter relation for column 1 (E.g. {ID}): ");
                string column1 = Console.ReadLine().ToString();
                Console.Write("Enter relation for column 2 (E.g. {ID}): ");
                string column2 = Console.ReadLine().ToString();

                //Store the relation
                MappingEngine.storeRelation(table1, table2, column1, column2);

                // Check if the user wants to make another mapping
                Console.Write("Would you like to add a relation? (Y/N): ");
                response = Console.ReadLine();
            }
        }