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()); } }
/// <summary> /// Initializes a new instance of the <see cref="CastMethod" /> class. /// </summary> /// <param name="extendedType">Type of the extended.</param> /// <param name="info">The info.</param> /// <param name="isExplicit">if set to <see langword="true" /> [is explicit].</param> /// <remarks></remarks> internal CastMethod([NotNull] ExtendedType extendedType, [NotNull] MethodInfo info, bool isExplicit) : base(extendedType, info) { Debug.Assert(info.Name == "op_Explicit" || info.Name == "op_Implicit"); IsExplicit = isExplicit; // ReSharper disable once AssignNullToNotNullAttribute FromType = ParameterTypes.First(); Debug.Assert(FromType != null); ToType = ReturnType; Debug.Assert(FromType == extendedType.Type || ToType == extendedType.Type); }
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()); } }