getSignal() public method

public getSignal ( int signalId ) : dbSignal
signalId int
return ATMLDataAccessLibrary.model.dbSignal
 private bool LoadSignalModel(dbSignal dbsignal)
 {
     bool loaded = false;
     if (dbsignal != null)
     {
         var dao = new SignalDAO();
         dbsignal = dao.getSignal(dbsignal.signalId);
         _currentSignalModel = SignalManager.GetSignalModel(dbsignal.xmlns, dbsignal.signalName);
         LoadSignalModel(_currentSignalModel);
         loaded = true;
     }
     return loaded;
 }
        private void signalComboBox_SelectedIndexChanged( object sender, EventArgs e )
        {
            try
            {
                HourGlass.Enabled = true;
                SignalModel signalModel = awbDropListTree.SelectedSignalModel;
                if (signalModel != null )
                {
                    var signal = signalModel.Signal;  //signalComboBox.SelectedItem as dbSignal;
                    if (signal != null)
                    {
                        //---------------------------------------------------//
                        //--- Find "name" in data grid and set it's value ---//
                        //---------------------------------------------------//
                        foreach (DataGridViewRow row in signalAttributes.Rows)
                        {
                            if (row.IsNewRow)
                                continue;

                            var name = row.Cells[0].Value as string;
                            var type = row.Cells[1].Value as string;
                            var value = row.Cells[2].Value as string;
                            if ("type".Equals( name ))
                            {
                                row.Cells[1].Value = edtName.Text;
                                break;
                            }
                        }
                        signalAttributes.Rows.Clear();

                        if (string.IsNullOrEmpty( edtName.Text ))
                            edtName.Text = signal.name;
                        var dao = new SignalDAO();
                        dbSignal dataSignal = dao.getSignal( signal.name, signalModel.SignalNameSpace );

                        string xmlns = signalModel.SignalNameSpace;
                        XmlSchemaComplexType complexType;
                        XmlSchemaElement element = null;
                        SchemaManager.GetComplexType( xmlns, signal.name, out complexType );
                        if (complexType == null)
                            SchemaManager.GetElement( xmlns, signal.name, out element );
                        if (complexType != null || element != null)
                        {
                            signalAttributes.Rows.Clear();
                            List<XmlSchemaAttribute> schemaAttributes = complexType != null
                                                                            ? SchemaManager.GetAttributes( complexType )
                                                                            : SchemaManager.GetAttributes( element );
                            List<dbSignalAttribute> dbAttributes = dao.getAllSignalAttributes( signal.name, signalModel.SignalNameSpace );
                            var foundAttributes = new Dictionary<string, dbSignalAttribute>();
                            foreach (dbSignalAttribute attribute in dbAttributes)
                            {
                                foundAttributes.Add( attribute.attributeName, attribute );
                                object value = null;
                                try
                                {
                                    if (_signalFunctionType != null)
                                    {
                                        PropertyInfo pi =
                                            _signalFunctionType.GetType().GetProperty( attribute.attributeName );
                                        if (pi != null)
                                            value = pi.GetValue( _signalFunctionType, null );
                                    }
                                }
                                catch (Exception err)
                                {
                                    LogManager.Error( err );
                                }
                                int idx =
                                    signalAttributes.Rows.Add( new[] {attribute.attributeName, attribute.type, value} );
                                signalAttributes.Rows[idx].Tag = attribute;
                            }

                            //-----------------------------------------------------------------------------//
                            //--- Check the database for each of the attributes found in the schema. If ---//
                            //--- the attribute does not exist in the database the add it.              ---//
                            //-----------------------------------------------------------------------------//
                            signalAttributes.Rows.Clear();
                            foreach (XmlSchemaAttribute attribute in schemaAttributes)
                            {
                                string name = attribute.Name;
                                if (!foundAttributes.ContainsKey( name ))
                                {
                                    var dbSignalAttribute = new dbSignalAttribute();
                                    dbSignalAttribute.signalId = dataSignal.signalId;
                                    dbSignalAttribute.attributeName = name;
                                    dbSignalAttribute.defaultValue = attribute.DefaultValue;
                                    dbSignalAttribute.fixedValue = attribute.FixedValue;
                                    if (attribute.AttributeSchemaType != null)
                                        dbSignalAttribute.type = attribute.AttributeSchemaType.Name;
                                    dbSignalAttribute.DataState = BASEBean.eDataState.DS_ADD;
                                    dbSignalAttribute.save();
                                    int idx = signalAttributes.Rows.Add( new[] {name, dbSignalAttribute.type, null} );
                                    signalAttributes.Rows[idx].Tag = attribute;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                HourGlass.Enabled = false;
            }
        }
Exemplo n.º 3
0
        public void SaveSignalModel()
        {
            //Check Database for _TSF.name
            //If not found add it
            //walk through attributes
            //check for attribute names
            //if not found add them

            var dao = new SignalDAO();
            dbSignal dataSignal = dao.getSignal( _name, _signalNameSpace );
            dbSignal baseSignal = dao.getSignal( _baseSignalName, _baseSignalNameSpace );
            if (dataSignal == null)
            {
                dataSignal = new dbSignal();
                dataSignal.parentSignalId = baseSignal != null ? baseSignal.signalId : 0;
                dataSignal.xmlns = _signalNameSpace;
                dataSignal.signalName = _name;
                dataSignal.uuid = Guid.Parse( _tsf.uuid );
                dataSignal.save();
            }

            foreach (SignalAttribute attr in _attributes)
            {
                bool hasAttribute = dao.hasAttribute( dataSignal.signalId, attr.Name );
                dbSignalAttribute dbAttribute;
                if (!hasAttribute)
                    dbAttribute = new dbSignalAttribute();
                else
                    dbAttribute = dao.GetAttribute( dataSignal.signalId, attr.Name );

                dbAttribute.DataState = hasAttribute ? BASEBean.eDataState.DS_EDIT : BASEBean.eDataState.DS_ADD;
                dbAttribute.attributeName = attr.Name;
                dbAttribute.signalId = dataSignal.signalId;
                dbAttribute.defaultValue = attr.DefaultValue;
                dbAttribute.fixedValue = attr.FixedValue;
                dbAttribute.type = attr.SchemaType;
                dbAttribute.save();
            }
        }