예제 #1
0
 public void RecordConfig(User user, MachineFrame frame, List <DeviceOperationLog> logs)
 {
     using (var ctx = new GlsunViewEntities())
     {
         ctx.DeviceOperationLog.AddRange(logs);
     }
 }
예제 #2
0
        // GET: MachineFrame/Create
        public ActionResult Create()
        {
            MachineFrame frame = new MachineFrame();

            SetMachineData();
            ViewBag.Action = "Create";
            return(View(frame));
        }
예제 #3
0
        public ActionResult Edit(MachineFrame frame, HttpPostedFileBase iconFile)
        {
            var json = new JsonResult();

            try
            {
                string iconFileName = "";
                if (iconFile != null)
                {
                    iconFileName = SaveIcon(iconFile);
                }
                using (var ctx = new GlsunViewEntities())
                {
                    var loginUser = (from u in ctx.User
                                     where u.ULoginName == HttpContext.User.Identity.Name
                                     select u).FirstOrDefault();

                    var frameModify = (from r in ctx.MachineFrame
                                       where r.ID == frame.ID
                                       select r).FirstOrDefault();

                    frameModify.MFName      = frame.MFName;
                    frameModify.MFIP        = frame.MFIP;
                    frameModify.MFPort      = frame.MFPort;
                    frameModify.MSID        = frame.MSID;
                    frameModify.MFMCUType   = frame.MFMCUType;
                    frameModify.MSLayer     = frame.MSLayer;
                    frameModify.MFIcon      = frame.MFIcon;
                    frameModify.Remark      = frame.Remark;
                    frameModify.EditorID    = loginUser.ID;
                    frameModify.EditingTime = DateTime.Now;
                    //图标没值
                    if (string.IsNullOrWhiteSpace(frameModify.MFIcon))
                    {
                        frameModify.MFIcon = iconFileName;
                    }
                    ctx.SaveChanges();
                }
                json.Data = new { Code = "", Data = "", Message = "保存成功" };
            }
            catch (Exception ex)
            {
                json.Data = new { Code = "Exception", Data = "", Message = ex.Message };
            }
            return(json);
        }
예제 #4
0
        public ActionResult GetMachineFrame(int id)
        {
            var json = new JsonResult();

            try
            {
                MachineFrame frame = null;
                using (var ctx = new GlsunViewEntities())
                {
                    frame = ctx.MachineFrame.Find(id);
                }
                json.Data = new { Code = "", Data = new MachineFrame {
                                      MFIP = frame.MFIP, MFPort = frame.MFPort, MFMCUType = frame.MFMCUType
                                  },
                                  Message = "保存成功" };
            }
            catch (Exception ex)
            {
                json.Data = new { Code = "Exception", Data = "", Message = ex.Message };
            }
            return(json);
        }
예제 #5
0
        // GET: MachineFrame/Edit/5
        public ActionResult Edit(int id)
        {
            MachineFrame frame  = null;
            int          roomID = 0;

            using (var ctx = new GlsunViewEntities())
            {
                frame = ctx.MachineFrame.Find(id);
                if (frame != null)
                {
                    roomID = (from shelf in ctx.MachineShelf
                              join room in ctx.MachineRoom
                              on shelf.MRID equals room.ID
                              where shelf.ID == frame.MSID.Value
                              select room.ID).First();
                }
            }
            SetMachineData();
            ViewBag.Action = "Edit";
            ViewBag.RoomID = roomID;
            return(View("Create", frame));
        }
예제 #6
0
        public ActionResult Create(MachineFrame frame, HttpPostedFileBase iconFile)
        {
            var json = new JsonResult();

            try
            {
                string iconFileName = "";
                if (iconFile != null)
                {
                    iconFileName = SaveIcon(iconFile);
                }
                using (var ctx = new GlsunViewEntities())
                {
                    var loginUser = (from u in ctx.User
                                     where u.ULoginName == HttpContext.User.Identity.Name
                                     select u).FirstOrDefault();
                    if (loginUser != null)
                    {
                        frame.CreatorID    = loginUser.ID;
                        frame.CreationTime = DateTime.Now;
                    }
                    //图标没值
                    if (string.IsNullOrWhiteSpace(frame.MFIcon))
                    {
                        frame.MFIcon = iconFileName;
                    }
                    ctx.MachineFrame.Add(frame);
                    ctx.SaveChanges();
                }
                json.Data = new { Code = "", Data = "", Message = "保存成功" };
            }
            catch (Exception ex)
            {
                json.Data = new { Code = "Exception", Data = "", Message = ex.Message };
            }
            return(json);
        }
예제 #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
        /// <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);
        }
예제 #10
0
        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>();
            }
        }