public RuntimeTask Create(IProcessTask task, IStageArgs stageArgs) { //get the user configured Design Time arguments + stage specific arguments var args = new RuntimeArgumentCollection(task.GetAllArguments().ToArray(), stageArgs); //Create an instance of the the appropriate ProcessTaskType switch (task.ProcessTaskType) { case ProcessTaskType.Executable: return(new ExecutableRuntimeTask(task, args)); case ProcessTaskType.SQLFile: return(new ExecuteSqlFileRuntimeTask(task, args)); case ProcessTaskType.Attacher: return(new AttacherRuntimeTask(task, args, _repository.MEF)); case ProcessTaskType.DataProvider: return(new DataProviderRuntimeTask(task, args, _repository.MEF)); case ProcessTaskType.MutilateDataTable: return(new MutilateDataTablesRuntimeTask(task, args, _repository.MEF)); default: throw new Exception("Cannot create runtime task: Unknown process task type '" + task.ProcessTaskType + "'"); } }
public void ExecuteSqlRuntimeTask_InvalidID(DatabaseType dbType) { var dt = new DataTable(); dt.Columns.Add("Lawl"); dt.Rows.Add(new object[] { 2 }); var db = GetCleanedServer(dbType, true); var tbl = db.CreateTable("Fish", dt); TableInfo ti; ColumnInfo[] cols; Import(tbl, out ti, out cols); string sql = @"UPDATE {T:0} Set {C:0} = 1"; IRuntimeTask task; IProcessTask pt; var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "ExecuteSqlFileRuntimeTaskTests", true); var sqlArg = new IArgument[] { Mock.Of <IArgument>(x => x.Name == "Sql" && x.Value == sql && x.GetValueAsSystemType() == sql) }; var args = new RuntimeArgumentCollection(sqlArg, new StageArgs(LoadStage.AdjustRaw, db, dir)); pt = Mock.Of <IProcessTask>(x => x.Path == typeof(ExecuteSqlMutilation).FullName && x.GetAllArguments() == sqlArg ); task = new MutilateDataTablesRuntimeTask(pt, args, CatalogueRepository.MEF); task.Check(new ThrowImmediatelyCheckNotifier()); HICDatabaseConfiguration configuration = new HICDatabaseConfiguration(db.Server); var job = new ThrowImmediatelyDataLoadJob(); job.RegularTablesToLoad = new List <ITableInfo> { ti }; job.LookupTablesToLoad = new List <ITableInfo>(); job.Configuration = configuration; var ex = Assert.Throws <Exception>(() => task.Run(job, new GracefulCancellationToken())); StringAssert.Contains("Mutilate failed", ex.Message); StringAssert.Contains("Failed to find a TableInfo in the load with ID 0", ex.InnerException.Message); task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); }
public void SetPropertiesForClass(RuntimeArgumentCollection args, object toSetPropertiesOf) { if (toSetPropertiesOf == null) { throw new NullReferenceException(ProcessTask.Path + " instance has not been created yet! Call SetProperties after the factory has created the instance."); } if (UsefulStuff.IsAssignableToGenericType(toSetPropertiesOf.GetType(), typeof(IPipelineRequirement <>))) { throw new Exception("ProcessTask '" + ProcessTask.Name + "' was was an instance of Class '" + ProcessTask.Path + "' which declared an IPipelineRequirement<>. RuntimeTask classes are not the same as IDataFlowComponents, IDataFlowComponents can make IPipelineRequirement requests but RuntimeTasks cannot"); } if (UsefulStuff.IsAssignableToGenericType(toSetPropertiesOf.GetType(), typeof(IPipelineOptionalRequirement <>))) { throw new Exception("ProcessTask '" + ProcessTask.Name + "' was was an instance of Class '" + ProcessTask.Path + "' which declared an IPipelineOptionalRequirement<>. RuntimeTask classes are not the same as IDataFlowComponents, IDataFlowComponents can make IPipelineRequirement requests but RuntimeTasks cannot"); } //get all possible properties that we could set foreach (var propertyInfo in toSetPropertiesOf.GetType().GetProperties()) { //see if any demand initialization DemandsInitializationAttribute initialization = (DemandsInitializationAttribute)System.Attribute.GetCustomAttributes(propertyInfo).FirstOrDefault(a => a is DemandsInitializationAttribute); //this one does if (initialization != null) { try { //get the approrpriate value from arguments var value = args.GetCustomArgumentValue(propertyInfo.Name); //use reflection to set the value propertyInfo.SetValue(toSetPropertiesOf, value, null); } catch (NotSupportedException e) { throw new Exception("Class " + toSetPropertiesOf.GetType().Name + " has a property " + propertyInfo.Name + " but is of unexpected type " + propertyInfo.GetType(), e); } catch (KeyNotFoundException e) { if (initialization.Mandatory) { throw new ArgumentException( "Class " + toSetPropertiesOf.GetType().Name + " has a Mandatory property '" + propertyInfo.Name + "' marked with DemandsInitialization but no corresponding argument was provided in ArgumentCollection", e); } } } } }
public AttacherRuntimeTask(IProcessTask task, RuntimeArgumentCollection args, MEF mef) : base(task, args) { //All attachers must be marked as mounting stages, and therefore we can pull out the RAW Server and Name var mountingStageArgs = args.StageSpecificArguments; if (mountingStageArgs.LoadStage != LoadStage.Mounting) { throw new Exception("AttacherRuntimeTask can only be called as a Mounting stage process"); } if (string.IsNullOrWhiteSpace(task.Path)) { throw new ArgumentException("Path is blank for ProcessTask '" + task + "' - it should be a class name of type " + typeof(IAttacher).Name); } Attacher = mef.CreateA <IAttacher>(ProcessTask.Path); SetPropertiesForClass(RuntimeArguments, Attacher); Attacher.Initialize(args.StageSpecificArguments.RootDir, RuntimeArguments.StageSpecificArguments.DbInfo); }
public void TestConstructionFromProcessTaskUsingDatabase() { const string expectedPath = @"\\a\fake\path.exe"; var loadMetadata = new LoadMetadata(CatalogueRepository); var processTask = new ProcessTask(CatalogueRepository, loadMetadata, LoadStage.Mounting) { Name = "Test process task", Path = expectedPath }; processTask.SaveToDatabase(); var argument = new ProcessTaskArgument(CatalogueRepository, processTask) { Name = "DatabaseName", Value = @"Foo_STAGING" }; argument.SaveToDatabase(); try { var args = new RuntimeArgumentCollection(processTask.ProcessTaskArguments.Cast <IArgument>().ToArray(), null); var runtimeTask = new ExecutableRuntimeTask(processTask, args); Assert.AreEqual(expectedPath, runtimeTask.ExeFilepath); Assert.AreEqual(1, runtimeTask.RuntimeArguments.GetAllArgumentsOfType <string>().Count()); var dictionaryOfStringArguments = runtimeTask.RuntimeArguments.GetAllArgumentsOfType <string>().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); Assert.IsNotNull(dictionaryOfStringArguments["DatabaseName"]); Assert.AreEqual("Foo_STAGING", dictionaryOfStringArguments["DatabaseName"]); } finally { loadMetadata.DeleteInDatabase(); } }
public DataProviderRuntimeTask(IProcessTask task, RuntimeArgumentCollection args, MEF mef) : base(task, args) { string classNameToInstantiate = task.Path; if (string.IsNullOrWhiteSpace(task.Path)) { throw new ArgumentException("Path is blank for ProcessTask '" + task + "' - it should be a class name of type " + typeof(IDataProvider).Name); } Provider = mef.CreateA <IDataProvider>(classNameToInstantiate); try { SetPropertiesForClass(RuntimeArguments, Provider); } catch (Exception e) { throw new Exception("Error when trying to set the properties for '" + task.Name + "'", e); } Provider.Initialize(args.StageSpecificArguments.RootDir, RuntimeArguments.StageSpecificArguments.DbInfo); }
public MutilateDataTablesRuntimeTask(IProcessTask task, RuntimeArgumentCollection args, MEF mef) : base(task, args) { //All attachers must be marked as mounting stages, and therefore we can pull out the RAW Server and Name var stageArgs = args.StageSpecificArguments; if (stageArgs == null) { throw new NullReferenceException("Stage args was null"); } if (stageArgs.DbInfo == null) { throw new NullReferenceException("Stage args had no DbInfo, unable to mutilate tables without a database - mutilator is sad"); } if (string.IsNullOrWhiteSpace(task.Path)) { throw new ArgumentException("Path is blank for ProcessTask '" + task + "' - it should be a class name of type " + typeof(IMutilateDataTables).Name); } MutilateDataTables = mef.CreateA <IMutilateDataTables>(ProcessTask.Path); SetPropertiesForClass(RuntimeArguments, MutilateDataTables); MutilateDataTables.Initialize(stageArgs.DbInfo, ProcessTask.LoadStage); }
public ExecuteSqlFileRuntimeTask(IProcessTask task, RuntimeArgumentCollection args) : base(task, args) { _task = task; Filepath = task.Path; }
public ExecutableRuntimeTask(IProcessTask processTask, RuntimeArgumentCollection args) : base(processTask, args) { ExeFilepath = processTask.Path; }
protected RuntimeTask(IProcessTask processTask, RuntimeArgumentCollection args) { ProcessTask = processTask; RuntimeArguments = args; }