Beispiel #1
0
        public void ParseScript()
        {
            try
            {
                int currentId = SignalBConfig.currentID;
                //先解析json文件
                JsonFile jsonFile   = new JsonFile();
                JArray   textJArray = JArray.Parse(jsonFile.ReadFile(@".\script\" + currentId + @".txt"));
                Console.WriteLine("read {0} file ok", (@".\script\" + currentId + @".txt"));
                IList <JToken>        results     = textJArray.Children().ToList();
                IList <ScriptMessage> messageList = new List <ScriptMessage>();
                foreach (JToken temp in results)
                {
                    ScriptMessage scriptTemp = temp.ToObject <ScriptMessage>();
                    messageList.Add(scriptTemp);
                }

                foreach (ScriptMessage scripTemp in messageList)
                {
                    SendHlMessageToUI(scripTemp);
                }
            }
            catch
            {
                Log.Error("Read script file fail: " + @".\script\" + SignalBConfig.currentID + @".txt");
            }
        }
Beispiel #2
0
        public void SendHlMessageToUI(ScriptMessage inputMessage)
        {
            //作一个随机延时20ms~50ms
            TimeDelay();
            //添加时间戳
            inputMessage.time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff");
            string originUI = inputMessage.UI;

            //区分三类消息,对应于界面呈现使用
            if (-1 != originUI.IndexOf("UE"))
            {
                inputMessage.NO = UENo++;
                inputMessage.UI = "UE";
                string msg = JsonConvert.SerializeObject(inputMessage);
                PublishHelper.PublishMsg("HlSignalMsg", msg);
                //记录日志
                logMsg.WriteLog(LogOfType.UE_MSGLOG, msg);
            }
            if (-1 != originUI.IndexOf("eNB"))
            {
                inputMessage.NO = eNBNo++;
                inputMessage.UI = "eNB";
                string msg = JsonConvert.SerializeObject(inputMessage);
                PublishHelper.PublishMsg("HlSignalMsg", msg);
                //记录日志
                logMsg.WriteLog(LogOfType.eNB_MSGLOG, msg);
            }
            if (-1 != originUI.IndexOf("gNB"))
            {
                inputMessage.NO = gNBNo++;
                inputMessage.UI = "gNB";
                string msg = JsonConvert.SerializeObject(inputMessage);
                PublishHelper.PublishMsg("HlSignalMsg", msg);
                //记录日志
                logMsg.WriteLog(LogOfType.gNB_MSGLOG, msg);
            }
        }
Beispiel #3
0
        public void WriteLog(LogOfType type, string info)
        {
            string fileName = GetFileName(type);

            if ("" == fileName)
            {
                return;
            }
            try
            {
                if (!File.Exists(fileName))
                {
                    fileStream = System.IO.File.Create(fileName);
                    writer     = new StreamWriter(fileStream);
                }
                else
                {
                    writer = File.AppendText(fileName);
                }
                //把消息写入文件
                ScriptMessage message = JsonConvert.DeserializeObject <ScriptMessage>(info);
                writer.WriteLine(DateTime.Now + ":");
                writer.WriteLine("    " + "No:" + message.NO.ToString() + "    Time:" + message.time.ToString());
                writer.WriteLine("    " + "UEID:" + message.ENBUEID.ToString() + "    Message:" + message.message.ToString());
                writer.WriteLine("    " + "Source:" + message.MessageSource.ToString() + "    Destination:" + message.MessageDestination.ToString());
                writer.WriteLine("    " + "data:" + message.data.ToString());
            }
            catch (Exception e)
            {
                Log.Error("open file " + fileName + " fail" + e.Message);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                    writer.Dispose();
                    fileStream.Close();
                    fileStream.Dispose();
                }
            }

            long size = 0;

            //获取文件大小
            //文件大小(byte)
            using (FileStream file = File.OpenRead(fileName))
            {
                size = file.Length;
            }

            //判断日志文件大于2M,创建新的文件
            if (size > (1024 * 1024 * 2))
            {
                if (LogOfType.UE_MSGLOG == type)
                {
                    logUEFile = "";
                }
                else if (LogOfType.gNB_MSGLOG == type)
                {
                    loggNBFile = "";
                }
                else if (LogOfType.eNB_MSGLOG == type)
                {
                    logeNBFile = "";
                }
            }
        }