Beispiel #1
0
        public override async Task OnActivateAsync()
        {
            Identity      = this.GetPrimaryKeyLong();
            _Logger       = ServiceProvider.GetService <ILoggerFactory>().CreateLogger("Node[" + Identity + "]");
            _CacheClient  = ServiceProvider.GetService <IRedisCacheClient>();
            _IMongoClient = ServiceProvider.GetService <IMongoClient>();
            EntityDB      = ServiceProvider.GetService <IEntityDB>();
            IdGenerator   = ServiceProvider.GetService <IIdGeneratorService>();

            EntityManager = new EntityManager();
            TimerManager  = new TimerManager(this);

            NodeType = await EntityDB.GetNodeType(Identity);

            BatchCahceList = new List <NList>();

            RegisterTimer(ScheduledSave, null, TimeSpan.FromSeconds(0), TimeSpan.FromMilliseconds(TimeUtils.MINITE));

            bool persist = await EntityDB.IsPersist(Identity);

            if (persist)
            {
                IReadOnlyList <Entity> entities = await LoadPersistEntities();

                if (NodeType == NodeType.Grain)
                {
                    foreach (Entity entity in entities)
                    {
                        await Load(entity);
                    }
                }
                else if (NodeType == NodeType.Cache)
                {
                    if (!await CacheExist(Nuid.New(Identity, Identity)))
                    {
                        await SetCacheEntities(entities);
                    }
                }
            }

            await base.OnActivateAsync();
        }
Beispiel #2
0
        public override async Task OnActivateAsync()
        {
            await base.OnActivateAsync();

            _SystemListener = new Dictionary <int, Func <NList, Task> >();
            _Logger         = ServiceProvider.GetService <ILoggerFactory>().CreateLogger("RoleAgent[" + Role + "]");

            Role      = this.GetPrimaryKeyLong();
            _RoleNode = GrainFactory.GetGrain <INode>(Role);
            _RoleId   = Nuid.New(Role, Role);

            if (!await EntityDB.IsPersist(Role))
            {
                await EntityDB.SetNodeType(Role, NodeType.Grain);

                await _RoleNode.Create(_RoleId, Player.TYPE, NList.New());
            }

            await _RoleNode.BindAgent(this);

            RegisterSystem(SystemMsg.CLIENT.CUSTOM, OnRecv_Custom);
        }