示例#1
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);
        }
示例#2
0
        /// <summary>
        /// 路由视图OLP部分
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="slot"></param>
        /// <returns></returns>
        public ActionResult RouteView(string ip, int port, int slot)
        {
            OLPInfo      olpInfo = new OLPInfo();
            OLPViewModel model   = new OLPViewModel()
            {
                IP   = ip,
                Port = port,
                Slot = slot
            };

            return(View(model));
        }
示例#3
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));
        }
示例#4
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);
        }
示例#5
0
        // GET: OLPCard
        public ActionResult Index(int did, int slot)
        {
            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);
            OLPCommService   service = new OLPCommService(tcp, slot);

            try
            {
                tcp.Connect();
                olpInfo.RefreshData(service);
            }
            catch (Exception ex)
            {
            }
            ViewBag.Did      = d.ID;
            ViewBag.EndPoint = d.DAddress + ":" + d.DPort.Value + ":" + slot.ToString();
            return(View(olpInfo));
        }
示例#6
0
        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);
        }
示例#7
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);
        }
示例#8
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));
        }
示例#9
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);
        }
示例#10
0
        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);
        }