public static void Run(string batchFilename)
        {
            if (batchFilename == null)
            {
                Console.WriteLine("Error. Missing argument: -batch");
                return;
            }

            if (!File.Exists(batchFilename))
            {
                Console.WriteLine("Error. File doesn't exist: " + batchFilename);
                return;
            }

            Console.WriteLine("Cleaning batch file: " + batchFilename);
            int numDeleted = ExperimentBatch.DeleteLogFiles(batchFilename);

            Console.WriteLine("{0} files deleted", numDeleted);
        }
示例#2
0
        public static void Run(string batchFilename, bool onlyUnfinished)
        {
            if (batchFilename == null)
            {
                Console.WriteLine("Error. Missing argument: -batch");
                return;
            }

            if (!File.Exists(batchFilename))
            {
                Console.WriteLine("Error. File doesn't exist: " + batchFilename);
                return;
            }

            //All the experimental units or only unfinished???
            LoadOptions loadOptions = new LoadOptions();

            if (onlyUnfinished)
            {
                loadOptions.Selection = LoadOptions.ExpUnitSelection.OnlyUnfinished;
            }
            else
            {
                loadOptions.Selection = LoadOptions.ExpUnitSelection.All;
            }

            Console.WriteLine("Running batch file: " + batchFilename);
            g_writer = System.IO.File.CreateText("log.txt");
            ExperimentBatch batch = new ExperimentBatch();

            batch.Load(batchFilename, loadOptions);

            NumUnfinishedExpUnits = batch.CountExperimentalUnits();
            NumTotalExpUnits      = NumUnfinishedExpUnits;
            if (NumUnfinishedExpUnits == 0)
            {
                Console.WriteLine("Finished: No experimental unit to be run");
                return;
            }
            else
            {
                Console.SetCursorPosition(0, experimentStatsLine);
                Console.WriteLine("Experimental units:");
                UpdateExperimentStats();
            }
            Console.SetCursorPosition(0, herdAgentsLine);
            Console.Write("Herd agents:");
            Shepherd shepherd = new Shepherd();

            shepherd.CallHerd();

            Thread.Sleep(2000);

            List <HerdAgentInfo> herdAgents = new List <HerdAgentInfo>();

            shepherd.GetHerdAgentList(ref herdAgents);

            Console.SetCursorPosition(herdAgentsRow, herdAgentsLine);
            Console.WriteLine("{0} available", herdAgents.Count);

            if (herdAgents.Count == 0)
            {
                Console.WriteLine("Error: no herd agents found to run the experiment batch");
            }

            Console.Write("Total progress: ");

            List <ExperimentalUnit> experiments = new List <ExperimentalUnit>();

            foreach (Experiment exp in batch.Experiments)
            {
                experiments.AddRange(exp.ExperimentalUnits);
            }
            CancellationTokenSource cancelSource = new CancellationTokenSource();

            Monitoring.MsgDispatcher dispatcher = new Monitoring.MsgDispatcher(OnJobAssigned, OnJobFinished
                                                                               , DispatchOnAllStatesChanged, DispatchOnStateChanged
                                                                               , DispatchOnMessageReceived, DispatchOnExperimentalUnitLaunched
                                                                               , Log, cancelSource.Token);

            int numExecutedExperimentalUnits =
                JobDispatcher.RunExperimentsAsync(experiments, herdAgents, dispatcher, cancelSource).Result;

            Console.SetCursorPosition(0, resultLine);
            Console.WriteLine("Badger finished: " + numExecutedExperimentalUnits + " experimental units were succesfully run");

            g_writer.Close();
        }