Esempio n. 1
0
        private void PoolBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool?modified = false;

            using (var context = new Context())
            {
                foreach (var pool in context.Pools)
                {
                    if (!Pools.Any(c => c.Id == pool.Id))
                    {
                        Pools.Add(pool);
                        modified = true;
                    }

                    var currentPool = Pools.FirstOrDefault(c => c.Id == pool.Id);

                    var nanopool = new Nanopool(pool.Type, GetWebProxy());
                    var result   = nanopool.GetListOfWorkers(pool.Wallet);

                    if (result != null && result.Status)
                    {
                        var newWorkers = new List <Worker>();
                        var removed    = 0;

                        if (pool.Workers.Any())
                        {
                            removed = pool.Workers.RemoveAll(x => !result.Data.Exists(y => y.Uid == x.Uid));
                        }

                        foreach (var worker in result.Data)
                        {
                            Worker current = null;

                            if (currentPool.Workers.Any())
                            {
                                current = currentPool.Workers.FirstOrDefault(c => c.Uid == worker.Uid);
                            }

                            if (current == null)
                            {
                                newWorkers.Add(worker);
                            }
                            else
                            {
                                worker.UpdateOther(current);
                            }
                        }

                        if (removed > 0)
                        {
                            modified = true;
                        }

                        if (newWorkers.Any())
                        {
                            currentPool.Workers.AddRange(newWorkers);
                            modified = true;
                        }
                    }
                }
            }

            e.Result = modified;
        }
 public bool PoolExists <T>() => Pools.Any(x => x is IEntropyPool <T>);