public ExperimentSummary GetOrCreateExperiment(string experimentName, string conversionKeyword,
IEnumerable<string> options)
{
var xml = Load();
var existingExperiment = xml.Root.Elements("Experiment")
.SingleOrDefault(x => x.Attribute("Name").Value == experimentName);
if (existingExperiment != null)
return new ExperimentSummary(
existingExperiment.Attribute("Name").Value,
existingExperiment.Attribute("AlwaysUseOption") == null
? null
: existingExperiment.Attribute("AlwaysUseOption").Value,
existingExperiment.Attribute("Ended") != null
);
var exp = new XElement("Experiment",
new XAttribute("Name", experimentName),
new XAttribute("Started", UtcNow),
new XElement("PossibleOptionValues",
options.Select(o => new XElement("Option", new XCData(o)))
)
);
if (experimentName != conversionKeyword)
exp.Add(new XAttribute("ConversionKeyword", conversionKeyword));
xml.Root.Add(exp);
Save(xml);
return new ExperimentSummary(experimentName, null, false);
}