public static int SeekActiveUnitsCuenca(DataTable dtzone, int qty)
        {
            System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();
            string UNIT_ID = (string)appSettings.GetValue("GroupsChilds.UnitId", typeof(string));

            string swhere = "";
            CmpGroupsChildsGisDB cGroupChildsDb = new CmpGroupsChildsGisDB();
            CmpGroupsDB          cGroupsDb      = new CmpGroupsDB();

            foreach (DataRow dr in dtzone.Rows)
            {
                // If there is not a UNIT we follow deeping in the tree...(Level 2)
                if (dr["CGRPG_TYPE"].ToString() != UNIT_ID)
                {
                    swhere = "CGRPG_ID	= "+ dr["CGRPG_CHILD"].ToString();
                    DataTable dtsubzone = cGroupChildsDb.GetData(null, swhere, null, null);
                    qty = SeekActiveUnits(dtsubzone, qty);
                }
                else
                {
                    CmpUnitsDB udb = new CmpUnitsDB();
                    swhere = "UNI_ID = " + dr["CGRPG_CHILD"].ToString() + " AND UNI_IP IS NOT NULL AND UNI_DSTA_ID IN (0,1,2)";
                    DataTable dtUnit = udb.GetData(null, swhere, null, null);
                    if (dtUnit.Rows.Count != 0)
                    {
                        qty++;
                    }
                }
            }
            return(qty);
        }
        public static string SeekUnitsString(DataTable dtzone)
        {
            System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();
            string UNIT_ID = (string)appSettings.GetValue("GroupsChilds.UnitId", typeof(string));
            string swhere  = "";
            CmpGroupsChildsGisDB cGroupChildsDb = new CmpGroupsChildsGisDB();
            CmpGroupsDB          cGroupsDb      = new CmpGroupsDB();
            string strRes  = "";
            string strTemp = "";

            foreach (DataRow dr in dtzone.Rows)
            {
                // If there is not a UNIT we follow deeping in the tree...(Level 2)
                if (dr["CGRPG_TYPE"].ToString() != UNIT_ID)
                {
                    swhere = "CGRPG_ID	= "+ dr["CGRPG_CHILD"].ToString();
                    DataTable dtsubzone = cGroupChildsDb.GetData(null, swhere, null, null);
                    strTemp = SeekUnitsString(dtsubzone);
                    if (strTemp != "")
                    {
                        if (strRes == "")
                        {
                            strRes = strTemp;
                        }
                        else
                        {
                            strRes += "," + strTemp;
                        }
                    }
                }
                else
                {
                    if (dr["CGRPG_CHILD"].ToString() != "")
                    {
                        CmpUnitsDB udb = new CmpUnitsDB();
                        swhere = "UNI_ID = " + dr["CGRPG_CHILD"].ToString() + " AND UNI_DPUNI_ID IN (1,2) ";
                        DataTable dtUnit = udb.GetData(null, swhere, null, null);
                        if (dtUnit.Rows.Count != 0)
                        {
                            if (strRes == "")
                            {
                                strRes = dr["CGRPG_CHILD"].ToString();
                            }
                            else
                            {
                                strRes += "," + dr["CGRPG_CHILD"].ToString();
                            }
                        }
                    }
                }
            }
            return(strRes);
        }
        private void OnInQueueReceiveCompleted(FecsBecsHeader header, string body)
        {
            if (_channelMgr != null)
            {
                string   uri     = header.ID;
                IChannel channel = _channelMgr.GetChannel(uri);
                if (channel == null)
                {
                    channel = _channelMgr.OpenChannel(uri, ChannelType.BecsQueue);
                    if (channel != null)
                    {
                        MessageProcessorManager.OnNewConnection(channel);
                    }
                }
                if (channel != null)
                {
                    BecsChannel   bc     = (BecsChannel)channel;
                    StringBuilder packet = new StringBuilder(256);
                    packet.AppendFormat(null, "<{0} {1}=\"{2}\" {3}=\"{4}\">{5}</{0}>",
                                        Tags.Packet, Tags.PacketSrcAttr, header.PacketInfo.SourceId,
                                        Tags.PacketDateAttr, Dtx.DtxToString(header.PacketInfo.Dtx), body);
                    string  xml         = packet.ToString();
                    ILogger localLogger = null;
                    try
                    {
                        Database   d        = null;
                        CmpUnitsDB cmpUnits = new CmpUnitsDB();
                        //d = DatabaseFactory.GetDatabase();
                        localLogger = DatabaseFactory.Logger;

                        if (localLogger != null)
                        {
                            localLogger.AddLog("[OnInQueueReceiveCompleted]: Updating ID: " + header.PacketInfo.SourceId + " IP :" + header.IP, LoggerSeverities.Debug);
                        }
                        if (Convert.ToInt32(header.PacketInfo.SourceId) != -1)
                        {
                            if (cmpUnits.UpdateIP(Convert.ToInt32(header.PacketInfo.SourceId), header.IP) != 1)
                            {
                                if (localLogger != null)
                                {
                                    localLogger.AddLog("[OnInQueueReceiveCompleted]: Error Updating IP", LoggerSeverities.Debug);
                                }
                            }
                            else
                            {
                                if (localLogger != null)
                                {
                                    localLogger.AddLog("[OnInQueueReceiveCompleted]: Update OK", LoggerSeverities.Debug);
                                }
                            }
                        }
                    }
                    catch
                    {
                        // Do not do nothing??
                        // Si tenemos un error en realizar un update de la ip
                        // no hacemos nada
                        if (localLogger != null)
                        {
                            localLogger.AddLog("[OnInQueueReceiveCompleted]: Error Updating IP", LoggerSeverities.Debug);
                        }
                    }
                    Interlocked.Increment(ref _packetId);
                    OPSTelegrama opsTel = OPSTelegramaFactory.CreateOPSTelegrama(_packetId, xml);
                    bc.ReceiveMessage(opsTel);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Process the Message. The process of this message is specified in OPS_D_M3.doc
        /// </summary>
        /// <returns>Response for the message (1 string)</returns>
        public StringCollection Process()
        {
            StringCollection res = null;

            // Get ALL current alarms of that device
            OPS.Comm.Becs.Components.CmpAlarmsDevices ad = _session.AlarmsDevices;
            //OPS.Comm.Becs.Components.CmpAlarmsDevices ad = new OPS.Comm.Becs.Components.CmpAlarmsDevices();
            if (ad.UpdateAlarms(_unit, _alarmsMasks, _date))
            {
                // Update UNIT status
                CmpUnitsDB udb = new CmpUnitsDB();
                udb.UpdateStatus(_unit, _status);


                if (_loadUnloadStatus >= 0)
                {
                    OracleConnection oraDBConn = null;
                    OracleCommand    oraCmd    = null;
                    ILogger          logger    = null;

                    try
                    {
                        Database d = OPS.Components.Data.DatabaseFactory.GetDatabase();
                        logger = DatabaseFactory.Logger;
                        System.Data.IDbConnection DBCon = d.GetNewConnection();
                        oraDBConn = (OracleConnection)DBCon;
                        oraDBConn.Open();

                        if (oraDBConn.State == System.Data.ConnectionState.Open)
                        {
                            oraCmd             = new OracleCommand();
                            oraCmd.Connection  = (OracleConnection)oraDBConn;
                            oraCmd.CommandText = "";

                            int iMask = 1;
                            int iStatus;
                            int iSlot;
                            for (int i = 0; i < 3; i++)
                            {
                                iSlot   = i + 1;
                                iStatus = Convert.ToInt32((_loadUnloadStatus & iMask) > 0);
                                iMask   = iMask * 2;

                                oraCmd.CommandText = string.Format("update umdm_stations_slots  set " +
                                                                   "USS_CURRENT_STATE={0}, " +
                                                                   "USS_UPDDATE=to_date('{1}', 'HH24MISSDDMMYY') " +
                                                                   "where  USS_ORDER_STATION = {2} " +
                                                                   "  and  USS_US_ID = {3}",
                                                                   iStatus, OPS.Comm.Dtx.DtxToString(_date), iSlot, _unit);

                                oraCmd.ExecuteNonQuery();
                            }

                            res = ReturnAck(AckMessage.AckTypes.ACK_PROCESSED);
                        }
                        else
                        {
                            if (logger != null)
                            {
                                logger.AddLog("[Msg3:Process]: Error: BD is not opened", LoggerSeverities.Error);
                            }
                            res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                        }
                    }
                    catch (Exception e)
                    {
                        if (logger != null)
                        {
                            logger.AddLog("[Msg3:Process]: Error: " + e.Message, LoggerSeverities.Error);
                        }
                        res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                    }
                    finally
                    {
                        if (oraCmd != null)
                        {
                            oraCmd.Dispose();
                            oraCmd = null;
                        }


                        if (oraDBConn != null)
                        {
                            oraDBConn.Close();
                            oraDBConn.Dispose();
                            oraDBConn = null;
                        }
                    }
                }
                else
                {
                    if (_user >= -1)
                    {
                        OracleConnection oraDBConn = null;
                        OracleCommand    oraCmd    = null;
                        ILogger          logger    = null;

                        try
                        {
                            Database d = OPS.Components.Data.DatabaseFactory.GetDatabase();
                            logger = DatabaseFactory.Logger;
                            System.Data.IDbConnection DBCon = d.GetNewConnection();
                            oraDBConn = (OracleConnection)DBCon;
                            oraDBConn.Open();

                            if (oraDBConn.State == System.Data.ConnectionState.Open)
                            {
                                oraCmd             = new OracleCommand();
                                oraCmd.Connection  = (OracleConnection)oraDBConn;
                                oraCmd.CommandText = "";


                                oraCmd.CommandText = string.Format("update units  set " +
                                                                   "uni_usr_id={0} " +
                                                                   "where uni_id = {1}",
                                                                   _user == -1?"NULL":_user.ToString(), _unit);

                                oraCmd.ExecuteNonQuery();

                                res = ReturnAck(AckMessage.AckTypes.ACK_PROCESSED);
                            }
                            else
                            {
                                if (logger != null)
                                {
                                    logger.AddLog("[Msg3:Process]: Error: BD is not opened", LoggerSeverities.Error);
                                }
                                res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                            }
                        }
                        catch (Exception e)
                        {
                            if (logger != null)
                            {
                                logger.AddLog("[Msg3:Process]: Error: " + e.Message, LoggerSeverities.Error);
                            }
                            res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                        }
                        finally
                        {
                            if (oraCmd != null)
                            {
                                oraCmd.Dispose();
                                oraCmd = null;
                            }


                            if (oraDBConn != null)
                            {
                                oraDBConn.Close();
                                oraDBConn.Dispose();
                                oraDBConn = null;
                            }
                        }
                    }
                    else
                    {
                        res = ReturnAck(AckMessage.AckTypes.ACK_PROCESSED);
                    }
                }
            }
            else
            {
                res = ReturnAck(AckMessage.AckTypes.ACK_PROCESSED);
            }


            return(res);
        }