Inheritance: ATMLDataAccessLibrary.db.beans.SignalMasterBean
Exemplo n.º 1
0
 private void ProcessBSCSignalTreeNode( dbSignal signal, XmlDocument document, XmlElement parentElement )
 {
     if (signal != null)
     {
         XmlElement basElement = document.CreateElement(signal.signalName);
         XmlAttribute id = document.CreateAttribute("id");
         XmlAttribute xmlns = document.CreateAttribute("xmlns");
         XmlAttribute uuid = document.CreateAttribute("uuid");
         id.Value = signal.signalId.ToString();
         xmlns.Value = signal.xmlns;
         uuid.Value = signal.uuid==null?"":signal.uuid.ToString();
         basElement.Attributes.Append(id);
         basElement.Attributes.Append(xmlns);
         basElement.Attributes.Append(uuid);
         foreach (dbSignalAttribute attribute in signal.Attributes)
         {
             XmlAttribute att = document.CreateAttribute(attribute.attributeName);
             att.Value = attribute.Value;
             basElement.Attributes.Append(att);
         }
         if (parentElement == null)
             document.AppendChild(basElement);
         else
             parentElement.AppendChild(basElement);
         foreach (dbSignal child in signal.ChildSignals)
         {
             ProcessBSCSignalTreeNode(child, document, basElement);
         }
         if (signal.signalName.Equals("TSF"))
         {
             //Process TSFs
             List<dbTSFLibrary> tsfs = getTSFLibraries();
             foreach (dbTSFLibrary dbTsfLibrary in tsfs)
             {
                 XmlElement lElement = document.CreateElement(dbTsfLibrary.libraryName);
                 List<dbTSFSignal> sigs = getTSFLibrarySignals(dbTsfLibrary.id);
                 foreach (dbTSFSignal dbTsfSignal in sigs )
                 {
                     dbSignal tsfSignal = getSignal(dbTsfSignal.signalName, dbTsfLibrary.targetNamespace);
                     ProcessBSCSignalTreeNode(tsfSignal, document, lElement );
                 }
                 basElement.AppendChild(lElement);
             }
         }
     }
 }
        private void SaveSelectedSignalModel()
        {
            HourGlass.Start();
            try
            {
                SignalDAO dao = DataManager.getSignalDAO();
                if (_signalModelLibrary != null)
                {
                    dao.DeleteTSFLibrary( _signalModelLibrary.TSFLibrary.uuid,
                                          _signalModelLibrary.TSFLibrary.targetNamespace );
                    var library = new dbTSFLibrary();
                    library.IncludeKeyOnInsert = true;
                    library.lastUpdate = DateTime.UtcNow;
                    library.id = Guid.Parse( _signalModelLibrary.TSFLibrary.uuid );
                    library.content = _signalModelLibrary.XmlContent;
                    library.targetNamespace = _signalModelLibrary.TSFLibrary.targetNamespace;
                    library.libraryName = _signalModelLibrary.TSFLibrary.name;
                    library.DataState = ( !dao.hasTSFLibrary( _signalModelLibrary.TSFLibrary.uuid ) )
                                            ? BASEBean.eDataState.DS_ADD
                                            : BASEBean.eDataState.DS_EDIT;
                    library.save();

                    foreach (SignalModel sm in _signalModelLibrary.SignalModels.Values)
                    {
                        TSFType tsf = sm.TSF;
                        dbSignal dataSignal = dao.getSignal( sm.Name, library.targetNamespace );
                        if (dataSignal == null)
                        {
                            //Add Signal to the database

                            string baseSignalName = sm.BaseSignalName;
                            dbSignal baseSignal = dao.getSignal( baseSignalName, sm.BaseSignalNameSpace );
                            dataSignal = new dbSignal();
                            dataSignal.ParentSignal = baseSignal;
                            dataSignal.signalName = sm.Name;
                            dataSignal.uuid = Guid.Parse(tsf.uuid);
                            dataSignal.xmlns = library.targetNamespace;
                            foreach (SignalAttribute attribute in sm.Attributes)
                            {
                                var a = new dbSignalAttribute();
                                a.attributeName = attribute.Name;
                                a.defaultValue = attribute.DefaultValue;
                                a.DataState = BASEBean.eDataState.DS_ADD;
                                a.type = attribute.SchemaType;
                                a.fixedValue = attribute.FixedValue;
                                if (dataSignal.Attributes == null )
                                    dataSignal.Attributes = new List<dbSignalAttribute>();
                                dataSignal.Attributes.Add( a );
                            }
                            dataSignal.DataState = BASEBean.eDataState.DS_ADD;
                        }
                        else
                        {
                            dataSignal.xmlns = library.targetNamespace;
                            dataSignal.uuid = Guid.Parse(tsf.uuid);
                            List<dbSignalAttribute> attributes = dataSignal.Attributes;
                            var attrMap = new Dictionary<string, SignalAttribute>();
                            var dbAttrMap = new Dictionary<string, dbSignalAttribute>();
                            foreach (SignalAttribute sa in sm.Attributes)
                                attrMap.Add( sa.Name, sa );

                            foreach (dbSignalAttribute dbAttribute in attributes)
                            {
                                string an = dbAttribute.attributeName;
                                dbAttrMap.Add( an, dbAttribute );
                                if (attrMap.ContainsKey( an ))
                                {
                                    SignalAttribute sa = attrMap[an];
                                    dbAttribute.type = sa.SchemaType;
                                    dbAttribute.defaultValue = sa.DefaultValue;
                                    dbAttribute.fixedValue = sa.FixedValue;
                                    dbAttribute.DataState = BASEBean.eDataState.DS_EDIT;
                                }
                                else
                                {
                                    dbAttribute.DataState = BASEBean.eDataState.DS_DELETE;
                                }
                            }

                            foreach (SignalAttribute sa in sm.Attributes)
                            {
                                if (!dbAttrMap.ContainsKey( sa.Name ))
                                {
                                    var dbAttribute = new dbSignalAttribute();
                                    dbAttribute.type = sa.SchemaType;
                                    dbAttribute.defaultValue = sa.DefaultValue;
                                    dbAttribute.fixedValue = sa.FixedValue;
                                    dbAttribute.DataState = BASEBean.eDataState.DS_ADD;
                                    dataSignal.Attributes.Add( dbAttribute );
                                }
                            }
                            dataSignal.DataState = BASEBean.eDataState.DS_EDIT;
                        }
                        dataSignal.xmlns = _signalModelLibrary.TSFLibrary.targetNamespace;
                        dataSignal.save();
                    }

                    foreach (ListViewItem item in lvSignals.Items)
                    {
                        var model = item.Tag as SignalModel;
                        if (model != null)
                        {
                            var signal = new dbTSFSignal();
                            signal.signalName = model.Name;
                            signal.id = Guid.Parse( model.TSF.uuid );
                            signal.signalContent = model.TSF.Serialize();
                            signal.libraryUuid = _signalModelLibrary.TSFLibrary.uuid;
                            signal.DataState = ( !dao.hasTSFSignal( model.TSF.uuid )
                                                     ? BASEBean.eDataState.DS_ADD
                                                     : BASEBean.eDataState.DS_EDIT );
                            signal.lastUpdate = DateTime.UtcNow;
                            try
                            {
                                signal.save();
                            }
                            catch (Exception e)
                            {
                                if (e.Message.ToLower().Contains( "duplicate" ))
                                {
                                    TestSignalBean otherSignal = dao.getTSFSignal( model.Name,
                                                                                   _signalModelLibrary.TSFLibrary.uuid );
                                    LogManager.Error( "UUID Conflict between document data and the database for Signal {0} in Signal Library {1} ",
                                                      model.Name, library.libraryName );
                                    if (otherSignal != null)
                                    {
                                        LogManager.Error( "\tDocument signal uuid {0}, Database signal uuid {{{1}}} ",
                                                          model.TSF.uuid, otherSignal.id.ToString().ToUpper() );

                                        if (dao.changeTSFSignalId( otherSignal.id, Guid.Parse(model.TSF.uuid) ))
                                        {
                                            LogManager.Info(
                                                "The Database signal uuid has been changed to reflect the Document signal uuid" );
                                            signal.DataState = BASEBean.eDataState.DS_EDIT;
                                            signal.save();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogManager.Error( e, "An error has occured saving the signal model library: {0}", e.Message );
            }
            finally
            {
                HourGlass.Stop();
                if (_signalModelLibrary == null)
                {
                    MessageBox.Show(Resources.A_Signal_Model_must_be_selected_to_save_);
                }
                else
                {
                    LogManager.Trace(Resources.Completed_Saving_Selected_Signal_Model);
                    MessageBox.Show(Resources.Completed_Saving_Selected_Signal_Model);
                }
            }
        }
Exemplo n.º 3
0
        public dbSignal getSignal(string signalName, string nameSpace )
        {
            dbSignal signal = null;
            if (signalName != null)
            {
                String sql = "SELECT * FROM signal_master WHERE signal_name = ?";
                List<OleDbParameter> dbParams = new List<OleDbParameter>();
                dbParams.Add(CreateParameter("@signal_name", signalName));
                if (!string.IsNullOrEmpty(nameSpace))
                {
                    sql += " AND xmlns = ? ";
                    dbParams.Add(CreateParameter("@xmlns", nameSpace));
                }

                OleDbDataReader reader = ExecuteSqlQuery(sql, dbParams.ToArray());
                if (reader != null)
                {
                    if (reader.Read())
                    {
                        signal = new dbSignal();
                        signal.load(reader);
                        signal.ChildSignals = getChildSignals(signal.signalId);
                        signal.Attributes = getSignalAttributes(signal.signalId);
                        if (signal.parentSignalId != null)
                            signal.ParentSignal = getSignal(signal.parentSignalId);

                    }
                    reader.Close();
                    reader.Dispose();
                }
            }
            return signal;
        }
Exemplo n.º 4
0
 public void ScoreInstruments(dbSignal signal)
 {
     //Search all the signal attributes where each attribute value
     // falls within the range of the hi and lo values in the capabilities database
     //Store the instrument with the attribute
     //Group all the instruments with the attributes that are within scope
     //Score the instruments based on the number of attributes it has
     //100% == all attributes
 }
Exemplo n.º 5
0
        public List<dbSignal> getRootSignals()
        {
            XmlDocument doc = new XmlDocument();
            List<dbSignal> signals = new List<dbSignal>();

            String sql = "SELECT * FROM signal_master WHERE parent_signal_id=? ORDER BY signal_name";
            OleDbParameter[] dbParams = { CreateParameter("@parent_signal_id", 1) };
            using (OleDbDataReader reader = ExecuteSqlQuery( sql, dbParams ))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        dbSignal signal = new dbSignal();
                        signal.load( reader );
                        signal.ChildSignals = getChildSignals( signal.signalId );
                        signal.Attributes = getSignalAttributes( signal.signalId );
                        signals.Add( signal );
                    }
                    reader.Close();
                    reader.Dispose();
                }
            }
            return signals;
        }
Exemplo n.º 6
0
 public dbSignal getSignal(int? signalId)
 {
     dbSignal signal = null;
     if (signalId != null)
     {
         String sql = "SELECT * FROM signal_master WHERE signal_id = ?";
         OleDbParameter[] dbParams = {CreateParameter("@signal_id", signalId)};
         OleDbDataReader reader = ExecuteSqlQuery(sql, dbParams);
         if (reader != null)
         {
             if (reader.Read())
             {
                 signal = new dbSignal();
                 signal.load(reader);
                 signal.ChildSignals = getChildSignals(signal.signalId);
                 signal.Attributes = getSignalAttributes(signal.signalId);
                 if (signal.parentSignalId != null)
                     signal.ParentSignal = getSignal( signal.parentSignalId );
             }
             reader.Close();
             reader.Dispose();
         }
     }
     return signal;
 }
Exemplo n.º 7
0
 public List<dbSignal> getChildSignals(int? parentSignalId)
 {
     List<dbSignal> signals = new List<dbSignal>();
     if (parentSignalId != null)
     {
         String sql = "SELECT * FROM signal_master WHERE parent_signal_id = ?";
         OleDbParameter[] dbParams = {CreateParameter("@parent_signal_id", parentSignalId)};
         OleDbDataReader reader = ExecuteSqlQuery(sql, dbParams);
         if (reader != null)
         {
             while (reader.Read())
             {
                 dbSignal signal = new dbSignal();
                 signal.load(reader);
                 signal.ChildSignals = getChildSignals(signal.signalId);
                 signal.Attributes = getSignalAttributes(signal.signalId);
                 signals.Add(signal);
             }
             reader.Close();
             reader.Dispose();
         }
     }
     return signals;
 }
Exemplo n.º 8
0
 public dbSignal GetBaseBSCSignal()
 {
     dbSignal signal = null;
     String sql = "SELECT * FROM signal_master WHERE parent_signal_id = 1 AND xmlns LIKE '%STDBSC'";
     List<OleDbParameter> dbParams = new List<OleDbParameter>();
     OleDbDataReader reader = ExecuteSqlQuery(sql, dbParams.ToArray());
     if (reader != null)
     {
         if (reader.Read())
         {
             signal = new dbSignal();
             signal.load(reader);
             signal.ChildSignals = getChildSignals(signal.signalId);
             signal.Attributes = getSignalAttributes(signal.signalId);
         }
         reader.Close();
         reader.Dispose();
     }
     return signal;
 }
Exemplo n.º 9
0
        public List<dbSignal> GetAllTsfSignals()
        {
            var doc = new XmlDocument();
            var signals = new List<dbSignal>();

            var sql = new StringBuilder();
            sql.Append("SELECT a.* FROM ")
                .Append(SignalMasterBean._TABLE_NAME)
                .Append(" a, ")
                .Append(TestSignalLibraryBean._TABLE_NAME)
                .Append(" b WHERE a.")
                .Append(SignalMasterBean._XMLNS)
                .Append(" = b.")
                .Append(TestSignalLibraryBean._TARGET_NAMESPACE)
                .Append(" ORDER BY ")
                .Append(SignalMasterBean._SIGNAL_NAME);
            OleDbParameter[] dbParams = { CreateParameter("@parent_signal_id", 1) };
            using (OleDbDataReader reader = ExecuteSqlQuery( sql.ToString(), dbParams ))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var signal = new dbSignal();
                        signal.load( reader );
                        signal.ChildSignals = getChildSignals( signal.signalId );
                        signal.Attributes = getSignalAttributes( signal.signalId );
                        signals.Add( signal );
                    }
                    reader.Close();
                    reader.Dispose();
                }
            }
            return signals;
        }
 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;
 }
Exemplo n.º 11
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();
            }
        }