Ejemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            AkkaSystem.Create();
        }
Ejemplo n.º 2
0
        public virtual object AkkaResolve(Type serviceType, object rsn, bool isAForcedActorSearch = false)
        {
            IActorRef actorReference;

            try
            {
                if (AkkaActors.TryGetValue(serviceType, out actorReference))
                {
                    return(actorReference);
                }
                if (!isAForcedActorSearch)
                {
                    return(base.Resolve(serviceType));
                }
            }
            catch (ActivationException) { throw; }
            catch (/*ActorInitialization*/ Exception) { }

            Props properties;
            Type  typeToTest = serviceType;

            while (typeToTest != null)
            {
                Type[] types = typeToTest.GenericTypeArguments;
                if (types.Length == 1)
                {
                    Type aggregateType = typeof(AkkaAggregateRoot <>).MakeGenericType(typeToTest.GenericTypeArguments.Single());
                    if (typeToTest == aggregateType)
                    {
                        typeToTest = aggregateType;
                        break;
                    }
                }
                typeToTest = typeToTest.BaseType;
            }
            if (typeToTest == null || !(typeToTest).IsAssignableFrom(serviceType))
            {
                properties = Props.Create(() => (ActorBase)RootResolve(serviceType));
            }
            else
            {
                properties = Props.Create(() => (ActorBase)AggregateFactory.CreateAggregate(serviceType, rsn as Guid?, false));
            }
            string actorName = serviceType.FullName.Replace("`", string.Empty);
            int    index     = actorName.IndexOf("[[", StringComparison.Ordinal);

            if (index > -1)
            {
                actorName = actorName.Substring(0, index);
            }
            actorReference = AkkaSystem.ActorOf(properties, string.Format("{0}~{1}", actorName, rsn));
            AkkaActors.Add(serviceType, actorReference);
            return(actorReference);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> battleResult([FromBody] BattResultReq req)
        {
            var res = InitDatabase();

            if (res.Content.code != 0)
            {
                return(res);
            }

            var result = await AkkaSystem.BattleResultActor().Ask <BattleResultResult>(new BattleResultParam()
            {
                battleId = req.battleId,
                roleId   = req.roleId
            });

            return(Json(result.code, result.message));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> battleSetup([FromBody] BattSetupReq req)
        {
            var result = await AkkaSystem.BattleSetupActor().Ask <BattleSetupResult>(new BattleSetupParam()
            {
                questId = req.questId,
                roleId  = req.roleId
            });

            if (result.code != 0)
            {
                return(Json(result.code, result.message));
            }
            else
            {
                return(Json(result));
            }
        }
Ejemplo n.º 5
0
        public virtual object Resolve(Type serviceType, object rsn)
        {
            IActorRef actorReference;

            try
            {
                if (AkkaActors.TryGetValue(serviceType, out actorReference))
                {
                    return(actorReference);
                }

                return(base.Resolve(serviceType));
            }
            catch (ActorInitializationException)
            {
                actorReference = AkkaSystem.ActorOf(AkkaSystem.GetExtension <DIExt>().Props(serviceType), serviceType.FullName);
                AkkaActors.Add(serviceType, actorReference);
                return(actorReference);
            }
        }
Ejemplo n.º 6
0
        private async Task <JsonResult <JsonModel> > Login(user_role role, device device)
        {
            var loginActor = AkkaSystem.LoginActor();

            if (loginActor != null)
            {
                var result = await loginActor.Ask <LoginResult>(new LoginParam()
                {
                    device = device,
                    role   = role,
                    home   = true
                }, TimeSpan.FromMinutes(1));

                if (result == null)
                {
                    return(Json(-1, "登陆失败,内部执行出错"));
                }
                return(Json(result.code, result.message));
            }
            return(Json(-500, "loginActor is null"));
        }
        /// <summary>
        /// Resolves instances of <paramref name="serviceType"/> looking up <see cref="AkkaActors"/>, then <see cref="IDependencyResolver.Resolve{T}"/> and finally <see cref="AggregateFactory"/>.
        /// </summary>
        public virtual object AkkaResolve(Type serviceType, object rsn, bool isAForcedActorSearch = false)
        {
            do
            {
                IActorRef actorReference;
                try
                {
                    if (AkkaActors.TryGetValue(serviceType, out actorReference))
                    {
                        return(actorReference);
                    }
                    if (!isAForcedActorSearch)
                    {
                        return(base.Resolve(serviceType));
                    }
                }
                catch (ActivationException) { throw; }
                catch (/*ActorInitialization*/ Exception) { /* */ }

                Props properties;
                Type  typeToTest = serviceType;
                while (typeToTest != null)
                {
                    Type[] types = typeToTest.GenericTypeArguments;
                    if (types.Length == 1)
                    {
                        Type aggregateType = typeof(AkkaAggregateRoot <>).MakeGenericType(typeToTest.GenericTypeArguments.Single());
                        if (typeToTest == aggregateType)
                        {
                            typeToTest = aggregateType;
                            break;
                        }
                        Type sagaType = typeof(AkkaSaga <>).MakeGenericType(typeToTest.GenericTypeArguments.Single());
                        if (typeToTest == sagaType)
                        {
                            typeToTest = sagaType;
                            break;
                        }
                    }
                    typeToTest = typeToTest.BaseType;
                }

                // This sorts out an out-of-order binder issue
                if (AggregateFactory == null)
                {
                    AggregateFactory = Resolve <IAggregateFactory>();
                }

                if (typeToTest == null || !(typeToTest).IsAssignableFrom(serviceType))
                {
                    properties = Props.Create(() => (ActorBase)RootResolve(serviceType));
                }
                else
                {
                    properties = Props.Create(() => (ActorBase)AggregateFactory.Create(serviceType, rsn as Guid?, false));
                }
                string actorName = serviceType.FullName.Replace("`", string.Empty);
                int    index     = actorName.IndexOf("[[", StringComparison.Ordinal);
                if (index > -1)
                {
                    actorName = actorName.Substring(0, index);
                }
                try
                {
                    actorReference = AkkaSystem.ActorOf(properties, string.Format("{0}~{1}", actorName, rsn));
                }
                catch (InvalidActorNameException)
                {
                    // This means that the actor has been created since we tried to get it... funnily enough concurrency doesn't actually mean concurrency.
                    continue;
                }
                AkkaActors.Add(serviceType, actorReference);
                return(actorReference);
            } while (true);
        }
Ejemplo n.º 8
0
 protected void Application_End()
 {
     AkkaSystem.Shutdown();
 }