void ReadXml() { AlgorithmList = new SortedSet <AlgorithmInfo>(new SortById()); if (!File.Exists(filePath)) { return; } XDocument doc = XDocument.Load(filePath); foreach (XElement element in doc.Root.Element("AlgorithmList").Elements()) { AlgorithmList.Add(AlgorithmInfoFactory.FromXml(element)); } }
public void Save() { XDocument doc = new XDocument(); doc.Add(new XElement("AlgorithmManager")); XElement xmlList = new XElement("AlgorithmList"); doc.Root.Add(xmlList); foreach (AlgorithmInfo info in AlgorithmList) { xmlList.Add(AlgorithmInfoFactory.ToXml(info)); } doc.Save(filePath); }
void AddClicked(object sender, EventArgs e) { Dialog dialog = new Dialog(); dialog.Title = "New algorithm info"; Table dialogContent = new Table(); dialog.Content = dialogContent; dialogContent.Add(new Label("Type:"), 0, 0); var typeCombo = new ComboBox(); foreach (var t in Enum.GetValues(typeof(AlgorithmType))) { typeCombo.Items.Add(t); } dialogContent.Add(typeCombo, 1, 0); dialog.Buttons.Add(new DialogButton(Command.Add)); dialog.Buttons.Add(new DialogButton(Command.Cancel)); var result = dialog.Run(this); if (result == Command.Add) { var newAlgorithm = AlgorithmInfoFactory.FromType((AlgorithmType)typeCombo.SelectedItem); newAlgorithm.Name = "New Algorithm"; newAlgorithm.Id = AlgorithmManager.Instance.AlgorithmList.Count; AlgorithmManager.Instance.AlgorithmList.Add(newAlgorithm); AlgorithmManager.Instance.Save(); UpdateList(sender, e); SelectAlgorithm(newAlgorithm); } dialog.Dispose(); }