private void Open(object param) { try { if (_model != null) { var cancel = AskSaveCancel(); if (cancel) { return; } } var filePath = _dialogService.ChooseFileToOpen(_fileExtension, _fileFilter); if (filePath == null) { return; } _openFile = filePath; XmlSerializer serializer = new XmlSerializer(typeof(KNX)); using (var reader = new StreamReader(_openFile)) { _model = (KNX)serializer.Deserialize(reader); } _manufacturerData = _model.ManufacturerData.First(); _hardware = _manufacturerData.Hardware.First(); _product = _hardware.Products.First(); _catalogSection = _manufacturerData.Catalog.First(); _catalogItem = _catalogSection.CatalogItem.First(); _hardware2Program = _hardware.Hardware2Programs.First(); _applicationProgram = _manufacturerData.ApplicationPrograms.First(); _appProgRef = _hardware2Program.ApplicationProgramRef.First(); _codeSegment = _applicationProgram.Static.Code.RelativeSegment.First(); var parameterList = _applicationProgram.Static.Parameters.OfType <Parameter_t>(); foreach (var item in parameterList) { item.AllTypes = ParameterTypes; item.Type = ParameterTypes.First(t => t.Id == item.ParameterType); Parameters.Add(item); } RaiseChanged(); } catch (Exception ex) { ClearData(); _dialogService.ShowMessage(ex.ToString()); } }
private void Open(object param) { try { if (_model != null) { var cancel = AskSaveCancel(); if (cancel) { return; } } var filePath = _dialogService.ChooseFileToOpen(_fileExtension, _fileFilter); if (filePath == null) { return; } _openFile = filePath; XmlSerializer serializer = new XmlSerializer(typeof(KNX)); using (var reader = new StreamReader(_openFile)) { _model = (KNX)serializer.Deserialize(reader); } if (File.Exists("knx_master.xml")) { using (var reader = new StreamReader("knx_master.xml")) { var masterData = (KNX)serializer.Deserialize(reader); _model.MasterData = masterData.MasterData; } } _manufacturerData = _model.ManufacturerData.First(); _hardware = _manufacturerData.Hardware.First(); _product = _hardware.Products.First(); _catalogSection = _manufacturerData.Catalog.First(); _catalogItem = _catalogSection.CatalogItem.First(); _hardware2Program = _hardware.Hardware2Programs.First(); _applicationProgram = _manufacturerData.ApplicationPrograms.First(); _appProgRef = _hardware2Program.ApplicationProgramRef.First(); _codeSegment = _applicationProgram.Static.Code.RelativeSegment.First(); Parameters.Clear(); foreach (var item in _applicationProgram.Static.Parameters.Parameter) { item.AllTypes = ParameterTypes; item.Type = ParameterTypes.First(t => t.Id == item.ParameterType); item.AllBlocks = ParameterBlock; item.Block = ParameterBlock.FirstOrDefault(t => t.ParameterRefRef.FirstOrDefault(o => _applicationProgram.Static.ParameterRefs.FirstOrDefault(p => o.RefId == p.Id)?.RefId == item.Id) != null); if (item.Block == null) { if (ParameterBlock.Count == 0) { CreateDefaultParameterBlock(); } item.Block = ParameterBlock.First(); } Parameters.Add(item); } RaiseChanged(); } catch (Exception ex) { ClearData(); _dialogService.ShowMessage(ex.ToString()); } }