コード例 #1
0
        public void MatchTemplate_WithMatching2TempateSegment_ShouldReturn2KeyValuePairs()
        {
            var routeMatch = RouteUtil.MatchTemplate("math/addition/2/3", "math/addition/{num1}/{num2}");

            routeMatch["num1"].Should().Be("2");
            routeMatch["num2"].Should().Be("3");
        }
コード例 #2
0
        public void ReInitWithiRealAgv()
        {
            bool res   = false;
            int  count = 1;

            while (res == false && count < REINIT_COUNT)
            {
                Thread.Sleep(count * 50);
                for (int i = 0; i < vehicles.Length; i++)
                {
                    if (vehicles[i].agvInfo != null)
                    {
                        vehicles[i].BeginX = (int)Math.Round(vehicles[i].agvInfo.CurLocation.CurNode.X / 1000.0);
                        vehicles[i].BeginY = (int)Math.Round(vehicles[i].agvInfo.CurLocation.CurNode.Y / 1000.0);
                        res = true;
                        Console.WriteLine("小车编号" + i + "初始化完成,起点(" + vehicles[i].BeginX + "," + vehicles[i].BeginY + ")");
                    }
                }
                count++;
            }
            ////把小车所在的节点设为占用状态
            RouteUtil.VehicleOcuppyNode(ElecMap.Instance, vehicles);
            if (count >= REINIT_COUNT)
            {
                MessageBox.Show("没有小车连接,请检查ip设置是否有问题");
            }
        }
コード例 #3
0
        /// <summary>
        /// 初始化小车
        /// </summary>
        public void InitialVehicle()
        {
            vehicleInited = false;
            //初始化小车位置

            if (null == FileUtil.sendData || FileUtil.sendData.Length < 1)
            {
                throw new ArgumentNullException();
            }
            int vehicleCount = FileUtil.sendData.Length;

            vehicles = new Vehicle[vehicleCount];
            for (int i = 0; i < vehicleCount; i++)
            {
                VehicleConfiguration config = new VehicleConfiguration();
                vehicles[i] = new Vehicle(FileUtil.sendData[i].BeginX, FileUtil.sendData[i].BeginY, i, false, Direction.Right, config);
                //MyPoint endPoint = RouteUtil.RandPoint(ElecMap.Instance);
                //MyPoint mp = SqlManager.Instance.GetVehicleCurLocationWithId(i);
                //if (mp != null)
                //{
                //    vehicles[i].BeginX = mp.X;
                //    vehicles[i].BeginY = mp.Y;
                //}
                int R = rand.Next(20, 225);
                int G = rand.Next(20, 225);
                int B = rand.Next(20, 225);
                vehicles[i].pathColor = Color.FromArgb(80, R, G, B);
                vehicles[i].showColor = Color.FromArgb(255, R, G, B);
            }

            vehicleInited = true;
            ////把小车所在的节点设为占用状态
            RouteUtil.VehicleOcuppyNode(ElecMap.Instance, vehicles);
        }
コード例 #4
0
 public void SetItemsDataToListItems(ItemData[] newListItems)
 {
     for (int index = 0; index < newListItems.Length; index++)
     {
         if (newListItems[index] != null)
         {
             Item newItem = (Item)Resources.Load(RouteUtil.GetPrefabsItems() + StringUtil.RemoveWhitespace(newListItems[index].name), typeof(Item));;
             listItems.Add(newItem);
         }
     }
 }
コード例 #5
0
        protected override async Task <HttpResponseMessage> ExecuteInternal(HttpRequestMessage req)
        {
            // get and validate collection name
            string collectionName = GetRouteValue(req, "collectionName");

            if (string.IsNullOrWhiteSpace(collectionName))
            {
                throw new ResourceNotFoundException();
            }

            this.Logger.Info($"Executing api for collection {collectionName}");
            // retrieve collection
            var collectionModel = await this.MockApiRepo.GetCollectionAsync(collectionName);

            // find matching api definition, throw 404 if no match is found. Skip the collectionName in the route to match the template
            var absolutePath = req.RequestUri.AbsolutePath.Substring(req.RequestUri.AbsolutePath.ToLower().IndexOf(collectionName.ToLower()) + collectionName.Length);

            this.Logger.Info($"Absolute path:{absolutePath}");
            var actualRoutePath = RouteUtil.BuildRoute(RouteUtil.GetSegments(absolutePath));

            this.Logger.Info($"Actual Route Path:{actualRoutePath}");
            IDictionary <string, string> routeTemplateValuesMap = null;
            var apiModel = collectionModel.MockApis.FirstOrDefault(model =>
            {
                routeTemplateValuesMap = RouteUtil.MatchTemplate(actualRoutePath, model.RouteTemplate);
                return(routeTemplateValuesMap != null);
            });

            if (apiModel == null)
            {
                throw new ResourceNotFoundException();
            }

            if (!HttpMethodMatch(req.Method, apiModel.Verb))
            {
                throw new MethodNotAllowedException();
            }

            // update route data for the API
            var routeData = req.GetRouteData();

            foreach (var templateKeyValue in routeTemplateValuesMap)
            {
                routeData.Values.Add(templateKeyValue.Key, templateKeyValue.Value);
            }

            // if a matching api definition is found, then validate the script
            this.languageBindingFactory.CreateLanguageValidator(apiModel.Language).Validate(apiModel.Body);

            // run the script now that all the validation has passed
            var apiLanguageBinding = this.languageBindingFactory.CreateLanguageBinding(apiModel.Language);

            return(apiLanguageBinding.Run(apiModel, req));
        }
コード例 #6
0
    private void CreateEnemies(EnemyData[] enemies)
    {
        foreach (var enemy in enemies)
        {
            if (enemy != null)
            {
                GameObject enemyObject = (GameObject)Resources.Load($"{RouteUtil.GetPrefabsEnemy()}{enemy.name}", typeof(GameObject));
                enemyObject.transform.position = new Vector3(enemy.position[0], enemy.position[1], enemy.position[2]);

                enemyObject.GetComponent <SimpleEnemy>().life = enemy.life;

                Instantiate(enemyObject);
            }
        }
    }
コード例 #7
0
        public void RandomMove(int Id)
        {
            MyPoint mpEnd = new MyPoint(3, 3, Direction.Right);// RouteUtil.RandRealPoint(ElecMap.Instance);

            while (mpEnd.X == vehicles[Id].BeginX && mpEnd.Y == vehicles[Id].BeginY)
            {
                mpEnd = RouteUtil.RandRealPoint(ElecMap.Instance);
            }
            SendData sd = new SendData(Id, vehicles[Id].BeginX, vehicles[Id].BeginY, mpEnd.X, mpEnd.Y);

            sd.Arrive = false;
            sd.EndLoc = "rest";
            sd.State  = State.carried;

            SearchRouteQueue.Instance.Enqueue(new SearchData(sd, false));
        }
コード例 #8
0
    private void CreateMerchant(MerchantData[] merchants)
    {
        foreach (var merchant in merchants)
        {
            if (merchant != null)
            {
                GameObject merchantObject = (GameObject)Resources.Load($"{RouteUtil.GetPrefabsNPC()}Merchant", typeof(GameObject));
                merchantObject.transform.position = new Vector3(merchant.position[0], merchant.position[1], merchant.position[2]);

                merchantObject.GetComponent <Merchant>().SetName(merchant.name);
                merchantObject.GetComponent <Merchant>().SetItemsDataToListItems(merchant.items);
                merchantObject.GetComponent <Animator>().runtimeAnimatorController = (RuntimeAnimatorController)Resources.Load($"{RouteUtil.GetAnimatorsNPC()}/Animator-{merchant.name}", typeof(RuntimeAnimatorController));
                merchantObject.GetComponent <SpriteRenderer>().sprite = (Sprite)Resources.Load($"{RouteUtil.GetPrefabsNPC()}Merchant/{merchant.name}", typeof(Sprite));

                Instantiate(merchantObject);
            }
        }
    }
コード例 #9
0
    private void CreateItems(ItemData[] items)
    {
        foreach (var item in items)
        {
            if (item != null)
            {
                GameObject itemObject = (GameObject)Resources.Load($"{RouteUtil.GetPrefabsItems()}ItemPrefab", typeof(GameObject));
                itemObject.transform.position = new Vector3(item.position[0], item.position[1], item.position[2]);

                Debug.Log(item.name);
                Item newItem = (Item)Resources.Load(RouteUtil.GetPrefabsItems() + StringUtil.RemoveWhitespace(item.name), typeof(Item));
                Debug.Log(newItem.icon);
                itemObject.GetComponent <PickupItem>().SetItem(newItem);
                itemObject.GetComponent <SpriteRenderer>().sprite = newItem.icon;

                Instantiate(itemObject);
            }
        }
    }
コード例 #10
0
    public void Load(InventoryData data)
    {
        for (int index = 0; index < data.items.Length; index++)
        {
            slots[index].amount = data.amounts[index];

            if (slots[index].amount <= 0)
            {
                slots[index].item = null;
            }
            else
            {
                string itemName = StringUtil.RemoveWhitespace(data.items[index]);
                slots[index].item = (Item)Resources.Load(RouteUtil.GetPrefabsItems() + itemName, typeof(Item));
                slots[index].SetIcon();
                slots[index].ShowAmount();
                slots[index].ShowIcon(true);
            }
        }
    }
コード例 #11
0
 public void IsInvalidRouteTemplate_UnbalancedBraces_ShouldReturnTrue()
 {
     RouteUtil.IsInvalidRouteTemplate("math/addition/{nu{m1}/{num2}").Should().BeTrue();
 }
コード例 #12
0
 public void IsInvalidRouteTemplate_InvalidChars_ShouldReturnTrue()
 {
     RouteUtil.IsInvalidRouteTemplate("math/add#ition/{num1}/{num2}").Should().BeTrue();
 }
コード例 #13
0
 public void IsInvalidRouteTemplate_ValidRouteWith2TemplateSegment_ShouldReturnFalse()
 {
     RouteUtil.IsInvalidRouteTemplate("math/addition/{num1}/{num2}").Should().BeFalse();
 }
コード例 #14
0
        public void MatchTemplate_WithNonMatching2TempateSegment_ShouldReturnNull()
        {
            var routeMatch = RouteUtil.MatchTemplate("math/substraction/2/3", "math/addition/{num1}/{num2}");

            routeMatch.Should().BeNull();
        }
コード例 #15
0
 public void GetSegments_For1SegmentsRoute_ShouldReturn1Segment()
 {
     RouteUtil.GetSegments("math").ShouldAllBeEquivalentTo(new string[] { "math" });
 }
コード例 #16
0
 public void GetSegments_For3SegmentsRoute_ShouldReturn3Segments()
 {
     RouteUtil.GetSegments("math/addition/2/3").ShouldAllBeEquivalentTo(new string[] { "math", "addition", "2", "3" });
 }