コード例 #1
0
 public void Enable(FilterParser filterParser)
 {
     _currentFilter = filterParser;
     CollectionView.View.Refresh();
     _thumbnailDispatcherTimer.Start();
 }
コード例 #2
0
 public void UpdateSearchText(FilterParser filterParser)
 {
     _currentFilter = filterParser;
     CollectionView.View.Refresh();
 }
コード例 #3
0
        public static FilterParser ParseString(string s)
        {
            var searchText = new StringBuilder();
            var parts      = s.Split('"')
                             .Select((element, index) => index % 2 == 0                   // If even index
                    ? element.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) // Split the item
                    : new[] { element })                                                  // Keep the entire item
                             .SelectMany(element => element).ToList();

            var result = new FilterParser();

            foreach (var part in parts)
            {
                var trueCondition  = part.StartsWith("is:", StringComparison.OrdinalIgnoreCase);
                var falseCondition = part.StartsWith("isnot:", StringComparison.OrdinalIgnoreCase);

                if (trueCondition || falseCondition)
                {
                    switch (part.Substring(trueCondition ? 3 : 6, part.Length - (trueCondition ? 3 : 6)).ToLower())
                    {
                    case "online":
                        result.IsOnline = trueCondition;
                        break;

                    case "administrator":
                    case "admin":
                        result.IsAdministrator = trueCondition;
                        break;

                    case "compatible":
                        result.Compatible = trueCondition;
                        break;
                    }
                    continue;
                }

                if (Regex.IsMatch(part, "^CI-[0-9]{1,6}$", RegexOptions.IgnoreCase))
                {
                    result.ClientId = int.Parse(part.Substring(3));
                    continue;
                }

                if (part.Contains(":"))
                {
                    var split = part.Split(new[] { ':' }, 2);
                    switch (split[0].ToLower())
                    {
                    case "username":
                    case "name":
                    case "user":
                        result.Username = split[1];
                        continue;

                    case "osname":
                    case "os":
                    case "operatingsystem":
                        result.OsName = split[1];
                        continue;

                    case "language":
                    case "lang":
                        result.Language = split[1];
                        continue;

                    case "clientid":
                        int clientId;
                        if (int.TryParse(split[1], out clientId))
                        {
                            result.ClientId = clientId;
                        }
                        continue;

                    case "group":
                        result.Group = split[1];
                        continue;

                    case "country":
                    case "location":
                        result.Country = split[1];
                        continue;
                    }
                }

                if (searchText.Length != 0)
                {
                    searchText.Append(" ");
                }

                searchText.Append(part);
            }

            result.SearchText = searchText.ToString();
            return(result);
        }