Exemple #1
0
        private void SyncDataSet(Dom.Action action)
        {
            System.Diagnostics.Debug.Assert(_iteration != 0);

            // Compute the iteration we need to switch on
            uint switchIteration = GetSwitchIteration();

            foreach (var item in action.outputData)
            {
                // Note: use the model name, not the instance name so
                // we only set the data set once for re-enterant states.
                var modelName = item.modelName;

                if (!_dataSets.Contains(modelName))
                {
                    return;
                }

                var val = _dataSets[modelName];

                // If the last switch was within the current iteration range then we don't have to switch.
                if (switchIteration == val.Iteration)
                {
                    return;
                }

                // Don't switch files if we are only using a single file :)
                if (val.Options.Count < 2)
                {
                    return;
                }

                do
                {
                    var opt = _randomDataSet.Choice(val.Options);

                    try
                    {
                        // Apply the data set option
                        item.Apply(opt);

                        // Save off the last switch iteration
                        val.Iteration = switchIteration;

                        // Done!
                        return;
                    }
                    catch (PeachException ex)
                    {
                        logger.Debug(ex.Message);
                        logger.Debug("Unable to apply data '{0}', removing from sample list.", opt.name);
                        val.Options.Remove(opt);
                    }
                }while (val.Options.Count > 0);

                throw new PeachException("Error, RandomStrategy was unable to apply data for \"" + item.dataModel.fullName + "\"");
            }
        }