Пример #1
0
        private static void Execute()
        {
            using (var dataStore = new Datastore(_connectionString))
            {
                int addressesAnalyzed = 0;
                _originalAddressCount = dataStore.GetUnanalyzedAddressCount();
                _originalAnalyzedCount = dataStore.GetAnalyzedAddressCount();
                _addressCache = dataStore.GetAllSeenAddresses().ToList();                
                bool stopping = false;

                Console.CancelKeyPress += (o, c) =>
                {
                    c.Cancel = true;
                    Log.Warn("Cancel key pressed! Stopping loop...");
                    stopping = true;
                };


                using (var webClient = new LongerTimeoutWebClient())
                {

                    AddressToAnalyze addressToAnalyze;
                    while (dataStore.GetNextAddressToAnalyze(out addressToAnalyze))
                    {
                        Log.Info("Analyzing address {0}...", addressToAnalyze.Hash);
                       
                        addressesAnalyzed++;
                        var addressData = GetAddressData(dataStore, webClient, addressToAnalyze);       
              
                        if (addressData != null)
                        {
                            try
                            {
                                var sw = new Stopwatch();
                                sw.Start();
                                int newTransaction = dataStore.AddAddressData(addressData);
                                sw.Stop();
                                ConsoleOnly.Debug("Added address data in {0}ms", sw.ElapsedMilliseconds);

                                Log.Info("Found {0} NEW Bitpay transactions out of {1} total.", newTransaction,
                                    addressData.Transactions.Count);
                                AddNewAddresses(dataStore, addressData);
                                dataStore.MarkAsAnalyzed(addressToAnalyze.Hash);
                            }
                            catch (SqlException e)
                            {
                                Log.Warn(string.Format("Address {0} FAILED to persist", addressData.AddressHash), e);
                                dataStore.MarkAsAnalyzed(addressToAnalyze.Hash);
                            }
                        }
                        
                        if (stopping)
                        {
                            Log.Debug("Stop requested, breaking from loop.");
                            LogEndData(dataStore, addressesAnalyzed);
                            break;
                        }
                    }
                }
                LogEndData(dataStore, addressesAnalyzed);
            }
        }
Пример #2
0
 private static void LogEndData(Datastore dataStore, int addressesAnalyzed)
 {
     Log.Info("Analyzed {0} addresses this run.", addressesAnalyzed);
     Log.Info("Found {0} new addresses to be added to the analysis queue.", dataStore.GetUnanalyzedAddressCount() - _originalAnalyzedCount + addressesAnalyzed);            
 }