Exemplo n.º 1
0
        /// <summary>
        /// Main program entry point.
        /// </summary>
        static int Main(string[] args)
        {
            try
            {
                string fileName = null;
                string commandLineSwitch = null;

                // Check the command line arguments.
                if (args.Length >= 1)
                    fileName = args[0];
                if (args.Length == 2)
                    commandLineSwitch = args[1];
                if (args.Length < 1 || args.Length > 4)
                    throw new Exception("Usage: ApsimX ApsimXFileSpec [/Recurse] [/Network] [/IP:<server IP>]");

                // Create a instance of a job that will go find .apsimx files. Then
                // pass the job to a job runner.
                RunDirectoryOfApsimFiles runApsim = new RunDirectoryOfApsimFiles(fileName, commandLineSwitch);

                Stopwatch timer = new Stopwatch();
                timer.Start();

                int numSimulations = 0;
                if (commandLineSwitch == "/SingleThreaded")
                    numSimulations = RunSingleThreaded(fileName);
                else if (args.Contains("/Network"))
                {
                    try
                    {
                        int IPindex = -1;
                        for (int i = 0; i < args.Length;i++ )
                            if (args[i].Contains("IP"))
                            {
                                IPindex = i;
                                break;
                            }
                        if (IPindex == -1)
                            throw new Exception("/Network specified, but no IP given (/IP:<server IP>]");

                            DoNetworkRun(fileName, args[IPindex].Split(':')[1], args.Contains("/Recurse"));// send files over network
                    }
                    catch (SocketException)
                    {
                        Console.WriteLine("Connection to server terminated.");
                    }
                }
                else
                {
                    Utility.JobManager jobManager = new Utility.JobManager();
                    jobManager.OnComplete += OnError;
                    jobManager.AddJob(runApsim);
                    jobManager.Start(waitUntilFinished: true);
                    if (jobManager.SomeHadErrors)
                    {
                        Console.WriteLine("Errors found");
                        return 1;
                    }

                    // Write out the number of simulations run to the console.
                    numSimulations = jobManager.NumberOfJobs - 1;
                }
                timer.Stop();
                Console.WriteLine("Finished running " + numSimulations.ToString() + " simulations. Duration " + timer.Elapsed.TotalSeconds.ToString("#.00") + " sec.");
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
                return 1;
            }
            return 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Main program entry point.
        /// </summary>
        /// <param name="args"> Command line arguments</param>
        /// <returns> Program exit code (0 for success)</returns>
        public static int Main(string[] args)
        {
            int exitCode = 0 ;
            try
            {
                string fileName = null;
                string commandLineSwitch = null;

                // Check the command line arguments.
                if (args.Length >= 1)
                {
                    fileName = args[0];
                }

                if (args.Length == 2)
                {
                    commandLineSwitch = args[1];
                }

                if (args.Length < 1 || args.Length > 4)
                {
                    throw new Exception("Usage: ApsimX ApsimXFileSpec [/Recurse] [/Network] [/IP:<server IP>]");
                }

                Stopwatch timer = new Stopwatch();
                timer.Start();

                if (commandLineSwitch == "/SingleThreaded")
                    RunSingleThreaded(fileName);

                else if (args.Contains("/Network"))
                {
                    try
                    {
                        int indexOfIPArgument = -1;
                        for (int i = 0; i < args.Length; i++)
                        {
                            if (args[i].Contains("IP"))
                            {
                                indexOfIPArgument = i;
                                break;
                            }
                        }

                        if (indexOfIPArgument == -1)
                        {
                            throw new Exception("/Network specified, but no IP given (/IP:<server IP>]");
                        }

                        DoNetworkRun(fileName, args[indexOfIPArgument].Split(':')[1], args.Contains("/Recurse")); // send files over network
                    }
                    catch (SocketException)
                    {
                        Console.WriteLine("Connection to server terminated.");
                    }
                }
                else
                {
                    // Create a instance of a job that will go find .apsimx files. Then
                    // pass the job to a job runner.
                    RunDirectoryOfApsimFiles runApsim = new RunDirectoryOfApsimFiles();
                    runApsim.FileSpec = fileName;
                    runApsim.DoRecurse = args.Contains("/Recurse");
                    JobManager jobManager = new JobManager();
                    jobManager.AddJob(runApsim);
                    jobManager.Start(waitUntilFinished: true);

                    if (jobManager.SomeHadErrors)
                        exitCode = 1;
                    else
                        exitCode = 0;
                }

                timer.Stop();
                Console.WriteLine("Finished running simulations. Duration " + timer.Elapsed.TotalSeconds.ToString("#.00") + " sec.");
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
                exitCode = 1;
            }

            if (exitCode != 0)
                Console.WriteLine("ERRORS FOUND!!");
            return exitCode;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Main program entry point.
        /// </summary>
        /// <param name="args"> Command line arguments</param>
        /// <returns> Program exit code (0 for success)</returns>
        public static int Main(string[] args)
        {
            int exitCode = 0;

            try
            {
                string fileName          = null;
                string commandLineSwitch = null;

                // Check the command line arguments.
                if (args.Length >= 1)
                {
                    fileName = args[0];
                }

                if (args.Length == 2)
                {
                    commandLineSwitch = args[1];
                }

                if (args.Length < 1 || args.Length > 4)
                {
                    throw new Exception("Usage: ApsimX ApsimXFileSpec [/Recurse] [/Network] [/IP:<server IP>]");
                }

                Stopwatch timer = new Stopwatch();
                timer.Start();

                if (commandLineSwitch == "/SingleThreaded")
                {
                    RunSingleThreaded(fileName);
                }

                else if (args.Contains("/Network"))
                {
                    try
                    {
                        int indexOfIPArgument = -1;
                        for (int i = 0; i < args.Length; i++)
                        {
                            if (args[i].Contains("IP"))
                            {
                                indexOfIPArgument = i;
                                break;
                            }
                        }

                        if (indexOfIPArgument == -1)
                        {
                            throw new Exception("/Network specified, but no IP given (/IP:<server IP>]");
                        }

                        DoNetworkRun(fileName, args[indexOfIPArgument].Split(':')[1], args.Contains("/Recurse")); // send files over network
                    }
                    catch (SocketException)
                    {
                        Console.WriteLine("Connection to server terminated.");
                    }
                }
                else
                {
                    // Create a instance of a job that will go find .apsimx files. Then
                    // pass the job to a job runner.
                    RunDirectoryOfApsimFiles runApsim = new RunDirectoryOfApsimFiles();
                    runApsim.FileSpec  = fileName;
                    runApsim.DoRecurse = args.Contains("/Recurse");
                    JobManager jobManager = new JobManager();
                    jobManager.AddJob(runApsim);
                    jobManager.Start(waitUntilFinished: true);

                    if (runApsim.JobsRanOK())
                    {
                        exitCode = 0;
                    }
                    else
                    {
                        exitCode = 1;
                    }
                }

                timer.Stop();
                Console.WriteLine("Finished running simulations. Duration " + timer.Elapsed.TotalSeconds.ToString("#.00") + " sec.");
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
                exitCode = 1;
            }

            return(exitCode);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Main program entry point.
        /// </summary>
        static int Main(string[] args)
        {
            try
            {
                string fileName          = null;
                string commandLineSwitch = null;

                // Check the command line arguments.
                if (args.Length >= 1)
                {
                    fileName = args[0];
                }
                if (args.Length == 2)
                {
                    commandLineSwitch = args[1];
                }
                if (args.Length < 1 || args.Length > 4)
                {
                    throw new Exception("Usage: ApsimX ApsimXFileSpec [/Recurse] [/Network] [/IP:<server IP>]");
                }

                // Create a instance of a job that will go find .apsimx files. Then
                // pass the job to a job runner.
                RunDirectoryOfApsimFiles runApsim = new RunDirectoryOfApsimFiles(fileName, commandLineSwitch);

                Stopwatch timer = new Stopwatch();
                timer.Start();

                int numSimulations = 0;
                if (commandLineSwitch == "/SingleThreaded")
                {
                    numSimulations = RunSingleThreaded(fileName);
                }
                else if (args.Contains("/Network"))
                {
                    try
                    {
                        int IPindex = -1;
                        for (int i = 0; i < args.Length; i++)
                        {
                            if (args[i].Contains("IP"))
                            {
                                IPindex = i;
                                break;
                            }
                        }
                        if (IPindex == -1)
                        {
                            throw new Exception("/Network specified, but no IP given (/IP:<server IP>]");
                        }

                        DoNetworkRun(fileName, args[IPindex].Split(':')[1], args.Contains("/Recurse"));    // send files over network
                    }
                    catch (SocketException)
                    {
                        Console.WriteLine("Connection to server terminated.");
                    }
                }
                else
                {
                    Utility.JobManager jobManager = new Utility.JobManager();
                    jobManager.OnComplete += OnError;
                    jobManager.AddJob(runApsim);
                    jobManager.Start(waitUntilFinished: true);
                    if (jobManager.SomeHadErrors)
                    {
                        Console.WriteLine("Errors found");
                        return(1);
                    }

                    // Write out the number of simulations run to the console.
                    numSimulations = jobManager.NumberOfJobs - 1;
                }
                timer.Stop();
                Console.WriteLine("Finished running " + numSimulations.ToString() + " simulations. Duration " + timer.Elapsed.TotalSeconds.ToString("#.00") + " sec.");
            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());
                return(1);
            }
            return(0);
        }