// GET: NMUCard /// <summary> /// /// </summary> /// <param name="id">设备ID</param> /// <returns></returns> 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); NMUCommService service = new NMUCommService(tcp); NMUInfo nmuInfo = new NMUInfo(); try { tcp.Connect(); nmuInfo.RefreshStatus(service); } catch (Exception ex) { } tcp.Dispose(); //JavaScriptSerializer serializer = new JavaScriptSerializer(); //ViewBag.DeviceInfo = serializer.Serialize(deviceView); ViewBag.DID = d.ID; return(View(nmuInfo)); }
public ActionResult RealTimeStatus(int did) { var ret = new JsonResult(); ret.JsonRequestBehavior = JsonRequestBehavior.AllowGet; try { Device d = new Device(); using (var ctx = new GlsunViewEntities()) { d = ctx.Device.Find(did); } //IP地址->连接服务->实例化一个状态类->填充状态 TcpClientService tcp = new TcpClientService(d.DAddress, d.DPort.Value); NMUCommService service = new NMUCommService(tcp); NMUInfo nmuInfo = new NMUInfo(); tcp.Connect(); nmuInfo.RefreshStatus(service); tcp.Dispose(); ret.Data = new { Code = "", Data = nmuInfo }; } catch (Exception ex) { ret.Data = new { Code = "Exception", Data = "" }; } return(ret); }
public ActionResult SetParam(string endpoint, string name, string value, int did) { JsonResult result = new JsonResult(); bool bSuccess = false; string operation = ""; int slot = 0; try { OLPInfo olpInfo = new OLPInfo(); var arrPoint = endpoint.Split(':'); if (arrPoint.Length == 3) { slot = int.Parse(arrPoint[2]); TcpClientService tcp = new TcpClientService(arrPoint[0], int.Parse(arrPoint[1])); tcp.Connect(); OLPCommService service = new OLPCommService(tcp, slot); olpInfo.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 = "设置失败,未找到设置参数的方法" }; } tcp.Dispose(); } else { result.Data = new { Code = "100", 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 = olpInfo.Serial_Number; log.DOLCardType = "OLP"; 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 SetParam(string endpoint, SFPModule sfp, string paramName, int did) { JsonResult result = new JsonResult(); bool bSuccess = false; string operation = ""; int slot = 0; try { OEOInfo oeoInfo = new OEOInfo(); var arrPoint = endpoint.Split(':'); if (arrPoint.Length == 3 && sfp != null) { slot = int.Parse(arrPoint[2]); TcpClientService tcp = new TcpClientService(arrPoint[0], int.Parse(arrPoint[1])); OEOCommService service = new OEOCommService(tcp, slot); tcp.Connect(); oeoInfo.RefreshData(service); if (paramName == "Work_Mode") { operation = string.Format("设置光模块{0}工作模式", sfp.SlotPosition); bSuccess = service.SetWorkMode(sfp.SlotPosition, sfp.Work_Mode); } else if (paramName == "Tx_Power_Control") { operation = string.Format("设置光模块{0}发功率控制", sfp.SlotPosition); bSuccess = service.SetTxPowerControl(sfp.SlotPosition, sfp.Tx_Power_Control); } if (bSuccess) { result.Data = new { Code = "", Data = "设置成功" }; } else { result.Data = new { Code = "101", Data = "设置失败" }; } tcp.Dispose(); } else { result.Data = new { Code = "100", 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 = oeoInfo.Serial_Number; log.DOLCardType = "OEO"; 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); }