public Scheduler(TicketStorage storage, Security.SecurityManager securityManager) { StartTime = new DateTime(1, 1, 1, 8, 0, 0); EndTime = new DateTime(1, 1, 1, 19, 0, 0); mainSchedule = new Thread(loop); this.storage = storage; this.storage.registerScheduler(this); this.securityManager = securityManager; loadTickets(); mainSchedule.Start(); }
//http://stackoverflow.com/a/11779234 //jobLocation: absolute location to ticket.json or job.json where job is the generic name for whatever needs to be done //Blocks main caller thread /*public static void runScript(Scheduler sched, int ticketId, ScriptType type, RunnableScript toRun, string jobLocation) { * * bool canRun = false; * if (type == ScriptType.Python) { * * switch (toRun) { * case RunnableScript.modifyScript: * Console.WriteLine("Not Implemented! Modify Script"); * canRun = false; * break; * case RunnableScript.verifyScript: * Console.WriteLine("Not Implemented! Verify Script"); * canRun = false; * break; * case RunnableScript.testScript: * canRun = true; * start.Arguments = string.Format("{0} {1}", scriptLoc(toRun), jobLocation); * break; * default: * Console.WriteLine("Default case called for runScript"); * break; * } * } * else { * Console.WriteLine("Not Implemented! Type: {0}", type); * } * if (canRun && start != null) { * Process process = Process.Start(start); * * new Task(() => { * * }).Start(); * } * }*/ public static void modifyTicket(int TicketId, Scheduler sched, Security.SecurityManager manager) { //try and get job location string ticketLocation = sched.getTicketLocation(TicketId); ProcessStartInfo start = new ProcessStartInfo(); start.FileName = pythonLoc; start.UseShellExecute = false; start.RedirectStandardOutput = true; //get userFile Location and generate random crypto info string randKey = Security.SecurityManager.randomCrypto(); string randIV = Security.SecurityManager.randomCrypto(); //Just use the default manager for now string userFileLocation = manager.getUserFileLocation("default", randKey, randIV); //CHANGE IN PRODUCTION //start.Arguments = String.Format("{0} {1}", scriptLoc(RunnableScript.modifyScript), ticketLocation); start.Arguments = String.Format("{0} {1} {2} {3} {4}", scriptLoc(RunnableScript.testScript), ticketLocation, userFileLocation, randKey, randIV); try { Process process = Process.Start(start); using (StreamReader reader = process.StandardOutput) { string result = reader.ReadToEnd(); Console.Write(result); } sched.completeTicket(TicketId, ticketLocation); manager.destroyUserFile(userFileLocation); } catch (Exception e) { string messsage = e.Message; } }