Esempio n. 1
0
        public static bool MergeAndWritePACFile(string gfwListResult)
        {
            //var stackTrace = new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(3));
            //var memberName = stackTrace.GetFrame(0).GetMethod().Name;
            //System.Diagnostics.Debug.WriteLine("-----------" + memberName);
            PACServer.TouchPACFile();
            var    original = PACServer.PacContent;
            string rules = null, userrules = null;

            if (!string.IsNullOrEmpty(gfwListResult))
            {
                var parse = ParseResult(gfwListResult);
                rules = SimpleJson.SimpleJson.SerializeObject(parse);
            }
            if (File.Exists(PACServer.USER_RULE_FILE))
            {
                string ur  = FileManager.NonExclusiveReadAllText(PACServer.USER_RULE_FILE, Encoding.UTF8);
                var    spl = ur.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Where(c => !c.StartsWith("!") && !c.StartsWith("["));
                userrules = SimpleJson.SimpleJson.SerializeObject(spl);
            }
            var result = PACServer.ReplaceContent(original, rules, userrules);

            if (original.Equals(result))
            {
                return(false);
            }
            PACServer.PacContent = result;
            return(true);
        }