当前位置: 首页>>代码示例>>C#>>正文


C# IFilter.Matches方法代码示例

本文整理汇总了C#中IFilter.Matches方法的典型用法代码示例。如果您正苦于以下问题:C# IFilter.Matches方法的具体用法?C# IFilter.Matches怎么用?C# IFilter.Matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFilter的用法示例。


在下文中一共展示了IFilter.Matches方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnumerateFileSystemEntries

        /// <summary>
        /// Returns a list of all files and subfolders found in the given folder.
        /// The search is recursive.
        /// </summary>
        /// <param name="basepath">The folder to look in.</param>
        /// <param name="filter">The filter to apply.</param>
        /// <returns>A list of the full filenames and foldernames. Foldernames ends with the directoryseparator char</returns>
        public static IEnumerable<string> EnumerateFileSystemEntries(string basepath, IFilter filter)
        {
            IFilter match;
            filter = filter ?? new FilterExpression();
            return EnumerateFileSystemEntries(basepath, (rootpath, path, attributes) => {
                bool result;
                if (!filter.Matches(path, out result, out match))
                    result = true;

                return result;
            });
        }
开发者ID:Berimor66,项目名称:duplicati,代码行数:19,代码来源:Utility.cs

示例2: Matches

        /// <summary>
        /// Utility function to match a filter with a default fall-through value
        /// </summary>
        /// <param name="filter">The filter to evaluate</param>
        /// <param name="path">The path to evaluate</param>
        /// <param name="match">The filter that matched</param>
        public static bool Matches(IFilter filter, string path, out IFilter match)
        {
            if (filter == null || filter.Empty)
            {
                match = null;
                return true;
            }
        
            bool result;
            if (filter.Matches(path, out result, out match))
                return result;

            var includes = false;
            var excludes = false;

            Tuple<bool, bool> cacheLookup;

            // Check for cached results
            lock(_matchLock)
                if (_matchFallbackLookup.TryGetValue(filter, out cacheLookup))
                {
                    includes = cacheLookup.Item1;
                    excludes = cacheLookup.Item2;
                }

            // Figure out what components are in the filter
            if (cacheLookup == null)
            {
                var q = new Queue<IFilter>();
                q.Enqueue(filter);

                while (q.Count > 0)
                {
                    var p = q.Dequeue();
                    if (p == null || p.Empty)
                        continue;
                    else if (p is FilterExpression)
                    {
                        if (((FilterExpression)p).Result)
                            includes = true;
                        else
                            excludes = true;
                    }
                    else if (p is JoinedFilterExpression)
                    {
                        q.Enqueue(((JoinedFilterExpression)p).First);
                        q.Enqueue(((JoinedFilterExpression)p).Second);
                    }
                }

                // Populate the cache
                lock(_matchLock)
                {
                    if (_matchFallbackLookup.Count > 10)
                        _matchFallbackLookup.Remove(_matchFallbackLookup.Keys.Skip(new Random().Next(0, _matchFallbackLookup.Count)).First());
                    _matchFallbackLookup[filter] = new Tuple<bool, bool>(includes, excludes);
                }
            }

            match = null;

            // We have only include filters, we exclude files by default
            if (includes && !excludes)
            {
                return path.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString());
            }
            // Otherwise we include by default
            else
            {
                return true;
            }

        }
开发者ID:admz,项目名称:duplicati,代码行数:79,代码来源:FilterExpression.cs

示例3: Matches

        /// <summary>
        /// Utility function to match a filter with a default fall-through value
        /// </summary>
        /// <param name="filter">The filter to evaluate</param>
        /// <param name="path">The path to evaluate</param>
        /// <param name="match">The filter that matched</param>
        public static bool Matches(IFilter filter, string path, out IFilter match)
        {
            if (filter == null || filter.Empty)
            {
                match = null;
                return true;
            }

            bool result;
            if (filter.Matches(path, out result, out match))
                return result;

            bool includes;
            bool excludes;

            AnalyzeFilters(filter, out includes, out excludes);
            match = null;

            // We have only include filters, we exclude files by default
            if (includes && !excludes)
            {
                return false;
            }
            // Otherwise we include by default
            else
            {
                return true;
            }
        }
开发者ID:thekrugers,项目名称:duplicati,代码行数:35,代码来源:FilterExpression.cs

示例4: Matches

        /// <summary>
        /// Utility function to match a filter with a default fall-through value
        /// </summary>
        /// <param name="filter">The filter to evaluate</param>
        /// <param name="path">The path to evaluate</param>
        /// <param name="match">The filter that matched</param>
        public static bool Matches(IFilter filter, string path, out IFilter match)
        {
            if (filter == null || filter.Empty)
            {
                match = null;
                return true;
            }

            bool result;
            if (filter.Matches(path, out result, out match))
                return result;

            // If we only exclude files, choose to include by default
            var q = new Queue<IFilter>();
            q.Enqueue(filter);

            // TODO: We should cache this, so we do not compute it every time
            while (q.Count > 0)
            {
                var p = q.Dequeue();
                if (p == null || p.Empty)
                    continue;
                else if (p is FilterExpression && ((FilterExpression)p).Result)
                {
                    match = p;
                    return false; // We have an include filter, so we exclude by default
                }
                else if (p is JoinedFilterExpression)
                {
                    q.Enqueue(((JoinedFilterExpression)p).First);
                    q.Enqueue(((JoinedFilterExpression)p).Second);
                }
            }

            // Only excludes, we return true
            match = null;
            return true;
        }
开发者ID:Berimor66,项目名称:duplicati,代码行数:44,代码来源:FilterExpression.cs


注:本文中的IFilter.Matches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。