Esempio n. 1
0
        private void TryConfigureCacheDefault(Func <CacheOptions, CacheOptions> configure)
        {
            var match = WildcardMatch.All();

            _sitecore.Services.TryAdd(ServiceDescriptor.Singleton <IConfigureMatchingOptions <CacheOptions> >(
                                          new ConfigureMatchingOptions <CacheOptions>(match.Identifier, match, configure)));
        }
Esempio n. 2
0
        ///
        /// Converts a wildcard to a regex.
        ///
        /// The wildcard pattern to convert.
        /// A regex equivalent of the given wildcard.
        public static string WildcardToRegex(string pattern, WildcardMatch matchType)
        {
            string escapedPattern = Escape(pattern);

            escapedPattern = escapedPattern.Replace("\\*", ".*");
            escapedPattern = escapedPattern.Replace("\\?", ".");

            switch (matchType)
            {
            case WildcardMatch.Exact:
                return("^" + escapedPattern + "$");

            case WildcardMatch.Anywhere:
                return(escapedPattern);

            case WildcardMatch.StartsWith:
                return("^" + escapedPattern);

            case WildcardMatch.EndsWith:
                return(escapedPattern + "$");

            default:
                throw new ArgumentOutOfRangeException("matchType");
            }
        }
 public static SitecoreCachingConfigBuilder ConfigureCache <T>(
     this SitecoreCachingConfigBuilder configBuilder,
     string storeName,
     CacheEntryPriority?defaultEntryPriority = null)
 {
     return(configBuilder.ConfigureCaches(WildcardMatch.Named <T>(), storeName, defaultEntryPriority));
 }
        List <IMyTerminalBlock> findBlocks()
        {
            List <IMyTerminalBlock> matches = new List <IMyTerminalBlock>();

            GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(matches, (x => (WildcardMatch.IsLike(blockPattern, (x as IMyTerminalBlock).CustomName, false) && (type == null || isInstanceOf(type, (x as IMyTerminalBlock)))) && (x as IMyTerminalBlock).HasAction(action)));

            return(matches);
        }
Esempio n. 5
0
        public SitecoreCachingConfigBuilder ConfigureCaches(
            WildcardMatch cacheNamePattern,
            Action <CacheOptions> configureCache)
        {
            Condition.Requires(cacheNamePattern, nameof(cacheNamePattern)).IsNotNull();

            _sitecore.Services.ConfigureMatching(cacheNamePattern.Identifier, cacheNamePattern, configureCache);

            return(this);
        }
Esempio n. 6
0
        public SitecoreCachingConfigBuilder ConfigureCaches(
            WildcardMatch cacheNamePattern,
            string storeName,
            CacheEntryPriority?defaultEntryPriority = null)
        {
            Condition.Requires(cacheNamePattern, nameof(cacheNamePattern)).IsNotNull();

            return(ConfigureCaches(cacheNamePattern, o =>
            {
                o.StoreName = storeName;
                if (defaultEntryPriority != null)
                {
                    o.EntryPriority = defaultEntryPriority.Value;
                }
            }));
        }
Esempio n. 7
0
        /// 
        /// Converts a wildcard to a regex.
        /// 
        /// The wildcard pattern to convert.
        /// A regex equivalent of the given wildcard.
        public static string WildcardToRegex(string pattern, WildcardMatch matchType)
        {
            string escapedPattern = Escape(pattern);
            escapedPattern = escapedPattern.Replace("\\*", ".*");
            escapedPattern = escapedPattern.Replace("\\?", ".");

            switch (matchType)
            {
                case WildcardMatch.Exact:
                    return escapedPattern;
                case WildcardMatch.Anywhere:
                    return escapedPattern + "$";
                case WildcardMatch.StartsWith:
                    return "^" + escapedPattern;
                case WildcardMatch.EndsWith:
                    return "^" + escapedPattern + "$";
                default:
                    throw new ArgumentOutOfRangeException("matchType");
            }
        }
Esempio n. 8
0
 ///
 /// Initializes a wildcard with the given search pattern and options.
 ///
 /// The wildcard pattern to match.
 /// A combination of one or more
 /// .
 public WildCard(string pattern, RegexOptions options, WildcardMatch matchType)
     : base(WildcardToRegex(pattern, matchType), options)
 {
 }
Esempio n. 9
0
 ///
 /// Initializes a wildcard with the given search pattern.
 ///
 /// The wildcard pattern to match.
 public WildCard(string pattern, WildcardMatch matchType)
     : base(WildcardToRegex(pattern, matchType))
 {
 }
Esempio n. 10
0
        public void Selections_are_implicitly_anchored(string data, string pattern, bool isMatch)
        {
            var predicate = isMatch ? "matches" : "does not match";

            WildcardMatch.Like(data, pattern).ShouldBe(isMatch, $"'{pattern}' {predicate} '{data}'");
        }
Esempio n. 11
0
 /// 
 /// Initializes a wildcard with the given search pattern and options.
 /// 
 /// The wildcard pattern to match.
 /// A combination of one or more
 /// .
 public WildCard(string pattern, RegexOptions options, WildcardMatch matchType)
     : base(WildcardToRegex(pattern, matchType), options)
 {
 }
Esempio n. 12
0
 /// 
 /// Initializes a wildcard with the given search pattern.
 /// 
 /// The wildcard pattern to match.
 public WildCard(string pattern, WildcardMatch matchType)
     : base(WildcardToRegex(pattern, matchType))
 {
 }
Esempio n. 13
0
 public SitecoreCachingConfigBuilder ConfigureCacheDefaults(Action <CacheOptions> configureCache)
 {
     return(ConfigureCaches(WildcardMatch.All(), configureCache));
 }