Exemple #1
0
        private static void TestRow(Options options, MapService layerInfo, LevelOfDetail lod, int level, Tile firstTile, Tile lastTile, int row)
        {
            // Exit the method if the row is out of the range of user-specified rows.
            if (
                (options.StartLevel.HasValue && options.StartLevel == level && options.StartRow.HasValue && row < options.StartRow)
                ||
                (options.EndLevel.HasValue && options.EndLevel == level && options.EndRow.HasValue && row > options.EndRow)
                )
            {
                return;
            }
            WebRequest webRequest;
            using (var sw = new StreamWriter(Path.Combine(options.OutputDirectory, string.Format("{0:00}_{1:000000}.csv", level, row)), false, System.Text.Encoding.ASCII))
            {
                sw.WriteLine("\"LOD\",\"Row\",\"Col\",\"xmin\",\"ymin\",\"xmax\",\"ymax\",\"ContentLength\",\"Error\"");
                for (int c = firstTile.Column; c < lastTile.Column; c++)
                {
                    var tileUrl = options.Url.GetTileUrl(level, row, c);

                    webRequest = HttpWebRequest.Create(tileUrl);
                    WebResponse response = null;
                    var envelope = layerInfo.GetTileExtent(level, row, c);
                    Exception theException = null;
                    int? contentLength = default(int?);
                    try
                    {
                        webRequest.Method = "HEAD";
                        response = webRequest.GetResponse();
                        string clStr = response.Headers[HttpResponseHeader.ContentLength];
                        int tempCl;
                        if (!string.IsNullOrWhiteSpace(clStr) && int.TryParse(clStr, out tempCl))
                        {
                            contentLength = tempCl;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceWarning("An exception occured at LOD {0}, row {1}, column {2}{3}{4}", lod.level, row, c, Environment.NewLine, ex);
                        theException = ex;
                    }
                    finally
                    {
                        if (response != null)
                        {
                            response.Close();
                        }
                    }
                    if (theException != null ||
                        (options.WriteErrorsOnly.HasValue && !options.WriteErrorsOnly.Value) ||
                        (options.MinimumValidContentLength.HasValue && (!contentLength.HasValue || contentLength.Value < options.MinimumValidContentLength.Value))
                        )
                    {
                        sw.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8}",
                            level, row, c, envelope.xmin, envelope.ymin, envelope.xmax, envelope.ymax,
                            contentLength.HasValue ? contentLength.Value.ToString() : string.Empty,
                            theException != null ? string.Format("\"{0}\"", theException.Message) : string.Empty);
                        sw.Flush();
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Tests the tiles in a level of detail and writes the results to a text table file.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="layerInfo"></param>
 /// <param name="lod"></param>
 private static void TestLod(Options options, MapService layerInfo, LevelOfDetail lod)
 {
     if ((!options.StartLevel.HasValue || lod.level >= options.StartLevel) && (!options.EndLevel.HasValue || lod.level <= options.EndLevel))
     {
         Debug.WriteLine("Begin testing LOD#{0}...", lod.level);
         var level = lod.level;
         var firstTile = layerInfo.GetFirstTile(level);
         var lastTile = layerInfo.GetLastTile(level);
         ParallelLoopResult plResult = Parallel.For(firstTile.Row, lastTile.Row, _parallelOptions, r => TestRow(options, layerInfo, lod, level, firstTile, lastTile, r));
         while (!plResult.IsCompleted)
         {
             // DO nothing.
         }
         Debug.WriteLine("End testing LOD#{0}...", lod.level);
     }
 }