Ejemplo n.º 1
0
        private void loadContents(string contents)
        {
            string[] names   = typeof(PresetBase).GetFields().Select(x => x.Name).ToArray();
            string   missing = string.Empty;

            for (int i = 0; i < names.Length; i++)
            {
                // If content don’t have some property then...
                if (!contents.Contains("\"" + names[i] + "\":"))
                {
                    missing += "\t\"" + names[i] + "\": null,\r\n";
                }
            }
            if (!string.IsNullOrEmpty(missing))
            {
                contents = "{" + missing + contents.Substring(contents.IndexOf('{') + 1);
            }
            PresetBase item = (PresetBase)JocysCom.ClassLibrary.Runtime.Serializer.DeserializeFromJson(contents, typeof(PresetBase));

            PresetName          = (item.PresetName != null) ? item.PresetName : PresetName;
            PresetDescription   = (item.PresetDescription != null) ? item.PresetDescription : PresetDescription;
            PresetRemarks       = (item.PresetRemarks != null) ? item.PresetRemarks : PresetRemarks;
            PasswordLength      = item.PasswordLength.HasValue ? item.PasswordLength.Value : PasswordLength;
            UseNumbers          = item.UseNumbers.HasValue ? item.UseNumbers.Value : UseNumbers;
            UseUppercase        = item.UseUppercase.HasValue ? item.UseUppercase.Value : UseUppercase;
            UseLowercase        = item.UseLowercase.HasValue ? item.UseLowercase.Value : UseLowercase;
            UseSymbols          = item.UseSymbols.HasValue ? item.UseSymbols.Value : UseSymbols;
            UseExtra            = item.UseExtra.HasValue ? item.UseExtra.Value : UseExtra;
            RatioNumbers        = item.RatioNumbers.HasValue ? item.RatioNumbers.Value : RatioNumbers;
            RatioUppercase      = item.RatioUppercase.HasValue ? item.RatioUppercase.Value : RatioUppercase;
            RatioLowercase      = item.RatioLowercase.HasValue ? item.RatioLowercase.Value : RatioLowercase;
            RatioSymbols        = item.RatioSymbols.HasValue ? item.RatioSymbols.Value : RatioSymbols;
            RatioExtra          = item.RatioExtra.HasValue ? item.RatioExtra.Value : RatioExtra;
            CharsNumbers        = (item.CharsNumbers != null) ? item.CharsNumbers : CharsNumbers;
            CharsUppercase      = (item.CharsUppercase != null) ? item.CharsUppercase : CharsUppercase;
            CharsLowercase      = (item.CharsLowercase != null) ? item.CharsLowercase : CharsLowercase;
            CharsSymbols        = (item.CharsSymbols != null) ? item.CharsSymbols : CharsSymbols;
            CharsExtra          = (item.CharsExtra != null) ? item.CharsExtra : CharsExtra;
            FilterRemember      = item.FilterRemember.HasValue ? item.FilterRemember.Value : FilterRemember;
            FilterKeyboard      = item.FilterKeyboard.HasValue ? item.FilterKeyboard.Value : FilterKeyboard;
            FilterEnforce       = item.FilterEnforce.HasValue ? item.FilterEnforce.Value : FilterEnforce;
            FilterPhone         = item.FilterPhone.HasValue ? item.FilterPhone.Value : FilterPhone;
            FilterAscii         = item.FilterAscii.HasValue ? item.FilterAscii.Value : FilterAscii;
            FilterChars         = item.FilterChars.HasValue ? item.FilterChars.Value : FilterChars;
            FilterCharsString   = item.FilterCharsString != null ? item.FilterCharsString : FilterCharsString;
            ScriptEnabled       = item.ScriptEnabled.HasValue ? item.ScriptEnabled.Value : ScriptEnabled;
            ScriptLanguage      = (item.ScriptLanguage != null) ? item.ScriptLanguage : ScriptLanguage;
            ScriptEntry         = item.ScriptEntry != null ? item.ScriptEntry : ScriptEntry;
            ScriptCode          = (item.ScriptCode != null) ? item.ScriptCode : ScriptCode;
            RegexEnabled        = item.RegexEnabled.HasValue ? item.RegexEnabled.Value : RegexEnabled;
            RegexPatternFind    = (item.RegexPatternFind != null) ? item.RegexPatternFind : RegexPatternFind;
            RegexPatternReplace = (item.RegexPatternReplace != null) ? item.RegexPatternReplace : RegexPatternReplace;
            RegexIgnoreCase     = item.RegexIgnoreCase.HasValue ? item.RegexIgnoreCase.Value : RegexIgnoreCase;
        }
Ejemplo n.º 2
0
        public string SaveAs(string fileName)
        {
            PresetBase item = new PresetBase();

            item.PresetName          = PresetName;
            item.PresetDescription   = PresetDescription;
            item.PresetRemarks       = PresetRemarks;
            item.PasswordLength      = PasswordLength;
            item.UseUppercase        = UseUppercase;
            item.UseLowercase        = UseLowercase;
            item.UseNumbers          = UseNumbers;
            item.UseSymbols          = UseSymbols;
            item.UseExtra            = UseExtra;
            item.RatioUppercase      = RatioUppercase;
            item.RatioLowercase      = RatioLowercase;
            item.RatioNumbers        = RatioNumbers;
            item.RatioSymbols        = RatioSymbols;
            item.RatioExtra          = RatioExtra;
            item.CharsUppercase      = CharsUppercase;
            item.CharsLowercase      = CharsLowercase;
            item.CharsNumbers        = CharsNumbers;
            item.CharsSymbols        = CharsSymbols;
            item.CharsExtra          = CharsExtra;
            item.FilterRemember      = FilterRemember;
            item.FilterKeyboard      = FilterKeyboard;
            item.FilterEnforce       = FilterEnforce;
            item.FilterPhone         = FilterPhone;
            item.FilterAscii         = FilterAscii;
            item.FilterChars         = FilterChars;
            item.FilterCharsString   = FilterCharsString;
            item.ScriptEnabled       = ScriptEnabled;
            item.ScriptLanguage      = ScriptLanguage;
            item.ScriptEntry         = ScriptEntry;
            item.ScriptCode          = ScriptCode;
            item.RegexEnabled        = RegexEnabled;
            item.RegexPatternFind    = RegexPatternFind;
            item.RegexPatternReplace = RegexPatternReplace;
            item.RegexIgnoreCase     = RegexIgnoreCase;
            string contents = JocysCom.ClassLibrary.Runtime.Serializer.SerializeToJson(item);

            contents = contents.TrimStart('{');
            contents = contents.TrimEnd('}');
            MemberInfo[] members = this.GetType().GetMembers();
            for (int i = 0; i < members.Length; i++)
            {
                string find = string.Format(",\"{0}\":", members[i].Name);
                string repl = string.Format(",\r\n\t\"{0}\":", members[i].Name);
                contents = contents.Replace(find, repl);
            }
            contents = "{\r\n\t" + contents + "\r\n}";
            System.IO.File.WriteAllText(fileName, contents);
            return(contents);
        }