示例#1
0
        /// <summary>
        /// Load items from KnowledgeData part - split by '|' and decoding type of item
        /// </summary>
        /// <returns></returns>
        private Dictionary <RegexKeyType, string[]> LoadItems()
        {
            var items = new Dictionary <RegexKeyType, string[]>();

            this.Content = this.Content.Replace("|", " | ");

            Regex.Split(this.Content, @"\s\| ")
            .Where(word => word.Contains("=")).ToList()
            .ForEach(item =>
            {
                var word = Regex.Split(item, "=");
                if (word.Count() == 2)
                {
                    var key   = WordUtils.TrimWhiteSpaces(word[0]);
                    var value = WordUtils.TrimWhiteSpaces(word[1]);

                    if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
                    {
                        var values = SplitMultipleValues(value);
                        var type   = new RegexKeyType();
                        type.Value = key;

                        try
                        {
                            items.Add(type, values);
                        }
                        catch { }
                    }
                }
            });

            return(items.Where(i => Attributes.Any(a => Regex.IsMatch(i.Key.Value, a.Value)))
                   .ToDictionary(i => {
                var key = i.Key;
                key.Type = Attributes.FirstOrDefault(a => Regex.Match(key.Value, a.Value).Success).Type;
                return key;
            },
                                 i => i.Value));
            //Attributes.FirstOrDefault(a => Regex.Match(i.Key, a).Success)
        }