예제 #1
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;
     Parameters.Clear();
     RaiseChanged();
 }
예제 #2
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);
                }

                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();

                var parameterList = _applicationProgram.Static.Parameters.Parameter;

                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());
            }
        }
예제 #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_TProductsProduct();
                _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          = "5.0";
                _applicationProgram.ReplacesVersions       = null;
                _applicationProgram.IsSecureEnabled        = false;
                _applicationProgram.MaxSecurityIndividualAddressEntries = 32;
                _applicationProgram.MaxSecurityGroupKeyTableEntries     = 50;

                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.Parameters              = new ApplicationProgramStatic_TParameters();
                appStatic.AddressTable            = new ApplicationProgramStatic_TAddressTable();
                appStatic.AddressTable.MaxEntries = ushort.MaxValue;

                appStatic.AssociationTable            = new ApplicationProgramStatic_TAssociationTable();
                appStatic.AssociationTable.MaxEntries = ushort.MaxValue;
                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");
                _hardware2Program.MediumTypes.Add("MT-2");

                _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();
            }
        }