Пример #1
0
        /// <summary>
        ///     Initializes the experiments to be monitored through a batch file that
        ///     contains all required data for the task.
        /// </summary>
        /// <param name="batchFileName">The batch file with experiment data</param>
        public bool LoadExperimentBatch(string batchFileName)
        {
            //Load unfinished experiments
            LoadOptions loadOptionsUnfinished = new LoadOptions()
            {
                Selection          = LoadOptions.ExpUnitSelection.OnlyUnfinished,
                LoadVariablesInLog = false
            };

            ExperimentBatch batchUnfinished = new ExperimentBatch();

            batchUnfinished.Load(batchFileName, loadOptionsUnfinished);

            LoggedExperiments.Clear();
            foreach (Experiment experiment in batchUnfinished.Experiments)
            {
                LoggedExperimentViewModel newExperiment = new LoggedExperimentViewModel(experiment);
                LoggedExperiments.Add(newExperiment);
            }
            //count unfinished experiments
            int numUnfinishedExperimentalUnits = batchUnfinished.CountExperimentalUnits();

            //load all experimental units and count them
            LoadOptions loadOptionsFinished = new LoadOptions()
            {
                Selection          = LoadOptions.ExpUnitSelection.OnlyFinished,
                LoadVariablesInLog = false
            };

            //we use a temp variable first to get the count of finished units so that setting the value of NumFinishedExperimentalUnitsBeforeStart triggers the progress update
            //AFTER setting the value of NumExperimentalUnits
            NumFinishedExperimentalUnitsBeforeStart = ExperimentBatch.CountExperimentalUnits(batchFileName, LoadOptions.ExpUnitSelection.OnlyFinished);
            NumExperimentalUnits = numUnfinishedExperimentalUnits + NumFinishedExperimentalUnitsBeforeStart;
            NumFinishedExperimentalUnitsAfterStart = 0;

            //Initialize pending experiment list
            m_pendingExperiments.Clear();

            foreach (var experiment in LoggedExperiments)
            {
                foreach (AppVersion version in experiment.AppVersions)
                {
                    if (!ExistsRequiredFile(version.ExeFile))
                    {
                        CaliburnUtility.ShowWarningDialog("Cannot find required file: " + version.ExeFile + ". Check the app definition file in /config/apps", "ERROR");
                        return(false);
                    }
                    foreach (string pre in version.Requirements.InputFiles)
                    {
                        if (!ExistsRequiredFile(pre))
                        {
                            CaliburnUtility.ShowWarningDialog("Cannot find required file: " + pre + ". Check the app definition file in /config/apps", "ERROR");
                            return(false);
                        }
                    }
                }
                foreach (LoggedExperimentalUnitViewModel unit in experiment.ExperimentalUnits)
                {
                    m_pendingExperiments.Add(unit.Model);
                }
            }

            BatchFileName = batchFileName;
            Plot.ClearLineSeries();
            AllMonitoredJobs.Clear();
            IsBatchLoaded = true;
            IsRunning     = false;

            return(true);
        }
Пример #2
0
        /// <summary>
        ///     Load an experiment from a batch file. If <paramref name="batchFileName"/> is either
        ///     null or empty, a dialog window will be opened to let the user select a batch file.
        /// </summary>
        /// <param name="batchFileName">The name of the file to load</param>
        public void LoadExperimentBatch(string batchFileName)
        {
            //Ask the user for the name of the batch
            if (string.IsNullOrEmpty(batchFileName))
            {
                bool bSuccess = Files.OpenFileDialog(ref batchFileName
                                                     , Files.ExperimentBatchDescription, Files.ExperimentBatchFilter);
                if (!bSuccess)
                {
                    return;
                }
            }

            //reset the view if a batch was succesfully selected
            ClearReportViewer();

            //Inefficient but not so much as to care
            //First we load the batch file to cout how many experimental units we have
            StartLongOperation();
            LoadedBatch = "Reading batch file";

            //first count the total number of experimental units
            m_numExperimentalUnits = ExperimentBatch.CountExperimentalUnits(batchFileName, LoadOptions.ExpUnitSelection.All);

            Task.Run(() =>
            {
                //load finished experimental units from the batch
                LoadOptions loadOptions = new LoadOptions()
                {
                    Selection          = LoadOptions.ExpUnitSelection.OnlyFinished,
                    LoadVariablesInLog = true,
                    OnExpUnitLoaded    = OnExperimentalUnitProcessed
                };

                LoadedBatch           = "Reading experiment files";
                ExperimentBatch batch = new ExperimentBatch();
                batch.Load(batchFileName, loadOptions);

                //Create ViewModels from LoggedExperimentBatch
                foreach (Experiment experiment in batch.Experiments)
                {
                    LoggedExperimentViewModel newExperiment
                        = new LoggedExperimentViewModel(experiment);

                    LoggedExperiments.Add(newExperiment);
                    ExperimentalUnits.AddRange(newExperiment.ExperimentalUnits);
                    Query.AddLogVariables(newExperiment.VariablesInLog);
                    ForksLoaded |= newExperiment.Forks.Count > 0;

                    newExperiment.TraverseAction(true, (n) =>
                    {
                        if (n is LoggedForkViewModel fork)
                        {
                            fork.PropertyChanged += OnChildPropertyChanged;
                        }
                    });
                }

                //Update flags use to enable/disable parts of the report generation menu
                NotifyOfPropertyChange(() => ForksLoaded);
                NotifyOfPropertyChange(() => VariablesLoaded);

                LoadedBatch = batchFileName;
                LogsLoaded  = true;

                EndLongOperation();
            });
        }