示例#1
0
 internal Databron(DataTable data, string databronnaam, string applicatienaam, string referentiequery, string gemeentecode, EscapeSequence escaper)
 {
     this.data            = data;
     this.databronnaam    = databronnaam;
     this.applicatienaam  = applicatienaam;
     this.referentiequery = referentiequery;
     this.gemeentecode    = gemeentecode;
     this.escaper         = escaper;
 }
示例#2
0
        public static Databron GetData(DbProviderFactory configprovider, DbConnection configconnection, String datasourcename)
        {
            // const string sql = "SELECT * FROM SOME_TABLE WHERE Name = @name";
            // cmd.CommandText = sql;
            // cmd.Parameters.AddWithValue("@name", name);


            var command = configprovider.CreateCommand();

            // TODO: parameter
            command.CommandText = "SELECT * FROM " + Properties.Settings.Default.databaseprefix + "databron WHERE databronnaam LIKE '" + datasourcename + "'";
            command.Connection  = configconnection;
            var adapter = configprovider.CreateDataAdapter();

            adapter.SelectCommand = command;
            var table = new DataTable();

            adapter.Fill(table);
            if (table.Rows.Count != 1)
            {
                throw new Exception("Kon de datasource met naam:" + datasourcename + " niet vinden!");
            }

            String datasource_provider         = Convert.ToString(table.Rows[0]["provider"]);
            String datasource_connectionstring = Convert.ToString(table.Rows[0]["connectionstring"]);
            String datasource_query            = Convert.ToString(table.Rows[0]["query"]);
            String applicatie     = Convert.ToString(table.Rows[0]["applicatienaam"]);
            String gemeentecode   = Convert.ToString(table.Rows[0]["gemeentecode"]);
            String escapesequence = "";

            // make backwards compatible
            if (table.Columns.Contains("escapesequence"))
            {
                escapesequence = Convert.ToString(table.Rows[0]["escapesequence"]);
            }
            else
            {
                Output.Warn("!!! Column 'escapesequence' not defined in databron, using NO escapers anywhere !!!");
            }
            EscapeSequence escaper = new EscapeSequence(escapesequence);

            var connection = new ISpiegel.Provider.FileSystem.Connection();
            DbProviderFactory datasource_factory = null;

            if (datasource_provider.Equals("ISpiegel.Providers.FileSystem"))
            {
                datasource_factory = new ISpiegel.Provider.FileSystem.Factory();
            }
            else
            {
                datasource_factory = DbProviderFactories.GetFactory(datasource_provider);
            }
            var datasource_connection = datasource_factory.CreateConnection();

            datasource_connection.ConnectionString = datasource_connectionstring.Replace("${WORKING_DIRECTORY}", System.IO.Directory.GetCurrentDirectory());
            datasource_connection.Open();
            var datasource_command = datasource_factory.CreateCommand();

            datasource_command.CommandText = datasource_query;
            datasource_command.Connection  = datasource_connection;
            var datasource_adapter = datasource_factory.CreateDataAdapter();

            datasource_adapter.SelectCommand = datasource_command;
            var datasource_table = new DataTable();

            datasource_adapter.Fill(datasource_table);
            datasource_connection.Close();

            // datasource_table.ExtendedProperties.Add("databronnaam", datasourcename);
            // datasource_table.ExtendedProperties.Add("applicatienaam", applicatie);
            // datasource_table.ExtendedProperties.Add("referentiequery", datasource_query);
            // datasource_table.ExtendedProperties.Add("gemeentecode", gemeentecode);

            return(new Databron(datasource_table, datasourcename, applicatie, datasource_query, gemeentecode, escaper));
        }