Beispiel #1
0
        private void RecordDataSet(Core.Dom.Action action)
        {
            foreach (var item in action.outputData)
            {
                var options = item.allData.ToList();

                if (options.Count > 0)
                {
                    // Don't use the instance name here, we only pick the data set
                    // once per state, not each time the state is re-entered.
                    var rec = new DataSetTracker(item.modelName, options);

                    if (!_dataSets.Contains(item.modelName))
                    {
                        _dataSets.Add(rec);
                    }
                }
            }
        }
Beispiel #2
0
        private void RecordDataSet(Core.Dom.Action action)
        {
            if (action.dataSet != null)
            {
                DataSetTracker val = new DataSetTracker();
                foreach (var item in action.dataSet.Datas)
                {
                    switch (item.DataType)
                    {
                    case DataType.File:
                        val.options.Add(item);
                        break;

                    case DataType.Files:
                        val.options.AddRange(item.Files.Select(a => new Data()
                        {
                            DataType = DataType.File, FileName = a
                        }));
                        break;

                    case DataType.Fields:
                        val.options.Add(item);
                        break;

                    default:
                        throw new PeachException("Unexpected DataType: " + item.DataType.ToString());
                    }
                }

                if (val.options.Count > 0)
                {
                    // Need to properly support more than one action that are unnamed
                    string key = GetDataModelName(action);
                    System.Diagnostics.Debug.Assert(!_dataSets.ContainsKey(key));
                    _dataSets.Add(key, val);
                }
            }
        }
Beispiel #3
0
        private void SyncDataSet(Dom.Action action)
        {
            System.Diagnostics.Debug.Assert(_iteration != 0);

            // Only sync <Data> elements if the action has a data model
            if (action.dataModel == null)
            {
                return;
            }

            string         key = GetDataModelName(action);
            DataSetTracker val = null;

            if (!_dataSets.TryGetValue(key, out val))
            {
                return;
            }

            // If the last switch was within the current iteration range then we don't have to switch.
            uint switchIteration = GetSwitchIteration();

            if (switchIteration == val.iteration)
            {
                return;
            }

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

            DataModel dataModel = null;

            // Some of our sample files may not crack.  Loop through them until we
            // find a good sample file.
            while (val.options.Count > 0 && dataModel == null)
            {
                Data option = _randomDataSet.Choice(val.options);

                if (option.DataType == DataType.File)
                {
                    try
                    {
                        dataModel = ApplyFileData(action, option);
                    }
                    catch (CrackingFailure)
                    {
                        logger.Debug("Removing " + option.FileName + " from sample list.  Unable to crack.");
                        val.options.Remove(option);
                    }
                }
                else if (option.DataType == DataType.Fields)
                {
                    try
                    {
                        dataModel = AppleFieldData(action, option);
                    }
                    catch (PeachException)
                    {
                        logger.Debug("Removing " + option.name + " from sample list.  Unable to apply fields.");
                        val.options.Remove(option);
                    }
                }
            }

            if (dataModel == null)
            {
                throw new PeachException("Error, RandomStrategy was unable to load data for model \"" + action.dataModel.fullName + "\"");
            }

            // Set new data model
            action.dataModel = dataModel;

            // Generate all values;
            var ret = action.dataModel.Value;

            System.Diagnostics.Debug.Assert(ret != null);

            // Store copy of new origional data model
            action.origionalDataModel = action.dataModel.Clone() as DataModel;

            // Save our current state
            val.iteration = switchIteration;
        }