// GET: Device public ActionResult Index(int id) { Device d = null; using (var ctx = new GlsunViewEntities()) { d = ctx.Device.Find(id); } //IP地址->连接服务->实例化一个状态类->填充状态 //TcpClientService tcp = new TcpClientService(d.DAddress, d.DPort.Value); //var tcp = TcpClientServiceTool.GetService(d.DAddress, d.DPort.Value); var tcp = TcpClientServicePool.GetService(d.DAddress, d.DPort.Value); NMUCommService nmu = new NMUCommService(tcp); DeviceOverview deviceView = new DeviceOverview(); deviceView.IP = d.DAddress; deviceView.Port = d.DPort.Value; try { //tcp.Connect(); //tcp.ConnectTimeout = 3000; if (tcp != null) { deviceView.RefreshStatus(nmu); //TcpClientServiceTool.SetServiceFree(tcp); TcpClientServicePool.FreeService(tcp); } else { throw new TimeoutException("设备连接超时"); } } catch (Exception ex) { deviceView.Type = "NoResponse"; deviceView.Unit = 4; } if (deviceView.Slots == null) { deviceView.Slots = new List <Slot>(); } JavaScriptSerializer serializer = new JavaScriptSerializer(); ViewBag.DeviceInfo = serializer.Serialize(deviceView); return(View(d)); }
public ActionResult GetCardInfo(string ip, int port) { //更新插卡信息 //更新卡的状态 var ret = new JsonResult(); var tcp = TcpClientServicePool.GetService(ip, port); if (tcp != null) { try { string key = string.Format("card_info_{0}:{1}", ip, port); NMUCommService nmu = new NMUCommService(tcp); DeviceOverview deviceView = new DeviceOverview(); deviceView.RefreshStatus(nmu); deviceView.IP = ip; deviceView.Port = port; var cardSlotInfo = GetCardSlotInfo(tcp, deviceView); tcp.IsBusy = false; ret.Data = new { Code = "", Data = cardSlotInfo }; } catch (Exception ex) { ret.Data = new { Code = "Exception", Data = ex.Message + "\n" + ex.StackTrace }; } finally { TcpClientServicePool.FreeService(tcp); } } else { ret.Data = new { Code = "Exception", Data = "获取TCP连接失败" }; } return(ret); }
public ActionResult GetCardInfo(string ip, int port) { //更新插卡信息 //更新卡的状态 var ret = new JsonResult(); try { string key = string.Format("card_info_{0}:{1}", ip, port); var info = MemoryCacheHelper.GetCacheItem <DeviceStatusSet>(key, () => { DeviceStatusSet set = new DeviceStatusSet(); //using (TcpClientService tcp = new TcpClientService(ip, port)) { //tcp.Connect(); var tcp = TcpClientServicePool.GetService(ip, port); if (tcp == null) { throw new Exception("null object"); } NMUCommService nmu = new NMUCommService(tcp); DeviceOverview deviceView = new DeviceOverview(); CardCommService cardService = null; deviceView.RefreshStatus(nmu); set.Overview = deviceView; NMUInfo numInfo = new NMUInfo(); NMUCommService nmuService = new NMUCommService(tcp); numInfo.RefreshStatus(nmuService); set.NMUInfo = numInfo; set.CardsInfo = new List <object>(); foreach (var e in deviceView.Slots) { if (e.IsInsert) { if (e.CardType == "EDFA") { cardService = new EDFACommService(tcp, e.SlotNumber); EDFAInfo edfaInfo = new EDFAInfo(); edfaInfo.RefreshData(cardService); e.CardInfo = edfaInfo; } else if (e.CardType == "OEO") { cardService = new OEOCommService(tcp, e.SlotNumber); OEOInfo oeoInfo = new OEOInfo(); oeoInfo.RefreshData(cardService); e.CardInfo = oeoInfo; } else if (e.CardType == "OLP") { cardService = new OLPCommService(tcp, e.SlotNumber); OLPInfo olpInfo = new OLPInfo(); olpInfo.RefreshData(cardService); e.CardInfo = olpInfo; } } } //tcp.Dispose(); TcpClientServicePool.FreeService(tcp); } return(set); }, null, DateTime.Now.AddSeconds(2)); ret.Data = new { Code = "", Data = info }; } catch (Exception ex) { ret.Data = new { Code = "Exception", Data = ex.Message + "\n" + ex.StackTrace }; } return(ret); }
private static void GetDeviceOverView(int id, out DeviceOverview deviceView, out DeviceInfo info, out List <CardSlotInfo> cardSlotInfo) { MachineFrame frame = null; MachineShelf shelf = null; MachineRoom room = null; using (var ctx = new GlsunViewEntities()) { frame = ctx.MachineFrame.Find(id); shelf = ctx.MachineShelf.Find(frame.MSID); room = ctx.MachineRoom.Find(shelf.MRID); } var tcp = TcpClientServicePool.GetService(frame.MFIP, frame.MFPort.Value); //设备整体状态信息 NMUCommService nmu = new NMUCommService(tcp); deviceView = new DeviceOverview(); deviceView.IP = frame.MFIP; deviceView.Port = frame.MFPort.Value; deviceView.MCUType = frame.MFMCUType; //主控卡信息 NMUInfo nmuInfo = new NMUInfo(); //设备信息 info = new DeviceInfo(); //卡槽信息 cardSlotInfo = new List <CardSlotInfo>(); if (tcp != null) { try { deviceView.RefreshStatus(nmu); nmuInfo.RefreshStatus(nmu); info = new DeviceInfo { Type = string.Format("{0}-{1}U-{2}", frame.MFName, deviceView.Unit, deviceView.Type), Shelf = string.Format("{0}-{1},第{2}层", shelf.MSName, shelf.MSNumber, frame.MSLayer), Room = room.MRName, Address = room.MRAddress, Description = room.MRDescription, SerialNumber = nmuInfo.Serial_Number, IP = frame.MFIP, Mask = nmuInfo.Subnet_Mask, MACAddr = deviceView.MACAddr }; cardSlotInfo = GetCardSlotInfo(tcp, deviceView); } catch (Exception ex) { deviceView.Type = "NoResponse"; deviceView.Unit = 4; } finally { TcpClientServicePool.FreeService(tcp); } } else { throw new TimeoutException("设备连接超时"); } if (deviceView.Slots == null) { deviceView.Slots = new List <Slot>(); } }