Exemplo n.º 1
0
        public static async ETTask <RobotCase> New(this RobotCaseComponent self)
        {
            await ETTask.CompletedTask;
            RobotCase robotCase = Entity.Create <RobotCase>(self);

            return(robotCase);
        }
Exemplo n.º 2
0
        public static async ETTask <RobotCase> New(this RobotCaseComponent self)
        {
            await ETTask.CompletedTask;
            RobotCase robotCase = self.AddChild <RobotCase>();

            return(robotCase);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
     }
 }
Exemplo n.º 5
0
        public static async ETTask <Scene> NewRobot(this RobotCase self, int zone, string name)
        {
            Scene zoneScene = null;

            try
            {
                zoneScene = SceneFactory.CreateZoneScene(zone, name, self);
                await LoginHelper.Login(zoneScene, ConstValue.LoginAddress, zone.ToString(), zone.ToString());

                await EnterMapHelper.EnterMapAsync(zoneScene);

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

            try
            {
                zoneScene = SceneFactory.CreateZoneScene(zone, $"Robot_{zone}", self);
                await LoginHelper.Login(zoneScene, ConstValue.LoginAddress, zone.ToString(), zone.ToString());

                await EnterMapHelper.EnterMapAsync(zoneScene);

                Log.Debug($"create robot ok: {zone}");
                return(zoneScene);
            }
            catch (Exception e)
            {
                zoneScene?.Dispose();
                throw new Exception($"RobotCase create robot fail, zone: {zone}", e);
            }
        }
Exemplo n.º 7
0
        public async ETTask Run(RobotCase robotCase)
        {
            using ListComponent <Scene> robots = ListComponent <Scene> .Create();

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

            foreach (Scene robotScene in robots.List)
            {
                M2C_TestRobotCase response = await robotScene.GetComponent <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!");
                }
            }
        }
        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}");
            }
        }
Exemplo n.º 9
0
 public static async ETTask <Scene> NewRobot(this RobotCase self, int zone)
 {
     return(await self.NewRobot(zone, $"Robot_{zone}"));
 }