public void FetchIcons() { // Start at a random place in the set. var start = (new Random()).Next(ItemIconDatabase.ItemsNeedingIcons.Count); var itemsToFetch = new List <Saint.Item>(ItemIconDatabase.ItemsNeedingIcons.Skip(start)); itemsToFetch.AddRange(ItemIconDatabase.ItemsNeedingIcons.Take(start)); foreach (var sItem in itemsToFetch) { // A prior item may share this icon, so always check if it was written. var iconId = (UInt16)sItem.GetRaw("Icon"); if (ItemIconDatabase.HasIcon(iconId)) { continue; } // Scrape search data from Lodestone. var itemUrl = SearchItem(iconId, sItem.Name); string hash = null; if (itemUrl != null) { hash = FetchItem(iconId, sItem.Name, itemUrl); } if (hash == null) { // Can't find this entry. Move on. continue; } // Fetch the icon and write entries. WriteIcon(iconId, hash); } }
public void FetchIcons() { // Start at a random place in the set. var start = (new Random()).Next(ItemIconDatabase.ItemsNeedingIcons.Count); var itemsToFetch = new List <Saint.Item>(ItemIconDatabase.ItemsNeedingIcons.Skip(start)); itemsToFetch.AddRange(ItemIconDatabase.ItemsNeedingIcons.Take(start)); var count = 0; var options = new ParallelOptions() { MaxDegreeOfParallelism = 8 }; Parallel.ForEach(itemsToFetch, options, sItem => { var num = Interlocked.Increment(ref count); // A prior item may share this icon, so always check if it was written. var iconId = (UInt16)sItem.GetRaw("Icon"); if (ItemIconDatabase.HasIcon(iconId)) { return; } var progress = $"{num}/{itemsToFetch.Count}, {100*num/itemsToFetch.Count}%"; // Scrape search data from Lodestone. var itemUrl = SearchItem(iconId, sItem.Name, progress); string hash = null; if (itemUrl != null) { hash = FetchItem(iconId, sItem.Name, itemUrl, progress); } if (hash == null) { // Can't find this entry. Move on. return; } // Fetch the icon and write entries. WriteIcon(iconId, hash); }); }