Ejemplo n.º 1
0
        public AlgorithmManager(IPoolManager poolManager, IObjectFactory objectFactory)
        {
            _storage = new List<IHashAlgorithmStatistics>();

            // add algorithms
            foreach (var pool in poolManager.GetAll())
            {
                var query = _storage.FirstOrDefault(x => x.Name == pool.Config.Coin.Algorithm);

                if (query != null)
                    continue;

                var statistics = objectFactory.GetHashAlgorithmStatistics(pool.Config.Coin.Algorithm);

                _storage.Add(statistics);
            }

            // assign pools to hash algorithms
            foreach (var item in _storage)
            {
                var algorithm = item;
                var pools = poolManager.GetAll().Where(p => p.Config.Coin.Algorithm == algorithm.Name);
                algorithm.AssignPools(pools);
            }
        }
Ejemplo n.º 2
0
 public NancyBootstrapper(IApplicationContext applicationContext, IStatisticsManager statisticsManager, IPoolManager poolManager, IConfigManager configManager)
 {
     _applicationContext = applicationContext;
     _statisticsManager = statisticsManager;
     _poolManager = poolManager;
     _configManager = configManager;
 }
Ejemplo n.º 3
0
 public PoolsModule(IPoolManager poolManager)
     : base("/pools")
 {
     Get["/"] = _ => View["pools", new PoolsModel
     {
         Pools = poolManager.GetAllAsReadOnly()
     }];
 }
Ejemplo n.º 4
0
 public IndexModule(IPoolManager poolManager, IStatistics statistics)
 {
     Get["/"] = _ => View["index", new IndexModel
     {
         Pools = poolManager.Pools,
         Statistics = statistics,
     }];
 }
Ejemplo n.º 5
0
        public ApiModule(IStatisticsManager statisticsManager, IPoolManager poolManager, IAlgorithmManager algorithmManager)
            : base("/api")
        {
            Get["/"] = _ =>
            {
                // include common data required by layout.
                ViewBag.Header = "Public API";

                // return our view
                return View["api", new ApiModel
                {
                    BaseUrl = Request.Url.SiteBase,
                    Coin = poolManager.First().Config.Coin
                }];
            };

            Get["/pools"] = _ =>
            {
                var response = (Response) poolManager.ServiceResponse;
                response.ContentType = "application/json";
                return response;
            };

            Get["/pool/{slug}"] = _ =>
            {
                var pool = poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // query the requested pool.

                var response = pool != null ? (Response)pool.ServiceResponse : PoolNotFound;
                response.ContentType = "application/json";
                return response;
            };

            Get["/algorithms"] = _ =>
            {
                var response = (Response)algorithmManager.ServiceResponse;
                response.ContentType = "application/json";
                return response;
            };

            Get["/algorithm/{slug}"] = _ =>
            {
                var algorithm = algorithmManager.Get(HttpUtility.HtmlEncode(_.slug)); // query the requested pool.

                var response = algorithm != null ? (Response)algorithm.ServiceResponse : AlgorithmNotFound;
                response.ContentType = "application/json";
                return response;
            };

            Get["/global"] = _ =>
            {
                var response = (Response) statisticsManager.ServiceResponse;
                response.ContentType = "application/json";
                return response;
            };
        }
Ejemplo n.º 6
0
        public StatisticsManager(IConfigManager configManager, IPoolManager poolManager, IAlgorithmManager algorithmManager)
        {
            Pools = poolManager;
            Algorithms = algorithmManager;

            _config = configManager.StatisticsConfig;
            _logger = Log.ForContext<StatisticsManager>();

            _recacheTimer = new Timer(Recache, null, Timeout.Infinite, Timeout.Infinite); // create the timer as disabled.
            Recache(null); // recache data initially.
        }
Ejemplo n.º 7
0
        public Pools(IPoolManager poolManager)
        {
            _poolManager = poolManager;
            _pools = new Dictionary<string, IPerPool>();
            _response = new Dictionary<string, ExpandoObject>();

            foreach (var pool in poolManager.Pools)
            {
                _pools.Add(pool.Config.Coin.Name, pool.Statistics);
            }
        }
Ejemplo n.º 8
0
        public DaemonManager(IPoolManager poolManager, IConfigManager configManager, IObjectFactory objectFactory)
        {
            // TODO: let all daemon's initialzied by daemon-manager.

            _logger = Log.ForContext<DaemonManager>();
            
            _poolManager = poolManager;
            _configManager = configManager;
            _objectFactory = objectFactory;

            _storage = new Dictionary<string, IDaemonClient>(); // initialize the daemon storage.

            ReadPoolDaemons(); // read pool daemons.
        }
Ejemplo n.º 9
0
        public IndexModule(IStatisticsManager statisticsManager, IPoolManager poolManager, IAlgorithmManager algorithmManager)
        {
            Get["/"] = _ =>
            {
                // include common data required by layout.
                ViewBag.Header = "Welcome";

                // return our view
                return View["index", new IndexModel
                {
                    Pools = poolManager.GetAllAsReadOnly(),
                    Algorithms = algorithmManager.GetAllAsReadOnly(),
                    Statistics = statisticsManager
                }];
            };
        }
Ejemplo n.º 10
0
        public HelpModule(IPoolManager poolManager, IConfigManager configManager, ISoftwareRepository softwareRepository)
            : base("/help")
        {
            Get["/faq"] = _ =>
            {
                ViewBag.Header = "Frequently Asked Questions";

                return View["faq"];
            };

            Get["/gettingstarted/"] = _ =>
            {
                var model = new GettingStartedModel
                {
                    Stack = configManager.StackConfig,
                    Pools = poolManager.GetAllAsReadOnly()
                };

                return View["gettingstarted/index", model];
            };

            Get["/gettingstarted/pool/{slug}"] = _ =>
            {
                var pool = poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                var model = new GettingStartedPoolModel
                {
                    Stack = configManager.StackConfig,
                    Pool = pool
                };

                return View["gettingstarted/pool", model];
            };

            Get["/miningsoftware/"] = _ =>
            {
                return View["miningsoftware", softwareRepository];
            };
        }
Ejemplo n.º 11
0
        public PoolModule(IPoolManager poolManager)
        {
            Get["/pool/{slug}/"] = _ =>
            {
                var pool = poolManager.GetBySymbol(_.slug);

                if (pool != null)
                    return View["pool", pool];

                var error = new Error
                {
                    Summary = "Pool not found",
                    Details = string.Format("The request pool does not exist: {0}", _.slug)
                };

                return View["error", error];
            };
        }
Ejemplo n.º 12
0
        public AlgorithmManager(IPoolManager poolManager)
        {
            _storage = new List<IHashAlgorithm>();

            // add algorithms
            foreach (var pool in poolManager.GetAll())
            {
                if (_storage.Contains(pool.HashAlgorithm))
                    continue;
                
                _storage.Add(pool.HashAlgorithm);
            }

            // assign pools to hash algorithms
            foreach (var item in _storage)
            {
                var algorithm = item;
                var pools = poolManager.GetAll().Where(p => p.Config.Coin.Algorithm == algorithm.GetType().Name.ToLower());
                algorithm.AssignPools(pools);
            }
        }
Ejemplo n.º 13
0
        public HealthMonitor(IEventProvider eventProvider, IEventValidator eventValidator, IPoolManager poolManager)
        {
            if (eventProvider == null)
            {
                throw new ArgumentNullException("eventProvider");
            }

            if (eventValidator == null)
            {
                throw new ArgumentNullException("eventValidator");
            }

            if (poolManager == null)
            {
                throw new ArgumentNullException("poolManager");
            }

            this.eventProvider = eventProvider;
            this.eventProvider.OnEntryWritten += this.OnEntryWritten;
            this.eventValidator = eventValidator;
            this.poolManager = poolManager;
        }
Ejemplo n.º 14
0
 public Algorithms(IPoolManager poolManager)
 {
     _poolManager = poolManager;
     _algorithms = new Dictionary<string, IPerAlgorithm>();
     _response = new Dictionary<string, object>();
 }
Ejemplo n.º 15
0
 public ReactToGroupSystemHandler(IPoolManager poolManager)
 {
     PoolManager = poolManager;
 }
Ejemplo n.º 16
0
 protected ViewResolverSystem(IPoolManager poolManager)
 {
     PoolManager = poolManager;
 }
Ejemplo n.º 17
0
 public DefaultViewResolver(IPoolManager poolManager, IEventSystem eventSystem, IInstantiator instantiator) : base(poolManager, eventSystem, instantiator)
 {
 }
Ejemplo n.º 18
0
        public virtual void Initialize(IEventSystem eventSystem, IPoolManager poolManager)
        {
            EventSystem = eventSystem;
            EntityPool  = poolManager.GetPool();

            cachedEntities.ObserveAdd().Select(x => x.Value).Subscribe(entity =>
            {
                if (Predicates.Count == 0)
                {
                    PreAdd(entity);
                    AddEntity(entity);
                    return;
                }

                var bools = new List <ReactiveProperty <bool> >();
                foreach (var predicate in Predicates)
                {
                    bools.Add(predicate.Invoke(entity));
                }
                var onLatest = Observable.CombineLatest(bools.ToArray());
                onLatest.DistinctUntilChanged().Subscribe(values =>
                {
                    if (values.All(value => value == true))
                    {
                        PreAdd(entity);
                        AddEntity(entity);
                    }
                    else
                    {
                        PreRemove(entity);
                        RemoveEntity(entity);
                    }
                }).AddTo(this.Disposer);;
            }).AddTo(this.Disposer);

            cachedEntities.ObserveRemove().Select(x => x.Value).Subscribe(entity =>
            {
                PreRemove(entity);
                RemoveEntity(entity);
            }).AddTo(this.Disposer);

            foreach (IEntity entity in EntityPool.Entities)
            {
                if (entity.HasComponents(Components.ToArray()))
                {
                    cachedEntities.Add(entity);
                }
            }

            EventSystem.OnEvent <EntityAddedEvent> ().Where(_ => _.Entity.HasComponents(Components.ToArray()) && cachedEntities.Contains(_.Entity) == false).Subscribe(_ =>
                                                                                                                                                                       { cachedEntities.Add(_.Entity); }).AddTo(this);

            EventSystem.OnEvent <EntityRemovedEvent> ().Where(_ => cachedEntities.Contains(_.Entity)).Subscribe(_ =>
                                                                                                                { cachedEntities.Remove(_.Entity); }).AddTo(this);

            EventSystem.OnEvent <ComponentAddedEvent> ().Where(_ => _.Entity.HasComponents(Components.ToArray()) && cachedEntities.Contains(_.Entity) == false).Subscribe(_ =>
                                                                                                                                                                          { cachedEntities.Add(_.Entity); }).AddTo(this);

            EventSystem.OnEvent <ComponentRemovedEvent> ().Where(_ => Components.Contains(_.Component.GetType()) && cachedEntities.Contains(_.Entity)).Subscribe(_ =>
                                                                                                                                                                 { cachedEntities.Remove(_.Entity); }).AddTo(this);
        }
Ejemplo n.º 19
0
        public PoolModule(IPoolManager poolManager)
            : base("/pool")
        {
            Get["/{slug}"] = _ =>
            {
                var pool = poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                ViewBag.Title = string.Format("{0} Pool", pool.Config.Coin.Name);
                ViewBag.Heading = string.Format("{0} Pool", pool.Config.Coin.Name);

                // return our view
                return View["pool", new PoolModel
                {
                    Pool = pool
                }];
            };

            Get["/{slug}/workers"] = _ =>
            {
                var pool = poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null) // make sure queried pool exists.
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                ViewBag.Header = string.Format("{0} Workers", pool.Config.Coin.Name);

                // return our view
                return View["workers", new WorkersModel
                {
                    Workers = pool.MinerManager.Miners
                }];
            };

            Get["/{slug}/round"] = _ =>
            {
                var pool = poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null) // make sure queried pool exists.
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                ViewBag.Header = string.Format("{0} Current Round", pool.Config.Coin.Name);

                // return our view
                return View["round", new RoundModel
                {
                    Round = pool.NetworkInfo.Round,
                    Shares = pool.RoundShares
                }];
            };

            Get["/{slug}/blocks/{page?1}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null) // make sure queried pool exists.
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                int page;
                if (!Int32.TryParse(_.page, out page))
                    page = 1;

                var paginationQuery = new PaginationQuery(page);

                var blocks = pool.BlockRepository.GetBlocks(paginationQuery);

                if (blocks.Count == 0)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = "No more blocks exist"
                    }];
                }

                var model = new BlocksModel
                {
                    Blocks = blocks,
                    Coin = pool.Config.Coin,
                    Filter = BlockFilter.All,
                    PaginationQuery = paginationQuery
                };

                return View["blocks", model];
            };

            Get["/{slug}/blocks/paid/{page?1}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null) // make sure queried pool exists.
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                int page;
                if (!Int32.TryParse(_.page, out page))
                    page = 1;

                var paginationQuery = new PaginationQuery(page);

                var blocks = pool.BlockRepository.GetPaidBlocks(paginationQuery);

                if (blocks.Count == 0)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = "No more blocks exist"
                    }];
                }

                var model = new BlocksModel
                {
                    Blocks = blocks,
                    Coin = pool.Config.Coin,
                    Filter = BlockFilter.PaidOnly,
                    PaginationQuery = paginationQuery
                };

                return View["blocks", model];
            };

            Get["/{slug}/block/{height:int}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null) // make sure queried pool exists.
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                var block = pool.BlockRepository.Get((uint)_.height);

                if (block == null)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested block does not exist: {0}", _.height)
                    }];
                }

                var model = new BlockModel
                {
                    Block = block,
                    Coin = pool.Config.Coin,
                    Payments = pool.PaymentRepository.GetPaymentDetailsForBlock((uint)_.height)
                };

                ViewBag.Header = string.Format("Block {0}", block.Height);
                ViewBag.SubHeader = string.Format("{0} block", pool.Config.Coin.Name);

                return View["block", model];
            };

            Get["/{slug}/tx/{id:int}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null) // make sure queried pool exists.
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                var details = pool.PaymentRepository.GetPaymentDetailsByTransactionId((uint)_.id);

                if (details == null)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested transaction does not exist.")
                    }];
                }

                var account = pool.AccountManager.GetAccountById(details.AccountId);
                var block = pool.BlockRepository.Get((uint) details.Block);

                ViewBag.Header = string.Format("Transaction Details");
                ViewBag.SubHeader = string.Format("{0}", details.TransactionId);

                var model = new PaymentDetailsModel
                {
                    Details = details,
                    Account = account,
                    Block = block,
                    Coin = pool.Config.Coin
                };

                return View["paymentdetails", model];
            };

            Get["/{slug}/payment/{id:int}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null) // make sure queried pool exists.
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", _.slug)
                    }];
                }

                var details = pool.PaymentRepository.GeyPaymentDetailsByPaymentId((uint)_.id);

                if (details == null)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested payment does not exist.")
                    }];
                }

                var account = pool.AccountManager.GetAccountById(details.AccountId);
                var block = pool.BlockRepository.Get((uint)details.Block);

                ViewBag.Header = string.Format("Payment Details");
                ViewBag.SubHeader = string.Format("{0}", details.PaymentId);

                var model = new PaymentDetailsModel
                {
                    Details = details,
                    Account = account,
                    Block = block,
                    Coin = pool.Config.Coin
                };

                return View["paymentdetails", model];
            };

            Get["/{slug}/account/address/{address:length(26,34)}/{page?1}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.

                if (pool == null)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested pool does not exist: {0}", HttpUtility.HtmlEncode(_.slug))
                    }];
                }

                var account = (IAccount)pool.AccountManager.GetAccountByAddress(_.address);

                if (account == null)
                {
                    return View["error", new ErrorViewModel
                    {
                        Details = string.Format("The requested account does not exist: {0}", _.address)
                    }];
                }

                int page;
                if (!Int32.TryParse(_.page, out page))
                    page = 1;

                var paginationQuery = new PaginationQuery(page);

                // get the payments for the account.
                var payments = pool.AccountManager.GetPaymentsForAccount(account.Id, paginationQuery);

                ViewBag.Header = string.Format("Account Details");
                ViewBag.SubHeader = account.Username;

                // return our view
                return View["account", new AccountModel
                {
                    Account = account,
                    Coin = pool.Config.Coin,
                    Payments = payments,
                    PaginationQuery = paginationQuery
                }];
            };
        }
Ejemplo n.º 20
0
 public SelfDestructionViewResolver(IPoolManager poolManager, IEventSystem eventSystem, IInstantiator instantiator)
     : base(poolManager, eventSystem, instantiator)
 {
     ViewPool.PreAllocate(20);
 }
Ejemplo n.º 21
0
 public static void RemoveEntities(this IPoolManager poolManager, params IEntity[] entities)
 {
     entities.ForEachRun(x => RemoveEntity(poolManager, x));
 }
Ejemplo n.º 22
0
 public static void RemoveEntities(this IPoolManager poolManager, IEnumerable <IEntity> entities)
 {
     entities.ForEachRun(x => RemoveEntity(poolManager, x));
 }
Ejemplo n.º 23
0
        public static void RemoveEntity(this IPoolManager poolManager, IEntity entity)
        {
            var containingPool = poolManager.GetContainingPoolFor(entity);

            containingPool.RemoveEntity(entity);
        }
Ejemplo n.º 24
0
        public static void RemoveEntities(this IPoolManager poolManager, Func <IEntity, bool> predicate)
        {
            var matchingEntities = poolManager.Pools.SelectMany(x => x.Entities).Where(predicate).ToArray();

            RemoveEntities(poolManager, matchingEntities);
        }
Ejemplo n.º 25
0
 public static IPool GetContainingPoolFor(this IPoolManager poolManager, IEntity entity)
 {
     return(poolManager.Pools.SingleOrDefault(x => x.ContainsEntity(entity)));
 }
Ejemplo n.º 26
0
 public EntityReactionSystemHandler(IPoolManager poolManager)
 {
     PoolManager = poolManager;
 }
Ejemplo n.º 27
0
 public virtual void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
 {
     EventSystem  = eventSystem;
     PoolManager  = poolManager;
     GroupFactory = groupFactory;
 }
Ejemplo n.º 28
0
 protected DefaultPooledViewResolverSystem(IPoolManager poolManager, IEventSystem eventSystem) :
     base(poolManager, eventSystem)
 {
     ViewPool = new ViewPool(PrefabTemplate);
 }
Ejemplo n.º 29
0
 protected DefaultPooledViewResolverSystem(IPoolManager poolManager, IEventSystem eventSystem, IInstantiator instantiator) :
     base(poolManager, eventSystem, instantiator)
 {
     ViewPool = new ViewPool(instantiator, PrefabTemplate);
 }
    public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
    {
        base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);

        ignoreCollisionWithSiblings = this.Create(typeof(ViewComponent), typeof(IgnoreCollisionWithSibling));
    }
Ejemplo n.º 31
0
    public void SpawnTheObject()
    {
        Quaternion rot        = transform.rotation;
        Vector3    pos        = transform.position;
        float      halfLength = length / 2.0f; //x-axis
        float      halfWidth  = width / 2.0f;  //z-axis
        float      halfHeight = height / 2.0f; //y-axis

        switch (whereToSpawn)
        {
        case WHERE_TO_SPAWN.TARGET_VECTOR3:
            rot = spawnRotation;
            pos = spawnPosition;
            break;

        case WHERE_TO_SPAWN.TARGET_TRANSFORM:
            rot = targetRotationTransform.rotation;
            pos = targetPositionTransform.position;
            break;

        case WHERE_TO_SPAWN.RANDOM_AREA_IN_BOUNDS:
            if (randomBounds == RANDOM_BOUNDS.SPHERE)
            {
                pos = Random.insideUnitSphere * radius;
            }
            else
            {
                float rndX = Random.Range(-halfLength, halfLength);
                float rndY = Random.Range(-halfHeight, halfHeight);
                float rndZ = Random.Range(-halfWidth, halfWidth);
                pos = new Vector3(rndX, rndY, rndZ);
            }
            break;
        }

        //now we know pos and rot to spawn

        SingletonManager m = SingletonManager.GetInstance();

        if (m != null)
        {
            IPoolManager p = m.GetPoolManager();
            if (p != null)
            {
                ObjectPool pool = p.GetObjectPool(poolName);
                if (pool != null)
                {
                    PooledObject pooled = pool.GetPooledObject(objectName);
                    if (pooled != null)
                    {
                        GameObject objSpawned = pooled.Spawn(pos, rot);
                        if (objSpawned == null)
                        {
                            Debug.LogWarning("The pool \"" + poolName + "\" had no more allocated \"" + objectName + "\" objects able to be spawned.");
                        }
                    }
                    else
                    {
                        Debug.LogError("The SpawnObject tried to spawn the object \"" + objectName + "\" from the pool \"" + poolName + "\" but it didn't exist.");
                    }
                }
                else
                {
                    Debug.LogError("The SpawnObject tried to access the pool \"" + poolName + "\" and it doesn't exist.");
                }
            }
        }
    }
 public WallHitSystem(IEventSystem eventSystem, IPoolManager poolManager) : base(eventSystem)
 {
     _poolManager = poolManager;
 }
Ejemplo n.º 33
0
        public virtual void Initialize(IEventSystem eventSystem, IPoolManager poolManager)
        {
            EventSystem = eventSystem;
            EntityPool  = poolManager.GetPool();

            cachedEntities.ObserveAdd().Select(e => e.Value).Subscribe(entity =>
            {
                if (Predicates.Count == 0)
                {
                    PreAdd(entity);
                    AddEntity(entity);
                    return;
                }

                var bools = new List <ReactiveProperty <bool> >();
                for (int i = 0; i < Predicates.Count; i++)
                {
                    bools.Add(Predicates[i].Invoke(entity));
                }
                var onLatest            = Observable.CombineLatest(bools.ToArray());
                var predicateDisposable = onLatest.DistinctUntilChanged().Subscribe(values =>
                {
                    for (int i = 0; i < values.Count; i++)
                    {
                        if (!values[i])
                        {
                            if (Entities.Contains(entity))
                            {
                                PreRemove(entity);
                                RemoveEntity(entity);
                            }
                            return;
                        }
                    }
                    PreAdd(entity);
                    AddEntity(entity);
                }).AddTo(this.Disposer);
                predicatesTable.Add(entity, predicateDisposable);
            }).AddTo(this.Disposer);

            cachedEntities.ObserveRemove().Select(e => e.Value).Subscribe(entity =>
            {
                if (predicatesTable.ContainsKey(entity))
                {
                    predicatesTable[entity].Dispose();
                    predicatesTable.Remove(entity);
                }
                PreRemove(entity);
                RemoveEntity(entity);
            }).AddTo(this.Disposer);

            foreach (IEntity entity in EntityPool.Entities)
            {
                if (entity.HasComponents(Components))
                {
                    cachedEntities.Add(entity);
                }
            }

            EventSystem.OnEvent <EntityAddedEvent>().Subscribe(evt =>
            {
                if (!cachedEntities.Contains(evt.Entity) && evt.Entity.HasComponents(Components))
                {
                    cachedEntities.Add(evt.Entity);
                }
            }).AddTo(this);

            EventSystem.OnEvent <EntityRemovedEvent>().Subscribe(evt =>
            {
                if (cachedEntities.Contains(evt.Entity))
                {
                    cachedEntities.Remove(evt.Entity);
                }
            }).AddTo(this);

            EventSystem.OnEvent <ComponentsAddedEvent>().Subscribe(evt =>
            {
                if (!cachedEntities.Contains(evt.Entity) && evt.Entity.HasComponents(Components))
                {
                    cachedEntities.Add(evt.Entity);
                }
            }).AddTo(this);

            EventSystem.OnEvent <ComponentsRemovedEvent>().Subscribe(evt =>
            {
                if (cachedEntities.Contains(evt.Entity))
                {
                    foreach (var component in evt.Components)
                    {
                        for (int i = 0; i < Components.Length; i++)
                        {
                            if (Components[i] == component.GetType())
                            {
                                cachedEntities.Remove(evt.Entity);
                                return;
                            }
                        }
                    }
                }
            }).AddTo(this);
        }
Ejemplo n.º 34
0
 public SetupSystemHandler(IPoolManager poolManager)
 {
     PoolManager = poolManager;
 }
Ejemplo n.º 35
0
 public SelfDestructionSystem(IPoolManager poolManager)
 {
     _defaultPool = poolManager.GetPool();
 }
Ejemplo n.º 36
0
 public virtual void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
 {
 }
Ejemplo n.º 37
0
 public EnemyCollisionSystem(IPoolManager poolManager, IEventSystem eventSystem)
 {
     _pool        = poolManager.GetPool("");
     _eventSystem = eventSystem;
 }
    public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
    {
        base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);

        publishEventByListeners = this.Create(typeof(PublishEventByListener), typeof(ViewComponent));
    }
Ejemplo n.º 39
0
 public GroupReactionSystemHandler(IPoolManager poolManager)
 {
     PoolManager = poolManager;
 }
 public ReactToEntitySystemHandler(IPoolManager poolManager)
 {
     PoolManager = poolManager;
 }
Ejemplo n.º 41
0
 public NancyBootstrapper(IApplicationContext applicationContext, IStatisticsManager statisticsManager, IPoolManager poolManager, IConfigManager configManager)
 {
     _applicationContext = applicationContext;
     _statisticsManager  = statisticsManager;
     _poolManager        = poolManager;
     _configManager      = configManager;
 }
Ejemplo n.º 42
0
        public IndexModule(IPoolManager poolManager)
        {
            Get["/"] = _ =>
            {
                var pool = poolManager.Get(slug); // find the requested pool.

                if (pool == null)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                ViewBag.Title   = string.Format("{0} Mining Pool", pool.Config.Coin.Name);
                ViewBag.Heading = string.Format("{0} Mining Pool", pool.Config.Coin.Name);

                // return our view
                return(View["pool", new PoolModel
                            {
                                Pool = pool
                            }]);
            };

            Get["/workers"] = _ =>
            {
                var pool = poolManager.Get(slug); // find the requested pool.

                if (pool == null)                 // make sure queried pool exists.
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                ViewBag.Header = string.Format("{0} Workers", pool.Config.Coin.Name);

                // return our view
                return(View["workers", new WorkersModel
                            {
                                Workers = pool.MinerManager.Miners
                            }]);
            };

            Get["/round"] = _ =>
            {
                var pool = poolManager.Get(slug); // find the requested pool.

                if (pool == null)                 // make sure queried pool exists.
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                ViewBag.Header = string.Format("{0} Current Round", pool.Config.Coin.Name);

                // return our view
                return(View["round", new RoundModel
                            {
                                Round = pool.NetworkInfo.Round,
                                Shares = pool.RoundShares
                            }]);
            };

            Get["/blocks/{page?1}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(slug); // find the requested pool.

                if (pool == null)                        // make sure queried pool exists.
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                int page;
                if (!Int32.TryParse(_.page, out page))
                {
                    page = 1;
                }

                var paginationQuery = new PaginationQuery(page);

                var blocks = pool.BlockRepository.GetBlocks(paginationQuery);

                if (blocks.Count == 0)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = "No more blocks exist"
                                }]);
                }

                var model = new BlocksModel
                {
                    Blocks          = blocks,
                    Coin            = pool.Config.Coin,
                    Filter          = BlockFilter.All,
                    PaginationQuery = paginationQuery
                };

                return(View["blocks", model]);
            };

            Get["/blocks/paid/{page?1}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(slug); // find the requested pool.

                if (pool == null)                        // make sure queried pool exists.
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                int page;
                if (!Int32.TryParse(_.page, out page))
                {
                    page = 1;
                }

                var paginationQuery = new PaginationQuery(page);

                var blocks = pool.BlockRepository.GetPaidBlocks(paginationQuery);

                if (blocks.Count == 0)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = "No more blocks exist"
                                }]);
                }

                var model = new BlocksModel
                {
                    Blocks          = blocks,
                    Coin            = pool.Config.Coin,
                    Filter          = BlockFilter.PaidOnly,
                    PaginationQuery = paginationQuery
                };

                return(View["blocks", model]);
            };

            Get["/block/{height:int}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(slug); // find the requested pool.

                if (pool == null)                        // make sure queried pool exists.
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                var block = pool.BlockRepository.Get((uint)_.height);

                if (block == null)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested block does not exist: {0}", _.height)
                                }]);
                }

                var model = new BlockModel
                {
                    Block    = block,
                    Coin     = pool.Config.Coin,
                    Payments = pool.PaymentRepository.GetPaymentDetailsForBlock((uint)_.height)
                };

                ViewBag.Header    = string.Format("Block {0}", block.Height);
                ViewBag.SubHeader = string.Format("{0} block", pool.Config.Coin.Name);

                return(View["block", model]);
            };

            Get["/tx/{id:int}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(slug); // find the requested pool.

                if (pool == null)                        // make sure queried pool exists.
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                var details = pool.PaymentRepository.GetPaymentDetailsByTransactionId((uint)_.id);

                if (details == null)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested transaction does not exist.")
                                }]);
                }

                var account = pool.AccountManager.GetAccountById(details.AccountId);
                var block   = pool.BlockRepository.Get((uint)details.Block);

                ViewBag.Header    = string.Format("Transaction Details");
                ViewBag.SubHeader = string.Format("{0}", details.TransactionId);

                var model = new PaymentDetailsModel
                {
                    Details = details,
                    Account = account,
                    Block   = block,
                    Coin    = pool.Config.Coin
                };

                return(View["paymentdetails", model]);
            };

            Get["/payment/{id:int}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(slug); // find the requested pool.

                if (pool == null)                        // make sure queried pool exists.
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                var details = pool.PaymentRepository.GeyPaymentDetailsByPaymentId((uint)_.id);

                if (details == null)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested payment does not exist.")
                                }]);
                }

                var account = pool.AccountManager.GetAccountById(details.AccountId);
                var block   = pool.BlockRepository.Get((uint)details.Block);

                ViewBag.Header    = string.Format("Payment Details");
                ViewBag.SubHeader = string.Format("{0}", details.PaymentId);

                var model = new PaymentDetailsModel
                {
                    Details = details,
                    Account = account,
                    Block   = block,
                    Coin    = pool.Config.Coin
                };

                return(View["paymentdetails", model]);
            };

            Get["/account/username/{username}/{page?1}"] = _ =>
            {
                var pool = (IPool)poolManager.Get(slug); // find the requested pool.

                if (pool == null)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested pool does not exist: {0}", slug)
                                }]);
                }

                var account = (IAccount)pool.AccountManager.GetAccountByUsernameOrAddress(_.username);

                if (account == null)
                {
                    return(View["error", new ErrorViewModel
                                {
                                    Details = string.Format("The requested account does not exist: {0}", _.username)
                                }]);
                }

                int page;
                if (!Int32.TryParse(_.page, out page))
                {
                    page = 1;
                }

                var paginationQuery = new PaginationQuery(page);

                // get the payments for the account.
                var payments = pool.AccountManager.GetPaymentsForAccount(account.Id, paginationQuery);

                ViewBag.Header    = string.Format("Account Details");
                ViewBag.SubHeader = account.Username;

                // return our view
                return(View["account", new AccountModel
                            {
                                Account = account,
                                Coin = pool.Config.Coin,
                                Payments = payments,
                                PaginationQuery = paginationQuery
                            }]);
            };
        }
Ejemplo n.º 43
0
 public SphereViewResolver(IPoolManager poolManager) : base(poolManager)
 {
 }
Ejemplo n.º 44
0
 public CoinSystem(IPoolManager poolManager)
 {
     _pool = poolManager.GetPool("");
 }
Ejemplo n.º 45
0
 public ManualSystemHandler(IPoolManager poolManager)
 {
     PoolManager = poolManager;
 }