Ejemplo n.º 1
0
        public GetSleepThread checkdGet(int chechkID, string towerName, int deviceID, DeviceContext db, int towerID, string LogMap, int CountCheck, bool MapLog)
        {
            using (IDbConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DeviceConnection"].ConnectionString))
            {
                var             getcheck        = connection.Query <GetSleepThread>($"select * from  GetSleepThread where TowerName='{towerName}' and DeviceID='{deviceID}' and TowerID='{towerID}'").FirstOrDefault();
                GetSleepThread  checkMapLog     = new GetSleepThread();
                GetThread       getThreadPreset = new GetThread();
                WalkTowerDevice addthread       = new WalkTowerDevice();
                if (getcheck != null || (CountCheck != 0 && MapLog == true))
                {
                    if (LogMap == "Log")
                    {
                        addthread         = connection.Query <WalkTowerDevice>($"select * from  WalkTowerDevice where LogID<>0 and WalkID='{chechkID}' and TowerName='{towerName}' and DeviceID='{deviceID}'").FirstOrDefault();
                        checkMapLog.LogID = 1;
                    }
                    else
                    {
                        addthread         = connection.Query <WalkTowerDevice>($"select * from  WalkTowerDevice where MapID<>0 and WalkID='{chechkID}' and TowerName='{towerName}' and DeviceID='{deviceID}'").FirstOrDefault();
                        checkMapLog.MapID = 1;
                    }
                    var maplogExistence = connection.Query <GetSleepThread>($"select * from  GetSleepThread where TowerName='{towerName}' and DeviceID='{deviceID}' and TowerID='{towerID}' and CheckID='{chechkID}'").FirstOrDefault();

                    if (maplogExistence == null)
                    {
                        checkMapLog.DeviceID     = addthread.DeviceID;
                        checkMapLog.TowerName    = addthread.TowerName;
                        checkMapLog.IP           = addthread.IP;
                        checkMapLog.ScanInterval = addthread.ScanInterval;
                        checkMapLog.WalkOid      = addthread.WalkOID;
                        checkMapLog.Version      = addthread.Version;
                        checkMapLog.CheckID      = addthread.WalkID;
                        checkMapLog.TowerID      = towerID;
                        checkMapLog.thread       = new Thread(() => getThreadPreset.ThreadPreset(addthread.WalkID, addthread.StringParserInd, addthread.DivideMultiply, addthread.ID, towerID, addthread.IP, addthread.ScanInterval, addthread.DeviceID, addthread.WalkOID, addthread.Version, addthread.StartCorrect, addthread.EndCorrect, addthread.OneStartError, addthread.OneEndError, addthread.OneStartCrash, addthread.OneEndCrash, addthread.TwoStartError, addthread.TwoEndError, addthread.TwoStartCrash, addthread.TwoEndCrash));
                        checkMapLog.thread.Start();

                        db.GetSleepThread.Add(checkMapLog);
                        db.SaveChanges();
                    }
                    else
                    {
                        if (LogMap == "Log")
                        {
                            connection.Query <GetSleepThread>($"update GetSleepThread set LogID=1 where TowerName='{towerName}' and DeviceID='{deviceID}' and TowerID='{towerID}' and CheckID='{chechkID}'");
                        }
                        else
                        {
                            connection.Query <GetSleepThread>($"update GetSleepThread set MapID=1 where TowerName='{towerName}' and DeviceID='{deviceID}' and TowerID='{towerID}' and CheckID='{chechkID}'");
                        }
                    }
                    return(checkMapLog);
                }
                else
                {
                    return(checkMapLog);
                }
            }
        }
Ejemplo n.º 2
0
        public GetSleepThread checkedLogMap(int checkID, string towerName, int deviceID, DeviceContext db, int towerID, string LogMap, int CountCheck, bool MapLog)
        {
            var             getcheck        = getData.GetCheckFirsDefine(towerName, deviceID, towerID);
            GetSleepThread  checkMapLog     = new GetSleepThread();
            GetThread       getThreadPreset = new GetThread();
            WalkTowerDevice addthread       = new WalkTowerDevice();

            if (getcheck != null || (CountCheck != 0 && MapLog == true))
            {
                if (LogMap == "Log")
                {
                    addthread         = getData.CheckLog(checkID, towerName, deviceID);
                    checkMapLog.LogID = 1;
                }
                else
                {
                    addthread         = getData.CheckMap(checkID, towerName, deviceID);
                    checkMapLog.MapID = 1;
                }
                var maplogExistence = getData.MapLogExistence(towerName, deviceID, towerID, checkID);

                if (maplogExistence == null)
                {
                    checkMapLog.DeviceID     = addthread.DeviceID;
                    checkMapLog.TowerName    = addthread.TowerName;
                    checkMapLog.IP           = addthread.IP;
                    checkMapLog.ScanInterval = addthread.ScanInterval;
                    checkMapLog.WalkOid      = addthread.WalkOID;
                    checkMapLog.Version      = addthread.Version;
                    checkMapLog.CheckID      = addthread.WalkID;
                    checkMapLog.TowerID      = towerID;
                    checkMapLog.thread       = new Thread(() => getThreadPreset.ThreadPreset(addthread.WalkID, addthread.StringParserInd, addthread.DivideMultiply, addthread.ID, towerID, addthread.IP, addthread.ScanInterval, addthread.DeviceID, addthread.WalkOID, addthread.Version, addthread.StartCorrect, addthread.EndCorrect, addthread.OneStartError, addthread.OneEndError, addthread.OneStartCrash, addthread.OneEndCrash, addthread.TwoStartError, addthread.TwoEndError, addthread.TwoStartCrash, addthread.TwoEndCrash));
                    checkMapLog.thread.Start();

                    getData.GetSleepThreadSave(db, checkMapLog);
                }
                else
                {
                    if (LogMap == "Log")
                    {
                        getData.SelectedLog(1, towerName, deviceID, towerID, checkID);
                    }
                    else
                    {
                        getData.SelectedMap(1, towerName, deviceID, towerID, checkID);
                    }
                }
                return(checkMapLog);
            }
            else
            {
                return(checkMapLog);
            }
        }
Ejemplo n.º 3
0
        public List <WalkTowerDevice> WalkSendReturn(string IP, int Port, string Version, string communityRead, List <WalkTowerDevice> walkList, string towerName, string DeviceName, int deviceID)
        {
            string walkTimeOutOID = "";

            using (IDbConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DeviceConnection"].ConnectionString))
            {
                var mibInf = connection.Query <MibTreeInformation>("Select * From  [TreeInformation]").ToList();

                OctetString community = new OctetString(communityRead);

                AgentParameters param = new AgentParameters(community);
                if (Version == "V1")
                {
                    param.Version = SnmpVersion.Ver1;
                }
                if (Version == "V2")
                {
                    param.Version = SnmpVersion.Ver2;
                }
                IpAddress agent = new IpAddress(IP);

                UdpTarget target  = new UdpTarget((IPAddress)agent, Port, 2000, 1);
                Oid       rootOid = new Oid(".1.3.6.1");

                Oid lastOid = (Oid)rootOid.Clone();

                Pdu pdu = new Pdu(PduType.GetNext);

                while (lastOid != null)
                {
                    try
                    {
                        if (pdu.RequestId != 0)
                        {
                            pdu.RequestId += 1;
                        }
                        pdu.VbList.Clear();
                        pdu.VbList.Add(lastOid);
                        if (walkTimeOutOID == lastOid.ToString())
                        {
                            WalkTimeOunt++;
                        }
                        if (WalkTimeOunt <= 10)
                        {
                            walkTimeOutOID = lastOid.ToString();
                        }
                        else
                        {
                            return(walkList);
                        }

                        if (Version == "V1")
                        {
                            result = (SnmpV1Packet)target.Request(pdu, param);
                        }
                        if (Version == "V2")
                        {
                            result = (SnmpV2Packet)target.Request(pdu, param);
                        }

                        if (result != null)
                        {
                            if (result.Pdu.ErrorStatus != 0)
                            {
                                lastOid = null;
                                break;
                            }
                            else
                            {
                                foreach (Vb v in result.Pdu.VbList)
                                {
                                    if (rootOid.IsRootOf(v.Oid))
                                    {
                                        WalkTowerDevice walk = new WalkTowerDevice();
                                        ID++;
                                        walk.ID     = ID;
                                        walk.WalkID = ID;
                                        string oid = v.Oid.ToString();
                                        var    OidMibdescription = mibInf.Where(m => m.OID == oid).FirstOrDefault();
                                        if (OidMibdescription == null)
                                        {
                                            oid = oid.Remove(oid.Length - 1);
                                            oid = oid.Remove(oid.Length - 1);
                                            OidMibdescription = mibInf.Where(o => o.OID == oid).FirstOrDefault();
                                        }
                                        if (OidMibdescription == null)
                                        {
                                            oid = oid.Remove(oid.Length - 1);
                                            oid = oid.Remove(oid.Length - 1);
                                            OidMibdescription = mibInf.Where(o => o.OID == oid).FirstOrDefault();

                                            if (OidMibdescription != null)
                                            {
                                                walk.WalkDescription = OidMibdescription.Description;
                                            }
                                        }
                                        else
                                        {
                                            walk.WalkDescription = OidMibdescription.Description;
                                        }
                                        if (OidMibdescription != null)
                                        {
                                            walk.WalkDescription = OidMibdescription.Description;
                                        }
                                        else
                                        {
                                            walk.WalkDescription = "Is Not Description";
                                        }
                                        walk.WalkOID = v.Oid.ToString();
                                        var oidname = mibInf.Where(o => o.OID == oid).FirstOrDefault();

                                        if (oidname != null)
                                        {
                                            walk.OIDName = oidname.Name;
                                        }
                                        else
                                        {
                                            walk.OIDName = "Is Not Name";
                                        }
                                        walk.Type         = v.Value.ToString();
                                        walk.Value        = SnmpConstants.GetTypeName(v.Value.Type);
                                        walk.ScanInterval = 60;
                                        walk.DeviceName   = DeviceName;
                                        walk.TowerName    = towerName;
                                        walk.DeviceID     = deviceID;
                                        walk.IP           = IP;
                                        walk.Version      = Version;

                                        //walk.StartCorrect = "0";
                                        //walk.EndCorrect = "0";
                                        //walk.OneStartError = "0";
                                        //walk.OneEndError = "0";
                                        //walk.OneStartCrash = "0";
                                        //walk.OneEndCrash = "0";
                                        //walk.TwoStartError = "0";
                                        //walk.TwoEndError = "0";
                                        //walk.TwoStartCrash = "0";
                                        //walk.TwoEndCrash = "0";

                                        walkList.Add(walk);
                                        lastOid = v.Oid;
                                    }
                                    else
                                    {
                                        lastOid = null;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e) { }
                }
                target.Close();
            }
            return(walkList);
        }