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


C# BinaryTree.BuildIndex方法代码示例

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


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

示例1: DoStart

        protected override void DoStart()
        {
            if (m_Resolution!= LookupResolution.Country && m_Resolution!= LookupResolution.City)
              throw new GeoException(StringConsts.GEO_LOOKUP_SVC_RESOLUTION_ERROR.Args(m_Resolution));

            if (!Directory.Exists(m_DataPath))
              throw new GeoException(StringConsts.GEO_LOOKUP_SVC_PATH_ERROR.Args(m_DataPath ?? StringConsts.UNKNOWN));

            var fnBlocks    = Path.Combine(m_DataPath, "GeoLite2-{0}-Blocks-IPv6.csv".Args(m_Resolution));
            var fnBlocksV4 = Path.Combine(m_DataPath, "GeoLite2-{0}-Blocks-IPv4.csv".Args(m_Resolution));
            var fnLocations = Path.Combine(m_DataPath, "GeoLite2-{0}-Locations-en.csv".Args(m_Resolution));

            if (!File.Exists(fnBlocks))
            throw new GeoException(StringConsts.GEO_LOOKUP_SVC_DATA_FILE_ERROR.Args(fnBlocks));
            if (!File.Exists(fnBlocksV4))
            throw new GeoException(StringConsts.GEO_LOOKUP_SVC_DATA_FILE_ERROR.Args(fnBlocksV4));
            if (!File.Exists(fnLocations))
            throw new GeoException(StringConsts.GEO_LOOKUP_SVC_DATA_FILE_ERROR.Args(fnLocations));

            m_CancelStart = false;
            m_Locations = new Dictionary<SealedString, Location>();

            try
            {
            const int MAX_PARSE_ERRORS = 8;

            var tree = new BinaryTree<Subnet, IPSubnetBlock>();
            var scope = new SealedString.Scope();
            foreach (var blocksFn in new[] { fnBlocks, fnBlocksV4 })
            {
              using (var stream = new FileStream(blocksFn, FileMode.Open, FileAccess.Read, FileShare.Read, 4*1024*1024))
              {
                int errors = 0;
                try
                {
                  foreach (var row in stream.AsCharEnumerable().ParseCSV(skipHeader: true, columns: 10))
                  {
                    if (m_CancelStart || !App.Active) break;
                    var arr = row.ToArray();
                    var block = new IPSubnetBlock(
                      scope.Seal(arr[0]),
                      scope.Seal(arr[1]),
                      scope.Seal(arr[2]),
                      scope.Seal(arr[3]),
                      arr[4].AsBool(),
                      arr[5].AsBool(),
                      scope.Seal(arr[6]),
                      arr[7].AsFloat(),
                      arr[8].AsFloat());

                    tree[new Subnet(block.Subnet.Value, true)] = block;
                  }
                }
                catch (Exception error)
                {
                  log(MessageType.Error, "DoStart('{0}')".Args(blocksFn), "Line: {0} {1}".Args(0/*line*/, error.ToMessageWithType()), error);
                  errors++;
                  if (errors > MAX_PARSE_ERRORS)
                  {
                    log(MessageType.CatastrophicError, "DoStart('{0}')".Args(blocksFn), "Errors > {0}. Aborting file '{1}' import".Args(MAX_PARSE_ERRORS, blocksFn));
                    break;
                  }
                }
              }
            }
            m_SubnetBST = new SubnetTree<IPSubnetBlock>(tree.BuildIndex());

            using (var stream = new FileStream(fnLocations, FileMode.Open, FileAccess.Read, FileShare.Read, 4 * 1024 * 1024))
            {
              try
              {
                foreach (var row in stream.AsCharEnumerable().ParseCSV(skipHeader: true, columns: 13))
                {
                  if (m_CancelStart || !App.Active) break;
                  var arr = row.ToArray();
                  var location = new Location(
                    scope.Seal(arr[0]),
                    scope.Seal(arr[1]),
                    scope.Seal(arr[2]),
                    scope.Seal(arr[3]),
                    scope.Seal(arr[4]),
                    scope.Seal(arr[5]),
                    scope.Seal(arr[6]),
                    scope.Seal(arr[7]),
                    scope.Seal(arr[8]),
                    scope.Seal(arr[9]),
                    scope.Seal(arr[10]),
                    scope.Seal(arr[11]),
                    scope.Seal(arr[12]));
                  m_Locations.Add(location.ID, location);
                }
              }
              catch (CSVParserException error)
              {
                log(MessageType.Error, "DoStart('{0}')".Args(fnLocations), "Line: {0} Column: {1} {2}".Args(error.Line, error.Column, error.ToMessageWithType()), error);
              }
              catch (Exception error)
              {
                log(MessageType.Error, "DoStart('{0}')".Args(fnLocations), "{1}".Args(error.ToMessageWithType()), error);
              }
//.........这里部分代码省略.........
开发者ID:itadapter,项目名称:nfx,代码行数:101,代码来源:GeoLookupService.cs


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