Exemple #1
0
        //从配置文件默认读取解析的序号文本
        public static Boolean StartByScriptXml()
        {
            JsonFile jsonFile = new JsonFile();

            if (false == File.Exists(@".\script\script_config.json"))
            {
                Console.WriteLine("script_config.json is not exist");
                return(false);
            }
            string configContent = jsonFile.ReadFile(@".\script\script_config.json");

            //按照默认启动
            JObject jObject         = JObject.Parse(configContent);
            string  defaultConfigID = jObject["defaultConfigID"].ToString().Trim();
            string  currentConfigID = jObject["currentConfigId"].ToString().Trim();

            //更新json配置文件中的currentId
            currentID = int.Parse(defaultConfigID);
            jObject["currentConfigId"] = defaultConfigID;
            //删除再创建
            File.Delete(@".\script\script_config.json");
            jsonFile.WriteFile(@".\script\script_config.json", jObject.ToString());

            return(true);
        }
Exemple #2
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");
            }
        }
Exemple #3
0
        //通过热键启动解析对应序号的文本
        public static Boolean SetScriptTxt(int ID)
        {
            currentID = ID;
            JsonFile jsonFile = new JsonFile();
            JObject  jObject  = JObject.Parse(jsonFile.ReadFile(@".\script\script_config.json"));

            //更新json配置文件中的currentId
            jObject["currentConfigId"] = ID;
            //删除再创建
            File.Delete(@".\script\script_config.json");
            jsonFile.WriteFile(@".\script\script_config.json", jObject.ToString());
            return(true);
        }