public static void RunPendingJobs(Database db) { LocalDatasourceExecutor jobExecutor; IDataSource ds; int?nextDatasourceId; DatasourceManager datasourceManager; ConfiguredDatasource currentDatasource; RawDataValue[] values; DatasourceParameterType[] parameterTypes; _log.Debug("Creating the datasource manager to load the datasources using reflection"); datasourceManager = new DatasourceManager(); _log.Debug("Checking for available jobs to run"); while ((nextDatasourceId = db.GetNextConfiguredDatasourceId()) != null) { _log.DebugFormat("Found configured datasource ID #{0} to run", nextDatasourceId); currentDatasource = db.ORManager.Get <ConfiguredDatasource>(nextDatasourceId); _log.DebugFormat("Loaded datasource; type={1}", currentDatasource.DatasourceType.Id); try { //Load the datasource class to process the configured datasource ds = datasourceManager.GetDatasource(currentDatasource.DatasourceType.Id); if (ds == null) { _log.WarnFormat("Could not load an appropriate datasource reader for ID {0}", currentDatasource.DatasourceType.Id); return; } //Load the parameter types parameterTypes = db.GetParameterTypesForDatasource(currentDatasource.DatasourceType.Id); //Set up the datasource currentDatasource.InitializeDatasource(ds, parameterTypes); jobExecutor = new LocalDatasourceExecutor(ds); jobExecutor.Execute(); //Set the configured datasource ID on all the values values = ds.Values; if (values != null && values.Length > 0) { foreach (RawDataValue currValue in values) { currValue.ConfiguredDatasourceId = nextDatasourceId.Value; } //Save the results db.BulkInsertRawData(values); } } catch (Exception ex) { _log.Error(string.Format("Error executing configured datasource id #{0}", nextDatasourceId), ex); } } }
public void Test() { DatasourceManager dm; IDataSource ds; dm = new DatasourceManager(); ds = dm.GetDatasource(1); }