コード例 #1
0
        public void Init()
        {
            humanFactory = new HumanFactory();
            var    requestor = WikiDataRequestor.Create();
            string response  = File.ReadAllText(TestFile);

            wikiDataResponse = requestor.ResultFromString(response);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: RichTeaMan/DeathKeeper
        public static void FillCache()
        {
            var errors       = new ConcurrentBag <Tuple <int, Exception> >();
            var responseBody = File.ReadAllText(WdqResponse);
            var wdqRequestor = new WdqRequestor();

            Console.WriteLine("Getting human instance references.");
            var wdqResult = wdqRequestor.ResultFromString(responseBody);

            Console.WriteLine("Found {0} human instances.", wdqResult.items.Length);

            var wikiDataRequestor = WikiDataRequestor.Create();

            int count = 0;

            var partitions = new List <IEnumerable <int> >();


            Parallel.ForEach(wdqResult.items, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 20
            }, id =>
            {
                try
                {
                    var humanUrl = wikiDataRequestor.GetEntityUrl(id);
                    wikiDataRequestor.WebCache.FillCache(humanUrl);
                    var c = Interlocked.Increment(ref count);
                    if (c % 100 == 0)
                    {
                        Console.Write("\r{0}/{1} completed.", c, wdqResult.items.Count());
                    }
                }
                catch (Exception ex)
                {
                    var t = new Tuple <int, Exception>(id, ex);
                    errors.Add(t);
                }
            });
            Console.WriteLine();
            Console.WriteLine("{0} humans found.", count);
            Console.WriteLine("Cache fill finished.");
        }
コード例 #3
0
 public HumanFactory()
 {
     WikiDataRequestor = WikiDataRequestor.Create();
 }
コード例 #4
0
 public void Init()
 {
     requestor = WikiDataRequestor.Create();
 }