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


C# Match.GetExactSignatureIndex方法代码示例

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


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

示例1: Match

        /// <summary>
        /// Entry point to the detection process. Provided with a <see cref="Match"/>
        /// configured with the information about the request.
        /// </summary>
        /// <remarks>
        /// The dataSet may be used by other threads in parallel and is not assumed to be used
        /// by only one detection process at a time.
        /// </remarks>
        /// <param name="match">
        /// The match object to be updated.
        /// </param>
        /// <remarks>
        /// The memory implementation of the data set will always perform fastest but does
        /// consume more memory. 
        /// </remarks>
        internal static void Match(
            Match match)
        {
            if (match.DataSet.Disposed)
                throw new InvalidOperationException(
                    "Data Set has been disposed and can't be used for match");

            // If the user agent is too short then don't try to match and 
            // return defaults.
            if (match.TargetUserAgentArray.Length == 0 ||
                match.TargetUserAgentArray.Length < match.DataSet.MinUserAgentLength)
            {
                // Set the default values.
                MatchDefault(match);
            }
            else
            {
                // Starting at the far right evaluate the nodes in the data
                // set recording matched nodes. Continue until all character
                // positions have been checked.
                Evaluate(match);

                // Can a precise match be found based on the nodes?
                var signatureIndex = match.GetExactSignatureIndex();

                if (signatureIndex >= 0)
                {
                    // Yes a precise match was found.
                    match._signature = match.DataSet.Signatures[signatureIndex];
                    match._method = MatchMethods.Exact;
                    match.LowestScore = 0;
                }
                else
                {
                    // No. So find any other nodes that match if numeric differences
                    // are considered.
                    EvaluateNumeric(match);

                    // Can a precise match be found based on the nodes?
                    signatureIndex = match.GetExactSignatureIndex();

                    if (signatureIndex >= 0)
                    {
                        // Yes a precise match was found.
                        match._signature = match.DataSet.Signatures[signatureIndex];
                        match._method = MatchMethods.Numeric;
                    }
                    else if (match.Nodes.Count > 0)
                    {
                        // Look for the closest signatures to the nodes found.
                        var closestSignatures = match.GetClosestSignatures();

#if DEBUG
                        // Validate the list is in ascending order of ranked signature index.
                        var enumerator = closestSignatures.GetEnumerator();
                        var lastIndex = -1;
                        while (enumerator.MoveNext())
                        {
                            Debug.Assert(lastIndex < enumerator.Current);
                            lastIndex = enumerator.Current;
                        }
#endif

                        // Try finding a signature with identical nodes just not in exactly the 
                        // same place.
                        _nearest.EvaluateSignatures(match, closestSignatures.Select(i =>
                            match.DataSet.Signatures[match.DataSet.RankedSignatureIndexes[i].Value]));

                        if (match._signature != null)
                        {
                            // All the sub strings matched, just in different character positions.
                            match._method = MatchMethods.Nearest;
                        }
                        else
                        {
                            // Find the closest signatures and compare them
                            // to the target looking at the smallest character
                            // difference.
                            _closest.EvaluateSignatures(match, closestSignatures.Select(i =>
                                match.DataSet.Signatures[match.DataSet.RankedSignatureIndexes[i].Value]));
                            match._method = MatchMethods.Closest;
                        }
                    }
                }

//.........这里部分代码省略.........
开发者ID:axle-h,项目名称:.NET-Device-Detection,代码行数:101,代码来源:Controller.cs


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