public ActionResult UpdateConfig(string ip, int port, int slot) { JsonResult result = new JsonResult(); //result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; EDFAInfo edfaInfo = new EDFAInfo(); var tcp = TcpClientServicePool.GetService(ip, port); if (tcp != null) { try { EDFACommService service = new EDFACommService(tcp, slot); edfaInfo.RefreshData(service); result.Data = new { Code = "", Data = edfaInfo }; } catch (Exception ex) { result.Data = new { Code = "Exception", Data = ex.Message }; } finally { TcpClientServicePool.FreeService(tcp); } } else { result.Data = new { Code = "Exception", Data = "获取TCP连接失败" }; } return(result); }
/// <summary> /// 设备视图 /// </summary> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="slot"></param> /// <returns></returns> public ActionResult Details(string ip, int port, int slot, int mfId) { EDFAInfo edfaInfo = new EDFAInfo(); var tcp = TcpClientServicePool.GetService(ip, port); if (tcp != null) { try { EDFACommService service = new EDFACommService(tcp, slot); edfaInfo.RefreshData(service); } catch { } finally { TcpClientServicePool.FreeService(tcp); } } EDFAViewModel edfa = new EDFAViewModel { IP = ip, Port = port, Slot = slot, Type = edfaInfo.Device_Type, WorkMode = edfaInfo.Work_Mode, Status = "正常", MaxOutput = edfaInfo.PUMP_Power, MaxGain = edfaInfo.Current_Gain, ProductModel = "OTS-" + edfaInfo.Device_Type, SerialNumber = edfaInfo.Serial_Number, HardwareVersion = edfaInfo.Hardware_Version, SoftwareVersion = edfaInfo.Software_Version }; ViewBag.MFID = mfId; return(View(edfa)); }
public ActionResult RealTimeStatus(int did, int slot) { JsonResult result = new JsonResult(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; try { string key = string.Format("edfa_info_{0}", did); var info = MemoryCacheHelper.GetCacheItem <EDFAInfo>(key, () => { Device d = null; using (var ctx = new GlsunViewEntities()) { d = ctx.Device.Find(did); } EDFAInfo edfaInfo = new EDFAInfo(); //TcpClientService tcp = new TcpClientService(d.DAddress, d.DPort.Value); var tcp = TcpClientServicePool.GetService(d.DAddress, d.DPort.Value); if (tcp == null) { throw new NullReferenceException(); } EDFACommService service = new EDFACommService(tcp, slot); edfaInfo.RefreshData(service); TcpClientServicePool.FreeService(tcp); return(edfaInfo); }, null, DateTime.Now.AddSeconds(2)); result.Data = new { Code = "", Data = info }; } catch (Exception ex) { result.Data = new { Code = "Exception", Data = "" }; } return(result); }
// GET: EDFACard /// <summary> /// /// </summary> /// <param name="ip">设备地址</param> /// <param name="port">端口</param> /// <param name="slot">槽位</param> /// <returns></returns> public ActionResult Index(int did, int slot) { Device d = null; using (var ctx = new GlsunViewEntities()) { d = ctx.Device.Find(did); } EDFAInfo edfaInfo = new EDFAInfo(); TcpClientService tcp = new TcpClientService(d.DAddress, d.DPort.Value); EDFACommService service = new EDFACommService(tcp, slot); try { tcp.Connect(); edfaInfo.RefreshData(service); } catch (Exception ex) { } ViewBag.Did = d.ID; ViewBag.EndPoint = d.DAddress + ":" + d.DPort.Value + ":" + slot.ToString(); return(View(edfaInfo)); }
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 List <CardSlotInfo> GetCardSlotInfo(TcpClientService tcp, DeviceOverview deviceView) { List <CardSlotInfo> cardSlotInfo = new List <CardSlotInfo>(); var context = new GlsunViewEntities(); foreach (var e in deviceView.Slots) { CardSlotInfo slotInfo = new CardSlotInfo { Slot = e.SlotNumber, Status = e.IsInsert ? "在位" : "N/A", CardType = e.CardType }; //其他信息 switch (e.CardType) { case "EDFA": EDFACommService srvEDFA = new EDFACommService(tcp, e.SlotNumber); EDFAInfo edfaInfo = new EDFAInfo(); edfaInfo.RefreshData(srvEDFA); switch (edfaInfo.Work_Mode) { case 0: slotInfo.WorkMode = "其他"; break; case 1: slotInfo.WorkMode = "ACC模式"; break; case 2: slotInfo.WorkMode = "APC模式"; break; case 3: slotInfo.WorkMode = "AGC模式"; break; default: slotInfo.WorkMode = ""; break; } slotInfo.HardwareVersion = edfaInfo.Hardware_Version; slotInfo.SoftwareVersion = edfaInfo.Software_Version; var alarm = context.AlarmInformation .Where(a => a.DAddress == deviceView.IP && a.AISlot == slotInfo.Slot) .OrderByDescending(a => a.AITime).FirstOrDefault(); if (alarm != null) { slotInfo.CurrentAlarm = alarm.AIContent; } else { slotInfo.CurrentAlarm = ""; } break; case "OEO": OEOCommService srvOEO = new OEOCommService(tcp, e.SlotNumber); OEOInfo oeoInfo = new OEOInfo(); oeoInfo.RefreshData(srvOEO); slotInfo.HardwareVersion = oeoInfo.Hardware_Version; slotInfo.SoftwareVersion = oeoInfo.Software_Version; //SFP模块是否有转发 bool bTranspond = false; //SFP模块是否有环回 bool bLoopback = false; foreach (var spf in oeoInfo.SFPSet) { if (spf.Work_Mode == 1) { bTranspond = true; } if (spf.Work_Mode == 3) { bLoopback = true; } } if (bTranspond && bLoopback) { slotInfo.WorkMode = "转发+环回"; } else if (bTranspond) { slotInfo.WorkMode = "转发"; } else if (bLoopback) { slotInfo.WorkMode = "环回"; } else { slotInfo.WorkMode = "N/A"; } var alarmOEO = context.AlarmInformation .Where(a => a.DAddress == deviceView.IP && a.AISlot == slotInfo.Slot) .OrderByDescending(a => a.AITime).FirstOrDefault(); if (alarmOEO != null) { slotInfo.CurrentAlarm = alarmOEO.AIContent; } else { slotInfo.CurrentAlarm = ""; } break; case "OLP": OLPCommService srvOLP = new OLPCommService(tcp, e.SlotNumber); OLPInfo olpInfo = new OLPInfo(); olpInfo.RefreshData(srvOLP); slotInfo.HardwareVersion = olpInfo.Hardware_Version; slotInfo.SoftwareVersion = olpInfo.Software_Version; switch (olpInfo.Work_Mode) { case 0: slotInfo.WorkMode = "手动"; break; case 1: slotInfo.WorkMode = "自动"; break; default: break; } var alarmOLP = context.AlarmInformation .Where(a => a.DAddress == deviceView.IP && a.AISlot == slotInfo.Slot) .OrderByDescending(a => a.AITime).FirstOrDefault(); if (alarmOLP != null) { slotInfo.CurrentAlarm = alarmOLP.AIContent; } else { slotInfo.CurrentAlarm = ""; } break; default: slotInfo.CardType = "N/A"; slotInfo.HardwareVersion = "N/A"; slotInfo.SoftwareVersion = "N/A"; slotInfo.WorkMode = "N/A"; slotInfo.CurrentAlarm = "N/A"; break; } cardSlotInfo.Add(slotInfo); } context.Dispose(); return(cardSlotInfo); }
public ActionResult SetParam(string endpoint, string name, string value, int did) { JsonResult result = new JsonResult(); bool bSuccess = false; string operation = ""; int slot = 0; try { var arrPoint = endpoint.Split(':'); EDFAInfo edfaInfo = new EDFAInfo(); if (arrPoint.Length == 3) { slot = int.Parse(arrPoint[2]); TcpClientService tcp = new TcpClientService(arrPoint[0], int.Parse(arrPoint[1]), 200); EDFACommService service = new EDFACommService(tcp, slot); tcp.Connect(); edfaInfo.RefreshData(service); string methodName = "Set" + name.Replace("_", ""); var methodInfo = service.GetType().GetMethod(methodName); if (methodInfo != null) { //获取设置项 object[] arrDescription = methodInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (arrDescription != null && arrDescription.Length > 0) { DescriptionAttribute desc = (DescriptionAttribute)arrDescription[0]; if (desc != null) { operation = desc.Description; } } //获取方法参数信息 var paramInfo = methodInfo.GetParameters(); object[] paramObject = new object[paramInfo.Length]; int i = 0; foreach (var e in paramInfo) { paramObject[i] = Convert.ChangeType(value, e.ParameterType); } var ret = (bool)methodInfo.Invoke(service, paramObject); if (ret) { bSuccess = true; result.Data = new { Code = "", Data = "设置成功" }; } else { result.Data = new { Code = "101", Data = "设置失败" }; } } } else { result.Data = new { Code = "102", Data = "设置失败,未找到设置参数的方法" }; } //日志记录 using (var ctx = new GlsunViewEntities()) { var d = ctx.Device.Find(did); var log = ctx.DeviceOperationLog.Create(); var user = ctx.User.Where(u => u.ULoginName == HttpContext.User.Identity.Name).FirstOrDefault(); //基本信息 log.DID = d.ID; log.DName = d.DName; log.DAddress = d.DAddress; log.SID = d.Subnet.ID; log.SName = d.Subnet.SName; log.SAddress = d.Subnet.SAddress; log.UID = user.ID; log.ULoginName = user.ULoginName; log.UName = user.UName; //业务信息 log.DOLCardSN = edfaInfo.Serial_Number; log.DOLCardType = "EDFA"; log.DOLDeviceSlot = short.Parse(slot.ToString()); log.DOLOperationDetials = operation; log.DOLOperationType = "板卡配置"; log.DOLOperationResult = bSuccess ? "成功" : "失败"; log.DOLOperationTime = DateTime.Now; log.Remark = ""; ctx.DeviceOperationLog.Add(log); ctx.SaveChanges(); } } catch (Exception ex) { result.Data = new { Code = "Exception", Data = "设置时发生异常" }; } return(result); }
public ActionResult SetConfiguration(EDFAInfo edfaInfo, string ip, int port, int slot, string configItems, int mfId) { JsonResult result = new JsonResult(); var tcp = TcpClientServicePool.GetService(ip, port); if (tcp != null) { try { EDFACommService service = new EDFACommService(tcp, slot); List <string> listException = new List <string>(); var arrProperty = configItems.Split(','); Type t = edfaInfo.GetType(); Type srvType = service.GetType(); List <DeviceOperationLog> logs = new List <DeviceOperationLog>(); foreach (var p in arrProperty) { //获取属性 var prop = t.GetProperty(p); if (prop != null) { //获取属性值 var value = prop.GetValue(edfaInfo); var methodName = "Set" + p.Replace("_", ""); var methodInfo = srvType.GetMethod(methodName); string operation = ""; if (methodInfo != null) { //获取设置项说明 object[] arrDescription = methodInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (arrDescription != null && arrDescription.Length > 0) { DescriptionAttribute desc = (DescriptionAttribute)arrDescription[0]; if (desc != null) { operation = desc.Description; } } //获取方法参数信息 var paramInfo = methodInfo.GetParameters(); object[] paramObject = new object[paramInfo.Length]; foreach (var e in paramInfo) { paramObject[0] = Convert.ChangeType(value, e.ParameterType); } var ret = (bool)methodInfo.Invoke(service, paramObject); if (!ret) { listException.Add(operation); } var log = new DeviceOperationLog { DOLCardSN = edfaInfo.Serial_Number, DOLCardType = "EDFA", DOLDeviceSlot = short.Parse(slot.ToString()), DOLOperationDetials = string.Format("{0}", operation, value), DOLOperationType = "板卡配置", DOLOperationResult = ret ? "成功" : "失败", DOLOperationTime = DateTime.Now, Remark = "" }; logs.Add(log); } } } using (var ctx = new GlsunViewEntities()) { MachineFrame frame = ctx.MachineFrame.Find(mfId); var user = ctx.User.Where(u => u.ULoginName == HttpContext.User.Identity.Name).FirstOrDefault(); foreach (var log in logs) { //基本信息 log.DID = frame.ID; log.DName = frame.MFName; log.DAddress = frame.MFIP; log.UID = user.ID; log.ULoginName = user.ULoginName; log.UName = user.UName; } ctx.DeviceOperationLog.AddRange(logs); //异步保存不阻塞网页 ctx.SaveChanges(); } /*if (!service.SetWorkMode(edfaInfo.Work_Mode)) * { * listException.Add("工作模式"); * } * if (!service.SetGainSetting(edfaInfo.Gain_Setting)) * { * listException.Add("增益"); * }*/ if (listException.Count == 0) { result.Data = new { Code = "", Data = "配置成功" }; } else { string data = "配置失败:"; foreach (var e in listException) { data += e + " "; } result.Data = new { Code = "Exception", Data = data }; } } catch (Exception ex) { result.Data = new { Code = "Exception", Data = ex.Message }; } finally { TcpClientServicePool.FreeService(tcp); } } else { result.Data = new { Code = "Exception", Data = "获取TCP连接失败" }; } return(result); }