/// <summary>Main program</summary> static int Main(string[] args) { try { AppDomain.CurrentDomain.AssemblyResolve += Manager.ResolveManagerAssembliesEventHandler; // Send a command to socket server to get the job to run. object response = GetNextJob(); while (response != null) { JobRunnerMultiProcess.GetJobReturnData job = response as JobRunnerMultiProcess.GetJobReturnData; // Run the simulation. string errorMessage = null; string simulationName = null; RunSimulation simulationRunner = null; try { simulationRunner = job.job as RunSimulation; // Replace datastore with a socket writer simulationRunner.Services = new object[] { new StorageViaSockets() }; // Run simulation simulationName = simulationRunner.simulationToRun.Name; simulationRunner.cloneSimulationBeforeRun = false; simulationRunner.Run(new CancellationTokenSource()); } catch (Exception err) { errorMessage = err.ToString(); } // Signal end of job. JobRunnerMultiProcess.EndJobArguments endJobArguments = new JobRunnerMultiProcess.EndJobArguments(); endJobArguments.key = job.key; endJobArguments.errorMessage = errorMessage; endJobArguments.simulationName = simulationName; SocketServer.CommandObject endJobCommand = new SocketServer.CommandObject() { name = "EndJob", data = endJobArguments }; SocketServer.Send("127.0.0.1", 2222, endJobCommand); // Get next job. response = GetNextJob(); } } catch (Exception err) { Console.WriteLine(err.ToString()); return(1); } finally { AppDomain.CurrentDomain.AssemblyResolve -= Manager.ResolveManagerAssembliesEventHandler; } return(0); }
/// <summary>Write all the data we stored</summary> private void WriteAllData() { SocketServer.CommandObject transferRowCommand = new SocketServer.CommandObject() { name = "TransferData", data = data }; SocketServer.Send("127.0.0.1", 2222, transferRowCommand); data.Clear(); }
public void WriteTable(DataTable data) { var rowData = new JobRunnerMultiProcess.TransferDataTable() { key = jobKey, data = data }; if (data.Rows.Count > 0) { SocketServer.CommandObject transferRowCommand = new SocketServer.CommandObject() { name = "TransferData", data = rowData }; SocketServer.Send("127.0.0.1", 2222, transferRowCommand); } }
/// <summary>Get the next job to run. Returns the job to run or null if no more jobs.</summary> private static object GetNextJob() { SocketServer.CommandObject command = new SocketServer.CommandObject() { name = "GetJob" }; object response = SocketServer.Send("127.0.0.1", 2222, command); if (response is string && response.ToString() == "NULL") { return(null); } while (response is string) { Thread.Sleep(300); response = SocketServer.Send("127.0.0.1", 2222, command); } return(response); }
/// <summary>Main program</summary> static int Main(string[] args) { try { AppDomain.CurrentDomain.AssemblyResolve += Manager.ResolveManagerAssembliesEventHandler; // Send a command to socket server to get the job to run. object response = GetNextJob(); while (response != null) { JobManagerMultiProcess.GetJobReturnData job = response as JobManagerMultiProcess.GetJobReturnData; // Run the simulation. string errorMessage = null; Simulation simulation = null; try { simulation = job.job as Simulation; simulation.Run(null, null); SocketServer.CommandObject transferDataCommand = new SocketServer.CommandObject() { name = "TransferData", data = DataStore.TablesToWrite }; SocketServer.Send("127.0.0.1", 2222, transferDataCommand); DataStore.TablesToWrite.Clear(); } catch (Exception err) { errorMessage = err.ToString(); } // Signal end of job. JobManagerMultiProcess.EndJobArguments endJobArguments = new JobManagerMultiProcess.EndJobArguments(); endJobArguments.key = job.key; endJobArguments.errorMessage = errorMessage; SocketServer.CommandObject endJobCommand = new SocketServer.CommandObject() { name = "EndJob", data = endJobArguments }; SocketServer.Send("127.0.0.1", 2222, endJobCommand); // Get next job. response = GetNextJob(); } //SocketServer.CommandObject transferDataCommand = new SocketServer.CommandObject() { name = "TransferData", data = DataStore.TablesToWrite }; //SocketServer.Send("127.0.0.1", 2222, transferDataCommand); } catch (SocketException) { // Couldn't connect to socket. Server not running? return(1); } catch (Exception err) { SocketServer.CommandObject command = new SocketServer.CommandObject() { name = "Error" }; command.data = err.ToString(); SocketServer.Send("127.0.0.1", 2222, command); return(1); } finally { AppDomain.CurrentDomain.AssemblyResolve -= Manager.ResolveManagerAssembliesEventHandler; } return(0); }
/// <summary>Main program</summary> static int Main(string[] args) { try { AppDomain.CurrentDomain.AssemblyResolve += Manager.ResolveManagerAssembliesEventHandler; // Send a command to socket server to get the job to run. object response = GetNextJob(); while (response != null) { JobRunnerMultiProcess.GetJobReturnData job = response as JobRunnerMultiProcess.GetJobReturnData; // Run the simulation. Exception error = null; string simulationName = null; StorageViaSockets storage = new StorageViaSockets(job.key); object[] services = new object[] { storage }; try { IRunnable jobToRun = job.job; if (jobToRun is RunSimulation) { RunSimulation simulationRunner = job.job as RunSimulation; // Replace datastore with a socket writer simulationRunner.Services = services; simulationName = simulationRunner.simulationToRun.Name; } else { Links links = new Links(services); links.Resolve(jobToRun); } jobToRun.Run(new CancellationTokenSource()); } catch (Exception err) { error = err; } // Signal we have completed writing data for this sim. storage.WriteAllData(); // Signal end of job. JobRunnerMultiProcess.EndJobArguments endJobArguments = new JobRunnerMultiProcess.EndJobArguments(); endJobArguments.key = job.key; if (error != null) { endJobArguments.errorMessage = error.ToString(); } endJobArguments.simulationName = simulationName; SocketServer.CommandObject endJobCommand = new SocketServer.CommandObject() { name = "EndJob", data = endJobArguments }; SocketServer.Send("127.0.0.1", 2222, endJobCommand); // Get next job. response = GetNextJob(); } } catch (Exception err) { Console.WriteLine(err.ToString()); return(1); } finally { AppDomain.CurrentDomain.AssemblyResolve -= Manager.ResolveManagerAssembliesEventHandler; } return(0); }