/// <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>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); }