Exemple #1
0
        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);
        }
Exemple #2
0
        public ActionResult UpdateConfig(string ip, int port, int slot)
        {
            JsonResult result  = new JsonResult();
            OLPInfo    olpInfo = new OLPInfo();
            var        tcp     = TcpClientServicePool.GetService(ip, port);

            if (tcp != null)
            {
                try
                {
                    OLPCommService service = new OLPCommService(tcp, slot);
                    olpInfo.RefreshData(service);
                    result.Data = new { Code = "", Data = olpInfo };
                }
                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);
        }
Exemple #3
0
        /// <summary>
        /// 配置路由
        /// </summary>
        /// <param name="model"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public ActionResult ConfigRoute(RouteViewModel model, string property, int value)
        {
            JsonResult result = new JsonResult();
            var        tcpA   = TcpClientServicePool.GetService(model.AIP, model.APort);
            var        tcpB   = TcpClientServicePool.GetService(model.BIP, model.BPort);

            if (tcpA == null)
            {
                result.Data = new { Code = "Exception", Data = "获取A端TCP连接失败" };
            }
            else if (tcpB == null)
            {
                result.Data = new { Code = "Exception", Data = "获取B端TCP连接失败" };
            }
            if (tcpA != null && tcpB != null)
            {
                try
                {
                    List <string> listException = new List <string>();
                    //设置方法名
                    string         methodName = "Set" + property.Replace("_", "");
                    OLPCommService serviceA   = new OLPCommService(tcpA, model.ASlot);
                    bool           ret        = (bool)ReflectionHelper.InvokeMethod(serviceA, methodName, new object[] { value });
                    if (!ret)
                    {
                        listException.Add("A端线路");
                    }
                    OLPCommService serviceB = new OLPCommService(tcpB, model.BSlot);
                    ret = (bool)ReflectionHelper.InvokeMethod(serviceB, methodName, new object[] { value });
                    if (!ret)
                    {
                        listException.Add("B端线路");
                    }
                    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(tcpA);
                    TcpClientServicePool.FreeService(tcpB);
                }
            }
            return(result);
        }
Exemple #4
0
        // 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));
        }
Exemple #5
0
        /// <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));
        }
Exemple #6
0
        /// <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)
        {
            OLPInfo      olpInfo = new OLPInfo();
            OLPViewModel model   = new OLPViewModel()
            {
                IP   = ip,
                Port = port,
                Slot = slot
            };

            var tcp = TcpClientServicePool.GetService(ip, port);

            if (tcp != null)
            {
                try
                {
                    OLPCommService service = new OLPCommService(tcp, slot);
                    olpInfo.RefreshData(service);
                    model.Type            = olpInfo.Card_Type;
                    model.Status          = "正常";
                    model.ProductModel    = "OTS-" + model.Type;
                    model.SerialNumber    = olpInfo.Serial_Number;
                    model.HardwareVersion = olpInfo.Hardware_Version;
                    model.SoftwareVersion = olpInfo.Software_Version;
                    model.WorkMode        = olpInfo.Work_Mode;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    TcpClientServicePool.FreeService(tcp);
                }
            }
            ViewBag.MFID = mfId;
            return(View(model));
        }
Exemple #7
0
        public ActionResult RealTimeStatus(int did, int slot)
        {
            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            try
            {
                string key  = string.Format("olp_info_{0}", did);
                var    info = MemoryCacheHelper.GetCacheItem <OLPInfo>(key,
                                                                       () =>
                {
                    Device d = null;
                    using (var ctx = new GlsunViewEntities())
                    {
                        d = ctx.Device.Find(did);
                    }
                    OLPInfo olpInfo = new OLPInfo();
                    //TcpClientService tcp = new TcpClientService(d.DAddress, d.DPort.Value);
                    var tcp = TcpClientServicePool.GetService(d.DAddress, d.DPort.Value);
                    if (tcp == null)
                    {
                        throw new NullReferenceException();
                    }
                    OLPCommService service = new OLPCommService(tcp, slot);
                    olpInfo.RefreshData(service);
                    TcpClientServicePool.FreeService(tcp);
                    return(olpInfo);
                },
                                                                       null, DateTime.Now.AddSeconds(2));
                result.Data = new { Code = "", Data = info };
            }
            catch (Exception ex)
            {
                result.Data = new { Code = "Exception", Data = "" };
            }
            return(result);
        }
        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);
        }
Exemple #9
0
        /// <summary>
        /// OLP配置
        /// </summary>
        /// <param name="info"></param>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="slot"></param>
        /// <returns></returns>
        public ActionResult SetConfiguration(OLPInfo info, int mfId, string ip, int port, int slot, string configItems)
        {
            JsonResult result = new JsonResult();
            var        tcp    = TcpClientServicePool.GetService(ip, port);

            if (tcp != null)
            {
                try
                {
                    var                       arrProperty   = configItems.Split(',');
                    List <string>             listException = new List <string>();
                    OLPCommService            service       = new OLPCommService(tcp, slot);
                    List <string>             listMethod    = new List <string>();
                    Type                      t             = info.GetType();
                    List <DeviceOperationLog> logs          = new List <DeviceOperationLog>();
                    foreach (var p in arrProperty.OrderBy(e => e))
                    {
                        //获取属性
                        var prop = t.GetProperty(p);
                        if (prop != null)
                        {
                            string name  = prop.Name;
                            object value = prop.GetValue(info);
                            //设置方法名
                            string methodName = "Set" + name.Replace("_", "");
                            var    methodInfo = service.GetType().GetMethod(methodName);
                            if (methodInfo != null)
                            {
                                listMethod.Add(methodInfo.Name);
                                string operation = "";
                                //获取设置项说明
                                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           = info.Serial_Number,
                                    DOLCardType         = "OLP",
                                    DOLDeviceSlot       = short.Parse(slot.ToString()),
                                    DOLOperationDetials = operation,
                                    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 (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);
        }
Exemple #10
0
        /// <summary>
        /// 设备连线跳转到路由
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult LinkRoute(int id)
        {
            RouteViewModel routeView = new RouteViewModel();

            using (var ctx = new GlsunViewEntities())
            {
                DeviceLine line  = ctx.DeviceLine.Find(id);
                Route      route = ctx.Route.Find(line.RID);

                MachineFrame frameA = ctx.MachineFrame.Find(route.RAMFID);
                MachineFrame frameB = ctx.MachineFrame.Find(route.RBMFID);

                if (route != null)
                {
                    routeView.RouteName     = route.RName;
                    routeView.AName         = route.RAName;
                    routeView.AIP           = frameA.MFIP;
                    routeView.APort         = frameA.MFPort.Value;
                    routeView.ASlot         = route.RASlot.Value;
                    routeView.ACardPosition = string.Format("A框{0}-盘{1}", routeView.AIP, routeView.ASlot);
                    routeView.ACardType     = "OLP";
                    routeView.BName         = route.RBName;
                    routeView.BIP           = frameB.MFIP;
                    routeView.BPort         = frameB.MFPort.Value;
                    routeView.BSlot         = route.RBSlot.Value;
                    routeView.BCardPosition = string.Format("B框{0}-盘{1}", routeView.BIP, routeView.BSlot);
                    routeView.BCardType     = "OLP";
                }
            }
            OLPInfo olpInfo = new OLPInfo();
            var     tcp     = TcpClientServicePool.GetService(routeView.AIP, routeView.APort);

            if (tcp != null)
            {
                OLPCommService service = new OLPCommService(tcp, routeView.ASlot);
                try
                {
                    olpInfo.RefreshData(service);
                    routeView.ACardType  = olpInfo.Card_Type;
                    routeView.AWorkRoute = olpInfo.Manual_Switch_Channel;
                }
                catch
                {
                    routeView.ACardType  = "";
                    routeView.AWorkRoute = 1;
                }
                finally
                {
                    TcpClientServicePool.FreeService(tcp);
                }
            }
            tcp = TcpClientServicePool.GetService(routeView.BIP, routeView.BPort);
            if (tcp != null)
            {
                OLPCommService service = new OLPCommService(tcp, routeView.BSlot);
                try
                {
                    olpInfo.RefreshData(service);
                    routeView.BCardType  = olpInfo.Card_Type;
                    routeView.BWorkRoute = olpInfo.Manual_Switch_Channel;
                }
                catch
                {
                    routeView.BCardType  = "";
                    routeView.BWorkRoute = 1;
                }
                finally
                {
                    TcpClientServicePool.FreeService(tcp);
                }
            }
            return(View("Index", routeView));
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        /// <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)
        {
            OEOInfo      oeoInfo = new OEOInfo();
            OEOViewModel model   = new OEOViewModel()
            {
                IP   = ip,
                Port = port,
                Slot = slot
            };
            var tcp = TcpClientServicePool.GetService(ip, port);

            if (tcp != null)
            {
                try
                {
                    OEOCommService service = new OEOCommService(tcp, slot);
                    oeoInfo.RefreshData(service);
                    tcp.IsBusy            = false;
                    model.Type            = "OEO";
                    model.Status          = "正常";
                    model.ProductModel    = "OTS-OEO";
                    model.SerialNumber    = oeoInfo.Serial_Number;
                    model.HardwareVersion = oeoInfo.Hardware_Version;
                    model.SoftwareVersion = oeoInfo.Software_Version;

                    //设置OEO卡的工作模式
                    List <int> workModeSet = new List <int>();
                    foreach (var sfp in oeoInfo.SFPSet)
                    {
                        if (sfp.Status == 1)
                        {
                            if (!workModeSet.Contains(sfp.Work_Mode))
                            {
                                workModeSet.Add(sfp.Work_Mode);
                            }
                        }
                    }
                    string workMode = "";
                    foreach (var mode in workModeSet)
                    {
                        string text = "";
                        switch (mode)
                        {
                        case 1:
                            text = "转发";
                            break;

                        case 3:
                            text = "交叉";
                            break;
                        }
                        if (!string.IsNullOrWhiteSpace(workMode))
                        {
                            workMode += "+" + text;
                        }
                        else
                        {
                            workMode = text;
                        }
                    }
                    model.WorkMode = workMode;
                }
                finally
                {
                    TcpClientServicePool.FreeService(tcp);
                }
            }
            ViewBag.MFID = mfId;
            return(View(model));
        }
Exemple #13
0
        /// <summary>
        /// OEO配置
        /// </summary>
        /// <param name="modules"></param>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="slot"></param>
        /// <returns></returns>
        public ActionResult SetConfiguration(List <SFPModule> modules, int mfId, string ip, int port, int slot, List <SFPModuleConfigRecord> records)
        {
            JsonResult result = new JsonResult();
            var        tcp    = TcpClientServicePool.GetService(ip, port);

            if (tcp != null)
            {
                try
                {
                    List <DeviceOperationLog> logs          = new List <DeviceOperationLog>();
                    List <string>             listException = new List <string>();
                    OEOInfo        oeoInfo = new OEOInfo();
                    OEOCommService service = new OEOCommService(tcp, slot);
                    oeoInfo.RefreshData(service);
                    var srvType = service.GetType();
                    foreach (var sfp in modules)
                    {
                        var record = (from r in records
                                      where r.Slot == sfp.SlotPosition
                                      select r).FirstOrDefault();
                        if (record != null)
                        {
                            foreach (var p in record.ChangeItems)
                            {
                                //获取属性
                                var prop = sfp.GetType().GetProperty(p);
                                if (prop != null)
                                {
                                    //获取属性值
                                    var    value      = prop.GetValue(sfp);
                                    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];
                                        object[] values      = new object[] { sfp.SlotPosition, value };
                                        int      i           = 0;
                                        foreach (var e in paramInfo)
                                        {
                                            paramObject[i] = Convert.ChangeType(values[i], e.ParameterType);
                                            i++;
                                        }
                                        var ret = (bool)methodInfo.Invoke(service, paramObject);
                                        if (!ret)
                                        {
                                            listException.Add(string.Format("光模块{0}", sfp.SlotPosition) + operation);
                                        }
                                        var log = new DeviceOperationLog
                                        {
                                            DOLCardSN           = oeoInfo.Serial_Number,
                                            DOLCardType         = "OEO",
                                            DOLDeviceSlot       = short.Parse(slot.ToString()),
                                            DOLOperationDetials = string.Format("光模块{0}{1}", sfp.SlotPosition, operation),
                                            DOLOperationType    = "板卡配置",
                                            DOLOperationResult  = ret ? "成功" : "失败",
                                            DOLOperationTime    = DateTime.Now,
                                            Remark = ""
                                        };
                                        logs.Add(log);
                                    }
                                }
                            }
                        }

                        /*if(!service.SetWorkMode(sfp.SlotPosition, sfp.Work_Mode))
                         * {
                         *  listException.Add(string.Format("SFP模块{0}工作模式", sfp.SlotPosition));
                         * }
                         * if(!service.SetTxPowerControl(sfp.SlotPosition, sfp.Tx_Power_Control))
                         * {
                         *  listException.Add(string.Format("SFP模块{0}发功率控制", sfp.SlotPosition));
                         * }*/
                    }
                    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 };
                    }
                    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();
                    }
                }
                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);
        }
        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>();
            }
        }