Esempio n. 1
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.
                    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);
        }
Esempio n. 2
0
        /// <summary>Run a simulation</summary>
        /// <param name="simulation">The simulation to run</param>
        /// <param name="doClone">Clone the simulation before running?</param>
        public void Run(Simulation simulation, bool doClone)
        {
            Apsim.ParentAllChildren(simulation);
            RunSimulation simulationRunner = new RunSimulation(this, simulation, doClone);

            Links.Resolve(simulationRunner);
            simulationRunner.Run(new System.Threading.CancellationTokenSource());
        }