Beispiel #1
0
        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());
            }
        }
Beispiel #2
0
 private void ClearData()
 {
     _model              = null;
     _openFile           = null;
     _manufacturerData   = null;
     _hardware           = null;
     _product            = null;
     _catalogItem        = null;
     _catalogSection     = null;
     _applicationProgram = null;
     _hardware2Program   = null;
     _appProgRef         = null;
     _codeSegment        = null;
     _parameterBlock     = null;
     Parameters.Clear();
     RaiseChanged();
 }
Beispiel #3
0
        private void CreateNew(object param)
        {
            try
            {
                if (_model != null)
                {
                    var cancel = AskSaveCancel();
                    if (cancel)
                    {
                        return;
                    }
                }

                _model = new KNX();

                string lang = Thread.CurrentThread.CurrentCulture.Name;

                _manufacturerData   = new ManufacturerData_tManufacturer();
                _applicationProgram = new ApplicationProgram_t();
                _hardware           = new Hardware_t();
                _catalogSection     = new CatalogSection_t();
                _product            = new Hardware_tProduct();
                _hardware2Program   = new Hardware2Program_t();
                _appProgRef         = new ApplicationProgramRef_t();
                _catalogItem        = new CatalogSection_tCatalogItem();

                _model.ManufacturerData.Add(_manufacturerData);
                _manufacturerData.Catalog.Add(_catalogSection);
                _manufacturerData.ApplicationPrograms.Add(_applicationProgram);
                _manufacturerData.Hardware.Add(_hardware);
                _hardware.Products.Add(_product);
                _hardware.Hardware2Programs.Add(_hardware2Program);
                _hardware2Program.ApplicationProgramRef.Add(_appProgRef);
                _catalogSection.CatalogItem.Add(_catalogItem);


                _model.CreatedBy   = _toolName;
                _model.ToolVersion = _toolVersion;

                ApplicationNumber  = 0;
                ApplicationVersion = 0;
                _applicationProgram.ProgramType            = ApplicationProgramType_t.ApplicationProgram;
                _applicationProgram.MaskVersion            = "MV-57B0";
                _applicationProgram.LoadProcedureStyle     = LoadProcedureStyle_t.MergedProcedure;
                _applicationProgram.PeiType                = 0;
                _applicationProgram.DefaultLanguage        = lang;
                _applicationProgram.DynamicTableManagement = false;
                _applicationProgram.Linkable               = false;
                _applicationProgram.MinEtsVersion          = "4.0";

                var appStatic = new ApplicationProgramStatic_t();
                _applicationProgram.Static = appStatic;

                var code = new ApplicationProgramStatic_tCode();
                appStatic.Code = code;

                _codeSegment = new ApplicationProgramStatic_tCodeRelativeSegment();
                code.RelativeSegment.Add(_codeSegment);
                _codeSegment.Name             = "Parameters";
                _codeSegment.Offset           = 0;
                _codeSegment.LoadStateMachine = 4;
                _codeSegment.Size             = 0;

                appStatic.AddressTable            = new ApplicationProgramStatic_tAddressTable();
                appStatic.AddressTable.MaxEntries = 255;

                appStatic.AssociationTable            = new ApplicationProgramStatic_tAssociationTable();
                appStatic.AssociationTable.MaxEntries = 255;
                appStatic.ComObjectTable = new ApplicationProgramStatic_tComObjectTable();
                appStatic.Options        = new ApplicationProgramStatic_tOptions();

                HardwareSerial  = "0";
                HardwareVersion = 0;
                _hardware.HasIndividualAddress  = true;
                _hardware.HasApplicationProgram = true;
                _hardware.IsIPEnabled           = true;

                _product.IsRailMounted   = false;
                _product.DefaultLanguage = lang;
                OrderNumber = "0";

                _hardware2Program.MediumTypes.Add("MT-5");

                _catalogSection.Name            = Ressources.Devices;
                _catalogSection.Number          = "1";
                _catalogSection.DefaultLanguage = lang;

                _catalogItem.Name                  = _product.Text;
                _catalogItem.Number                = 1;
                _catalogItem.ProductRefId          = _product.Id;
                _catalogItem.Hardware2ProgramRefId = _hardware2Program.Id;
                _catalogItem.DefaultLanguage       = lang;

                RaiseChanged();
            }
            catch (Exception ex)
            {
                _dialogService.ShowMessage(ex.ToString());
                ClearData();
            }
        }