public ILogFormat Create(Stream stream) { var savedPresets = Settings.Default.LexPresets ?? new XElement("Presets"); var presets = new List<LexPreset>( from element in savedPresets.Elements("Preset") select new LexPreset { Name = (string) element.Attribute("Name"), CommonCode = (string) element.Attribute("CommonCode"), SegmentCode = (string) element.Attribute("SegmentCode"), RecordCode = (string) element.Attribute("RecordCode") }); var selectView = new LexPresetsView(); var viewModel = selectView.ViewModel; foreach (var preset in presets) viewModel.Presets.Add(preset); viewModel.SelectedPreset = viewModel.Presets.FirstOrDefault(); viewModel.EditPreset = preset => { InvalidateCache(preset); ShowEditPresetDialog(selectView, stream, preset, presets.Select(x => x.Name)); }; viewModel.CreateNewPreset = () => { var preset = new LexPreset { Name = "New Preset", SegmentCode = "%%", RecordCode = "%%" }; return ShowEditPresetDialog(selectView, stream, preset, presets.Select(x => x.Name)) ? preset : null; }; if (selectView.ShowDialog() != true) return null; Settings.Default.LexPresets = new XElement("Presets", from preset in viewModel.Presets select new XElement("Preset", new XAttribute("Name", preset.Name), new XAttribute("CommonCode", preset.CommonCode), new XAttribute("SegmentCode", preset.SegmentCode), new XAttribute("RecordCode", preset.RecordCode))); Settings.Default.Save(); var selectedPreset = selectView.ViewModel.SelectedPreset; if (selectedPreset == null) return null; if (selectedPreset.Format != null) return selectedPreset.Format; return Compile(selectedPreset) ?? CompileManually(selectView, stream, selectedPreset); }
public ILogFormat Create(Stream stream) { var savedPresets = Settings.Default.LexPresets ?? new XElement("Presets"); var presets = new List <LexPreset>( from element in savedPresets.Elements("Preset") select new LexPreset { Name = (string)element.Attribute("Name"), CommonCode = (string)element.Attribute("CommonCode"), SegmentCode = (string)element.Attribute("SegmentCode"), RecordCode = (string)element.Attribute("RecordCode") }); var selectView = new LexPresetsView(); var viewModel = selectView.ViewModel; foreach (var preset in presets) { viewModel.Presets.Add(preset); } viewModel.SelectedPreset = viewModel.Presets.FirstOrDefault(); viewModel.EditPreset = preset => { InvalidateCache(preset); ShowEditPresetDialog(selectView, stream, preset, presets.Select(x => x.Name)); }; viewModel.CreateNewPreset = () => { var preset = new LexPreset { Name = "New Preset", SegmentCode = "%%", RecordCode = "%%" }; return(ShowEditPresetDialog(selectView, stream, preset, presets.Select(x => x.Name)) ? preset : null); }; if (selectView.ShowDialog() != true) { return(null); } Settings.Default.LexPresets = new XElement("Presets", from preset in viewModel.Presets select new XElement("Preset", new XAttribute("Name", preset.Name), new XAttribute("CommonCode", preset.CommonCode), new XAttribute("SegmentCode", preset.SegmentCode), new XAttribute("RecordCode", preset.RecordCode))); Settings.Default.Save(); var selectedPreset = selectView.ViewModel.SelectedPreset; if (selectedPreset == null) { return(null); } if (selectedPreset.Format != null) { return(selectedPreset.Format); } return(Compile(selectedPreset) ?? CompileManually(selectView, stream, selectedPreset)); }