Esempio n. 1
0
        [STAThread] //Runs faster with the tag, but seems to have some issue with exiting
        static void Main(string[] args)
        {
            string xmlInputFile;
            string mapOutputDirectory;
            string textOutputDir;
            string xmlBackup;

#if DEBUG
            Console.WriteLine("calling check license");
#endif

            CheckLicense();
            frmInput f = new frmInput();

#if DEBUG
            Console.WriteLine("calling LoadArgs");
#endif
            LoadArgs(args, out xmlInputFile, out mapOutputDirectory, out textOutputDir, out xmlBackup);
#if DEBUG
            Console.WriteLine("Calling DoBackUpLoad");
#endif
            BackUpParams backupParms = DoBackUpLoad(args, mapOutputDirectory, textOutputDir);
#if DEBUG
            Console.WriteLine("Calling DoRun");
#endif
            f.doRun(xmlInputFile, mapOutputDirectory, textOutputDir, xmlBackup, backupParms);

            //ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown();
            System.Environment.Exit(0);

            //thisProc.Kill();
            //Console.WriteLine("End of program");
        }
Esempio n. 2
0
        /********************************************************************************
         *  Function name   : doSimulation
         *  Description     : Contains the main loop for the simulation
         *  Return type     : void
         * *******************************************************************************/
        public void doSimulation(BackUpParams inParams) // Boolean backupSave, string backupSaveName, int backupSaveInterval, char backupSaveUnit, int backupSaveCount, Boolean backupLoad, string backupdir)
        {                                               //frmInput inForm,
            mLog.Debug("inside sim manager do simulation calling initialize daily sim");
            initializeSimulation();

            DateTime nextTime;
            TimeSpan addTime;

            //Sets up the timed saved intervals
            switch (inParams.backupSaveUnit)
            {
            case 'm':
                addTime = new TimeSpan(0, inParams.backupSaveInterval, 0);
                break;

            case 'h':
                addTime = new TimeSpan(inParams.backupSaveInterval, 0, 0);
                break;

            case 'd':
                addTime = new TimeSpan(inParams.backupSaveInterval, 0, 0, 0);
                break;

            default:
                addTime = new TimeSpan();
                break;
            }
            nextTime = DateTime.Now.Add(addTime);

            //Loads a Backup
            if (inParams.backupLoad)
            {
                //  this.loadBackup(backupdir);
                this.MapManager.CurrTime = this.currTime;
            }
            else
            {
                // this needs to initialize to 0 if we aren't resuming from backup
                this.currSeason          = 0;
                this.currTime            = this.mStartSeasonDate;
                this.currTime            = this.currTime.AddHours(this.AnimalManager.AnimalAttributes.WakeUpTime);
                this.MapManager.CurrTime = this.currTime;
            }

            mLog.Debug("now start the big loop for the sim");

            //Start the simulation loop
            for (; this.currSeason < this.mNumSeasons; this.currSeason++)
            {
                // Heartbeat - is the program still running?
                Console.WriteLine("Season: " + currSeason + "/" + this.mNumSeasons);

                mLog.Debug("starting a season");
                mLog.Debug("currDate is " + this.currTime.ToShortDateString());
                mLog.Debug("end season date is " + this.EndSeasonDate.ToShortDateString());
                Console.WriteLine("Currtime: {0} EndSeasonDate: {1}", currTime, this.EndSeasonDate);
                Console.Write("Run time is " + DateTime.Now.ToShortTimeString());

                while (currTime < this.EndSeasonDate)
                {
                    if (inParams.backupSave)
                    {
                        if (inParams.backupSaveUnit == 'i' && !inParams.backupLoad)
                        {
                            // Create backups every backupSaveInterval iterations
                            if ((this.iteration % inParams.backupSaveInterval) == (inParams.backupSaveInterval - 1))
                            {
                                this.createBackup(inParams.backupSaveName, inParams.backupSaveCount);
                            }
                        }
                        else
                        {
                            inParams.backupLoad = false;
                            if (DateTime.Now.Ticks > nextTime.Ticks)
                            {
                                this.createBackup(inParams.backupSaveName, inParams.backupSaveCount);
                                nextTime = DateTime.Now.Add(addTime);
                            }
                        }
                    }

                    // advance iteration count for iteration-based saving, since simulation doesn't run on an explicit iteration counter
                    this.iteration++;
                    // Heartbeat - is the program still running?

                    Console.WriteLine("Time: " + currTime + " leading to " + this.EndSeasonDate + " iteration:" + this.iteration);

                    this.doTimeStep();   // changes the modifiers, update animal manager.
                    this.currTimeStep++; // used for progress bar update.
                    // t = t + dt
                    this.currTime = this.currTime.AddMinutes(this.mElapsedTimeBetweenTimeStep);
                    if (currTime.Hour == 0)
                    {
                        initializeDailySimulation();
                        //this.upDateForm(ref inForm);
                    }
                }

                //now reset the year and advance by a year
                mLog.Debug("done with one season now addvance throuout the year");
                mLog.Debug("currDate is " + this.currTime.ToShortDateString());
                this.currTime      = this.mStartSeasonDate.AddYears(currSeason + 1);
                this.currTime      = this.currTime.AddHours(this.AnimalManager.AnimalAttributes.WakeUpTime);
                this.EndSeasonDate = this.EndSeasonDate.AddYears(1);
                mLog.Debug("now the currDate is " + this.currTime.ToShortDateString());
                mLog.Debug("calling initialize yearly sim");
                initializeYearlySimulation();
                mLog.Debug("done with initializing yearly sim");
                mLog.Debug("");
                mLog.Debug("Curr season is " + currSeason);
                mLog.Debug("NumSeasons is " + mNumSeasons);
                mLog.Debug("");
            }
            // this.mMapManager.removeExtraFiles();

            mLog.Debug("FINISHED SIM LOOP!");
        }
Esempio n. 3
0
        private static BackUpParams DoBackUpLoad(string[] args, string mapOutputDirectory, string textOutputDir)
        {
            BackUpParams backupParms = new BackUpParams();

            // Parse optional command line arguments if they exist
            try
            {
                if (args.Length > 3)
                {
                    for (int i = 3; i < args.Length; i++)
                    {
                        //if checkpointing
                        if (args[i].ToLower() == "-c")
                        {
                            backupParms.backupSave         = true;
                            backupParms.backupSaveInterval = int.Parse(args[i + 1]);
                            backupParms.backupSaveUnit     = 'z';
                            switch (args[i + 2].ToLower())
                            {
                            case "i":
                                backupParms.backupSaveUnit = 'i';
                                break;

                            case "m":
                                backupParms.backupSaveUnit = 'm';
                                break;

                            case "h":
                                backupParms.backupSaveUnit = 'h';
                                break;

                            case "d":
                                backupParms.backupSaveUnit = 'd';
                                break;
                            }

                            backupParms.backupSaveName = args[i + 3];
                            if (backupParms.backupSaveUnit == 'z')
                            {
                                throw new Exception("backup save unit must be i, m, h, or d");
                            }
                            if (backupParms.backupSaveInterval < 1)
                            {
                                throw new Exception("backup save interval must be greater than 0");
                            }
                        }
                        //if loading
                        if (args[i].ToLower() == "-l")
                        {
                            backupParms.backupLoad = true;
                            backupParms.backupdir  = args[i + 1];
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine("Incorrect backup configuration");
                usage();
                Environment.Exit(-1);
            }

            //When reloading, delete the directory if it exists, and remake it.
            if (System.IO.Directory.Exists(mapOutputDirectory) && System.IO.Directory.Exists(textOutputDir) && System.IO.Directory.Exists(backupParms.backupdir))
            {
                if (backupParms.backupLoad)
                {
                    if (mapOutputDirectory == textOutputDir)
                    {
                        Directory.GetFiles(mapOutputDirectory, "*", SearchOption.AllDirectories);
                        System.IO.Directory.Delete(mapOutputDirectory, true);
                        dirCopy(backupParms.backupdir, mapOutputDirectory);
                    }
                    else
                    {
                        System.IO.Directory.Delete(mapOutputDirectory, true);
                        System.IO.Directory.Delete(textOutputDir, true);
                        dirCopy(backupParms.backupdir, mapOutputDirectory);
                        System.IO.Directory.CreateDirectory(textOutputDir);
                    }
                }
                else
                {
                    Console.WriteLine("Warning: Directory already exist");
                    Environment.Exit(0);
                }
            }
            else if (System.IO.Directory.Exists(backupParms.backupdir))
            {
                if (backupParms.backupLoad)
                {
                    if (mapOutputDirectory == textOutputDir)
                    {
                        dirCopy(backupParms.backupdir, mapOutputDirectory);
                    }
                    else
                    {
                        dirCopy(backupParms.backupdir, mapOutputDirectory);
                        System.IO.Directory.CreateDirectory(textOutputDir);
                    }
                }
            }
            return(backupParms);
        }