示例#1
0
 public Lottery(Options options, ThreadSafeCounter threadSafeCounter, ConcurrentBag <LotteryTicket> winningLotteryTickets, HashSet <string> bitcoinAddressToBalance)
 {
     _options                 = options;
     _threadSafeCounter       = threadSafeCounter;
     _winningLotteryTickets   = winningLotteryTickets;
     _bitcoinAddressToBalance = bitcoinAddressToBalance;
 }
示例#2
0
        private static void Run(Options options)
        {
            // sanity check
            try
            {
                SanityCheck(options);
            }
            catch (EndpointException e)
            {
                Console.WriteLine("Sanity check failed for endpoint {0}: {1}", options.Endpoint, e.Message);
                return;
            }
            catch (FileException e)
            {
                Console.WriteLine("Sanity check failed for file {0}: {1}", options.File, e.Message);
                return;
            }

            // init btc addresses
            Console.WriteLine("Initializing Bitcoin Lottery with {0} thread(s)...", options.Threads);
            var bitcoinAddressWithBalance = GetBitcoinAddressWithBalance(options.Dump);

            var threadSafeCounter     = new ThreadSafeCounter();
            var winningLotteryTickets = new ConcurrentBag <LotteryTicket>();

            // run lottery
            for (var i = 0; i < options.Threads; i++)
            {
                var lottery = new Lottery(options, threadSafeCounter, winningLotteryTickets, bitcoinAddressWithBalance);
                new Thread(lottery.Run).Start();
            }

            // run watch dog
            var watchDog = new WatchDog(options, threadSafeCounter, winningLotteryTickets);

            new Thread(watchDog.Run).Start();
        }
示例#3
0
 public WatchDog(Options options, ThreadSafeCounter threadSafeCounter, ConcurrentBag <LotteryTicket> winningLotteryTickets)
 {
     _options               = options;
     _threadSafeCounter     = threadSafeCounter;
     _winningLotteryTickets = winningLotteryTickets;
 }