Exemple #1
0
        public static async ETTask <RobotCase> New(this RobotCaseComponent self)
        {
            await ETTask.CompletedTask;
            RobotCase robotCase = self.AddChild <RobotCase>();

            return(robotCase);
        }
Exemple #2
0
        // 创建机器人,生命周期是RobotCase
        public static async ETTask NewRobot(this RobotCase self, int count, List <Scene> scenes)
        {
            ETTask[] tasks = new ETTask[count];
            for (int i = 0; i < count; ++i)
            {
                tasks[i] = self.NewRobot(scenes);
            }

            await ETTaskHelper.WaitAll(tasks);
        }
Exemple #3
0
 // 这个方法创建的是进程所属的机器人,建议使用RobotCase.NewRobot来创建
 private static async ETTask NewZoneRobot(this RobotCase self, int zone, List <Scene> scenes)
 {
     try
     {
         scenes.Add(await self.NewRobot(zone));
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
 }
        public static async ETTask Run(this RobotCaseDispatcherComponent self, int caseType, string line)
        {
            if (!self.Dictionary.TryGetValue(caseType, out IRobotCase iRobotCase))
            {
                return;
            }

            try
            {
                using (RobotCase robotCase = await RobotCaseComponent.Instance.New())
                {
                    robotCase.CommandLine = line;
                    await iRobotCase.Run(robotCase);
                }
            }
            catch (Exception e)
            {
                Log.Error($"{self.DomainZone()} {e}");
                RobotLog.Console($"RobotCase Error {caseType}:\n\t{e}");
            }
        }
Exemple #5
0
        public async ETTask Run(RobotCase robotCase)
        {
            using ListComponent <Scene> robots = ListComponent <Scene> .Create();

            // 创建了两个机器人,生命周期是RobotCase,RobotCase_FirstCase.Run执行结束,机器人就会删除
            await robotCase.NewRobot(2, robots);

            foreach (Scene robotScene in robots)
            {
                M2C_TestRobotCase response = await robotScene.GetComponent <Client.SessionComponent>().Session.Call(new C2M_TestRobotCase()
                {
                    N = robotScene.Zone
                }) as M2C_TestRobotCase;

                if (response.N != robotScene.Zone)
                {
                    // 跟预期不一致就抛异常,外层会catch住在控制台上打印
                    throw new Exception($"robot case: {RobotCaseType.FirstCase} run fail!");
                }
            }
        }
Exemple #6
0
        public static async ETTask <Scene> NewRobot(this RobotCase self, int zone, string name)
        {
            Scene clientScene = null;

            try
            {
                clientScene = await Client.SceneFactory.CreateClientScene(zone, name, self);

                await Client.LoginHelper.Login(clientScene, zone.ToString(), zone.ToString());

                await Client.EnterMapHelper.EnterMapAsync(clientScene);

                Log.Debug($"create robot ok: {zone}");
                return(clientScene);
            }
            catch (Exception e)
            {
                clientScene?.Dispose();
                throw new Exception($"RobotCase create robot fail, zone: {zone}", e);
            }
        }
Exemple #7
0
        private static async ETTask <Scene> NewRobot(this RobotCase self)
        {
            int   zone        = self.GetParent <RobotCaseComponent>().GetN();
            Scene clientScene = null;

            try
            {
                clientScene = await Client.SceneFactory.CreateClientScene(zone, $"Robot_{zone}", self);

                await Client.LoginHelper.Login(clientScene, zone.ToString(), zone.ToString());

                await Client.EnterMapHelper.EnterMapAsync(clientScene);

                Log.Debug($"create robot ok: {zone}");
                return(clientScene);
            }
            catch (Exception e)
            {
                clientScene?.Dispose();
                throw new Exception($"RobotCase create robot fail, zone: {zone}", e);
            }
        }
Exemple #8
0
 public static async ETTask <Scene> NewRobot(this RobotCase self, int zone)
 {
     return(await self.NewRobot(zone, $"Robot_{zone}"));
 }