ATML1671Translator.translator.SignalMapper.Process C# (CSharp) Method

Process() public method

public Process ( byte aixmlDocument ) : void
aixmlDocument byte
return void
        public void Process(byte[] aixmlDocument)
        {
            Dictionary<string, dbTSFSignal> signalLookup = new Dictionary<string, dbTSFSignal>();
            string xmlMapping = CreateSignalMappingXml( aixmlDocument );
            SignalMapping mapping = XmlUtils.DeserializeObject<SignalMapping>(xmlMapping);
            if (mapping != null)
            {
                string modelName = mapping.ModelLibrary;
                string sourceType = mapping.SourceType;
                _usedSignalsList.Clear();
                dbTSFLibrary library = GetTestSignalLibrary( mapping.ModelLibrary );
                foreach (var noun in mapping.AtlasNouns )
                {
                    string nounName = noun.Name;
                    string tsfSignalName = noun.Tsf;
                    _usedSignalsList.Add( nounName );

                    SourceSignalMapBean mapBean = _signalMappingDao.GetMappedSignal(sourceType, nounName);
                    if (mapBean == null)
                    {
                        mapBean = new SourceSignalMapBean();
                        mapBean.DataState = BASEBean.eDataState.DS_ADD;
                    }
                    else
                    {
                        mapBean.DataState = BASEBean.eDataState.DS_EDIT;
                    }
                    mapBean.sourceName = nounName;
                    mapBean.sourceType = sourceType;
                    if (string.IsNullOrEmpty(mapBean.targetType))
                        mapBean.targetType = modelName;
                    if (string.IsNullOrEmpty(mapBean.targetName))
                        mapBean.targetName = tsfSignalName;
                    mapBean.save();

                    foreach (var modifier in noun.Modifiers)
                    {
                        SourceSignalAttributeMapBean attribute = _signalMappingDao.GetMappedSignalAttribute(
                            mapBean.id.ToString(), modifier.Name );
                        if (attribute == null)
                        {
                            attribute = new SourceSignalAttributeMapBean();
                            attribute.DataState = BASEBean.eDataState.DS_ADD;
                            attribute.mapId = mapBean.id;
                            attribute.sourceName = modifier.Name;
                            attribute.sourceSuffix = modifier.Suffix;
                            attribute.targetQualifier = modifier.Qualifier;
                            attribute.targetName = modifier.Attribute;
                            attribute.save();
                        }
                        else
                        {
                            attribute.DataState = BASEBean.eDataState.DS_EDIT;
                        }
                    }

                    if (!string.IsNullOrEmpty( tsfSignalName ))
                    {
                        List<TestSignalBean> signals = _signalDao.getTSFSignals( tsfSignalName );
                        foreach (TestSignalBean testSignalBean in signals)
                        {

                        }
                    }
                }

                if (library != null)
                {
                    //--- Create a lookup map for all the signals in the library ---//
                    foreach (dbTSFSignal tsfSignal in library.Signals)
                    {
                        if( !signalLookup.ContainsKey( tsfSignal.signalName ) )
                            signalLookup.Add(tsfSignal.signalName, tsfSignal);
                    }
                }
            }
        }

Usage Example

        private void btnBuildSignalMap_Click( object sender, EventArgs e )
        {
            try
            {
                HourGlass.Start();
                var mapper = new SignalMapper();
                //var xmlPath = (String) ATMLContext.GetProperty( "translator.parser.xml-path" );
                string projectName = ProjectManager.ProjectName;
                if (string.IsNullOrEmpty( projectName ))
                    throw new Exception( "You must open a project in order to map signals." );
                //string projectPath = Path.Combine( ATMLContext.TESTSET_PATH, projectName );
                string xmlPath = Path.Combine( ATMLContext.ProjectTranslatorAixmlPath, projectName + ".aixml.xml" );
                if (!File.Exists( xmlPath ))
                    throw new TranslationException( "Mapping Failed: Missing AIXML File." );

                mapper.Process( FileManager.ReadFile( xmlPath ) );

                var form = new ATMLSignalMappingForm( mapper.UsedSignalsList ) {TreeModel = SignalManager.Instance.TSFSignalTree};
                HourGlass.Stop();
                form.ShowDialog( this );
            }
            catch (Exception err)
            {
                LogManager.SourceError( ATMLTranslator.SOURCE, err );
            }
            finally
            {
                HourGlass.Stop();
            }
        }