Beispiel #1
0
        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);
        }
Beispiel #2
0
        // 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));
        }
Beispiel #3
0
        /// <summary>
        /// Create client
        /// </summary>
        /// <typeparam name="TEventHandler"></typeparam>
        /// <param name="port"></param>
        /// <param name="connect"></param>
        /// <param name="autoReconnect"></param>
        /// <returns></returns>
        public static Tuple <IClientService, TEventHandler> CreateClient <TEventHandler>(int port, bool connect = false, bool autoReconnect = false)
            where TEventHandler : IClientEventHandler
        {
            var eventHandler = Activator.CreateInstance <TEventHandler>();
            var client       = new TcpClientService(eventHandler,
                                                    new ClientConfig("127.0.0.1", port, autoReconnect),
                                                    _loggerFactory, EnumDataProcessorType.Hsm, (b) => b.ToList().Take(1).ToArray());

            if (connect)
            {
                client.Connect();
            }
            return(new Tuple <IClientService, TEventHandler>(client, eventHandler));
        }
Beispiel #4
0
        /// <summary>
        /// Runs client
        /// </summary>
        static void RunClient()
        {
            // setup client
            var config = new ClientConfig(_ipAddress, _port, false);
            TcpClientService client = new TcpClientService(new ClientEventHandler(), config, _loggerFactory, EnumDataProcessorType.Hsm);

            // UI commands
            Console.WriteLine("========================================================================");
            Console.WriteLine("Commands");
            Console.WriteLine("quit - Quits the program");
            Console.WriteLine("========================================================================");
            Console.WriteLine();

            // connect
            client.Connect();

            // read user input for messages to send to the server
            while (true)
            {
                string msg = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    // send
                    client.Send(Encoding.UTF8.GetBytes(msg));

                    // stop on exit message
                    if (msg.ToLowerInvariant() == "quit")
                    {
                        break;
                    }
                }
            }

            // disconnect
            client.Disconnect();

            // wait for user
            Console.ReadLine();
        }
Beispiel #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));
        }
Beispiel #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);
        }
Beispiel #7
0
        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);
        }