Пример #1
0
        public async Task BuildShipIndex(int delayMs = 5000, IndexBuildOptions options = IndexBuildOptions.None)
        {
            var time     = new OperationTimer().Start();
            var shipList = await _searcher.GetShipList();

            Log($"Fetched {shipList.Count} ships in {time.Elapsed.ToString()}");
            if (options == IndexBuildOptions.OnlyMissing)
            {
                using (var db = _client)
                {
                    var current = db.GetShips().ToList();
                    shipList = shipList.Where(s => !current.Any(c => c.ShipId == s.Id) && !s.Rarity.Equals("Unreleased")).ToList();
                }
            }
            var ships = new List <Ship>();

            time.Restart();
            foreach (var ship in shipList)
            {
                try
                {
                    var shipDetails = await _searcher.GetShipDetails(ship);

                    if (LogToConsole)
                    {
                        time.WriteToConsole($"Adding {shipDetails.ToString()} to index...");
                    }
                    ships.Add(shipDetails);
                    await System.Threading.Tasks.Task.Delay(delayMs);
                }
                catch (Wiki.Diagnostics.ShipNotFoundException ex)
                {
                    Log(ex.Message);
                    // ignored
                }
                catch (Wiki.Diagnostics.FetchPageException ex)
                {
                    Log($"{ex.Message}: {ex.InnerException.Message} ({ex.InnerException.ToString()})");
                    // ignored
                }
            }
            Log($"Retrieved {ships.Count} ship details in {time.Elapsed.ToString()}");
            using (var db = _client ?? new ShipDbClient())
            {
                if (options == IndexBuildOptions.SideBySide)
                {
                    _client.RebuildSxS(ships.Where(s => s != null));
                }
                else
                {
                    var collection = db.GetShipCollection();
                    collection.Upsert(ships.Where(s => s != null));
                    collection.EnsureIndex(s => s.ShipId);
                    collection.EnsureIndex(s => s.ShipName);
                }
            }
            time.Stop();
        }
Пример #2
0
 static async Task GetShip() {
     var searcher = new WikiSearcher();
     // var result = (await searcher.GetShipDetails("Pensacola")).ToList();
     // var results = (await searcher.GetShipDetails("Salt Lake City")).ToList();
     var results = (await searcher.GetShipDetails("London")).ToList();
 }