private void buildTaskChain(app kickoff, app combine, List <app> dataloaders, List <app> userapps, int rep) { string taskresult; List <task> QVDloadtasks = new List <task>(); //Create Kick of task task kickofftask; kickofftask = new task(); kickofftask.app = kickoff; kickofftask.enabled = false; kickofftask.taskType = 0; kickofftask.name = "Reload of :" + kickoff.name; //timetrigger for kick off task List <schemaEvent> triggers = new List <schemaEvent>(); schemaEvent newevent = new schemaEvent(); newevent.enabled = true; newevent.daylightSavingTime = 0; newevent.eventType = 0; newevent.incrementDescription = "15 0 0 0"; newevent.incrementOption = 0; newevent.name = "hourly"; newevent.timeZone = "UTC"; newevent.schemaFilterDescription = new string[] { "* * - * * * * *" }; newevent.startDate = "2016-06-23T20:45:10.000Z"; newevent.expirationDate = "9999-01-01T00:00:00.000Z"; triggers.Add(newevent); ReloadObject taskandtrigger = new ReloadObject(); taskandtrigger.task = kickofftask; taskandtrigger.schemaEvents = triggers.ToArray(); string xTask = JsonConvert.SerializeObject(taskandtrigger, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); taskresult = qrsClient.Post("/qrs/reloadtask/create", xTask); kickofftask = JsonConvert.DeserializeObject <task>(taskresult); //Create QVDLoaderTriggers ReloadObject ReloadChain = new ReloadObject(); foreach (app app in dataloaders) { task childtask = new task(); childtask.app = app; childtask.enabled = true; childtask.taskType = 0; childtask.name = "Reload of :" + app.name; List <compositeEvent> CompEvents = new List <compositeEvent>(); List <compositeRule> CompRules = new List <compositeRule>(); compositeRule aRule = new compositeRule(); aRule.reloadTask = kickofftask; aRule.ruleState = "TaskSuccessful"; CompRules.Add(aRule); timeConstraint TS = new timeConstraint(); TS.days = 0; TS.hours = 6; TS.minutes = 0; compositeEvent aEvent = new compositeEvent(); aEvent.name = "FollowInitialExtract"; aEvent.eventType = 1; aEvent.compositeRules = CompRules.ToArray(); aEvent.enabled = true; aEvent.timeConstraint = TS; CompEvents.Add(aEvent); ReloadChain.task = childtask; ReloadChain.compositeEvents = CompEvents.ToArray(); string sTask = JsonConvert.SerializeObject(ReloadChain, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); taskresult = qrsClient.Post("/qrs/reloadtask/create", sTask); QVDloadtasks.Add(JsonConvert.DeserializeObject <task>(taskresult)); } //ConsolidateTask ReloadChain = new ReloadObject(); task consolidatetask = new task(); consolidatetask.app = combine; consolidatetask.enabled = true; consolidatetask.taskType = 0; consolidatetask.name = "Reload of :" + combine.name; List <compositeEvent> ConsolidateCompEvents = new List <compositeEvent>(); List <compositeRule> ConsolidateCompRules = new List <compositeRule>(); for (int i = 0; i < QVDloadtasks.Count; i++) { compositeRule ConsolidateRule = new compositeRule(); ConsolidateRule.reloadTask = QVDloadtasks[i]; ConsolidateRule.ruleState = "TaskSuccessful"; ConsolidateCompRules.Add(ConsolidateRule); } timeConstraint TS2 = new timeConstraint(); TS2.days = 0; TS2.hours = 6; TS2.minutes = 0; compositeEvent newEvent = new compositeEvent(); newEvent.name = "Follow all sales QVDs"; newEvent.eventType = 1; newEvent.compositeRules = ConsolidateCompRules.ToArray(); newEvent.enabled = true; newEvent.timeConstraint = TS2; ConsolidateCompEvents.Add(newEvent); ReloadChain.task = consolidatetask; ReloadChain.compositeEvents = ConsolidateCompEvents.ToArray(); string Task = JsonConvert.SerializeObject(ReloadChain, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); taskresult = qrsClient.Post("/qrs/reloadtask/create", Task); consolidatetask = JsonConvert.DeserializeObject <task>(taskresult); // second level children foreach (app app in userapps) { task childtask = new task(); childtask.app = app; childtask.enabled = true; childtask.taskType = 0; childtask.name = "Reload of :" + app.name; List <compositeEvent> CompEvents = new List <compositeEvent>(); List <compositeRule> CompRules = new List <compositeRule>(); compositeRule aRule = new compositeRule(); aRule.reloadTask = consolidatetask; aRule.ruleState = "TaskSuccessful"; CompRules.Add(aRule); timeConstraint TS = new timeConstraint(); TS.days = 0; TS.hours = 6; TS.minutes = 0; compositeEvent aEvent = new compositeEvent(); aEvent.name = "Follow Transform of QVDs"; aEvent.eventType = 1; aEvent.compositeRules = CompRules.ToArray(); aEvent.enabled = true; aEvent.timeConstraint = TS; CompEvents.Add(aEvent); ReloadChain.task = childtask; ReloadChain.compositeEvents = CompEvents.ToArray(); string sTask = JsonConvert.SerializeObject(ReloadChain, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); taskresult = qrsClient.Post("/qrs/reloadtask/create", sTask); } }
public string addTaskChainApps(int number, int chaindepth) { System.IO.File.WriteAllBytes(System.IO.Path.GetTempPath() + @"\InitialSalesDataExtract.qvf", Properties.Resources.InitialSalesDataExtract); System.IO.File.WriteAllBytes(System.IO.Path.GetTempPath() + @"\SalesQVDload.qvf", Properties.Resources.SalesQVDLoad); System.IO.File.WriteAllBytes(System.IO.Path.GetTempPath() + @"\TransformSalesData.qvf", Properties.Resources.TransformSalesData); System.IO.File.WriteAllBytes(System.IO.Path.GetTempPath() + @"\Sales.qvf", Properties.Resources.Sales); for (int rep = 100; rep < 100 + number; rep++) { TimeSpan responsetime = DateTime.Now.TimeOfDay; app kickoff; app combine; List <app> QVDLoaders; List <app> UserApps; QVDLoaders = new List <app>(); UserApps = new List <app>(); Dictionary <string, string> queries = new Dictionary <string, string>(); queries.Add("name", rep + "_Kick off task chain "); string postfileresult = qrsClient.PostFile("/qrs/app/upload", System.IO.Path.GetTempPath() + @"\InitialSalesDataExtract.qvf", queries); kickoff = JsonConvert.DeserializeObject <app>(postfileresult); queries = new Dictionary <string, string>(); queries.Add("name", rep + "_Transform Sales Data "); postfileresult = qrsClient.PostFile("/qrs/app/upload", System.IO.Path.GetTempPath() + @"\TransformSalesData.qvf", queries); combine = JsonConvert.DeserializeObject <app>(postfileresult); for (int i = 1; i <= chaindepth; i++) { queries = new Dictionary <string, string>(); queries.Add("name", rep + "_Data Loader " + i); postfileresult = qrsClient.PostFile("/qrs/app/upload", System.IO.Path.GetTempPath() + @"\SalesQVDload.qvf", queries); app appresult = JsonConvert.DeserializeObject <app>(postfileresult); QVDLoaders.Add(appresult); } for (int i = 1; i <= chaindepth; i++) { queries = new Dictionary <string, string>(); queries.Add("name", rep + "_User App " + i); postfileresult = qrsClient.PostFile("/qrs/app/upload", System.IO.Path.GetTempPath() + @"\Sales.qvf", queries); app newapp = JsonConvert.DeserializeObject <app>(postfileresult); UserApps.Add(newapp); //publish it //publishApp(newapp, "Global Sales"); } buildTaskChain(kickoff, combine, QVDLoaders, UserApps, rep); responsetime = DateTime.Now.TimeOfDay - responsetime; writeresult("Add", "TaskChain", responsetime); } return(number + " task chains added"); }