Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connects a client
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonClientConnect_Click(object sender, EventArgs e)
        {
            // already running
            if (_client != null)
            {
                return;
            }

            // check port numeric
            int port;

            if (!int.TryParse(textBoxClientPort.Text, out port))
            {
                MessageBox.Show("Port must be numeric.", "Configuration error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // set encoding
            int codePage = ((KeyValuePair <int, string>)comboBoxClientEncoding.SelectedItem).Key;

            ClientEncoding = Encoding.GetEncoding(codePage);

            // setup client
            _client = _provider.GetService <TcpClientService>();

            // connect
            _client.ConnectAsync();
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Disconnects a client
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonClientDisconnect_Click(object sender, EventArgs e)
 {
     if (_client != null)
     {
         _client.Disconnect();
         _client = null;
     }
 }
Ejemplo n.º 5
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Constructor. </summary>
        ///
        /// <remarks>   Justin, 7/11/2015. </remarks>
        ///
        /// <param name="ipaddr">   The ipaddr. </param>
        /// <param name="nPort">    The port. </param>
        ///-------------------------------------------------------------------------------------------------
        public TcpListenerService(IPAddress ipaddr, int nPort)
        {
            //create an instance of the client service
            MTcpClientService = new TcpClientService();

            //create a listener with ip and port number
            MTcpListener = new TcpListener(ipaddr, nPort);
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }