public async Task ClearShouldClearStore()
        {
            var cache = new ConcurrentCache();

            await cache.Add("001", "01", new DiscoveryResponse(_responses[0]));

            await cache.Add("002", "02", new DiscoveryResponse(_responses[1]));

            await cache.Clear();

            Assert.IsTrue(cache.IsEmpty);
        }
        public async Task CacheShouldNotAddWithEmptyOrNullArguments(string mcc, string mnc)
        {
            var cache = new ConcurrentCache();

            await cache.Add(mcc, mnc, new DiscoveryResponse(_responses[0]));

            Assert.IsTrue(cache.IsEmpty);
        }
        public async Task CacheShouldGetResponseWhenMultipleStored()
        {
            var cache    = new ConcurrentCache();
            var expected = new DiscoveryResponse(_responses[1]);
            var mcc      = "001";
            var mnc      = "01";

            await cache.Add(mcc, mnc, expected);

            await cache.Add("002", "02", new DiscoveryResponse(_responses[0]));

            var actual = await cache.Get(mcc, mnc);

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Cached);
            Assert.IsNotNull(actual.ResponseData.response.apis);
        }
Exemple #4
0
 public FlowField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
 {
     if (_flowFieldCache == null || !_flowFieldCache.TryGetValue(pathRequest, out var flowField))
     {
         var potentialField = _potentialFieldAlgorithm.FindPath(dijkstraNodeNetwork, pathRequest, out succes);
         flowField = new FlowField(potentialField);
         _flowFieldCache?.Add(pathRequest, flowField);
     }
     succes = flowField[pathRequest.PathStart].Length > 0;
     return(flowField);
 }
Exemple #5
0
        public PotentialField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
        {
            if (_potentialFieldCache == null || !_potentialFieldCache.TryGetValue(pathRequest, out var potentialField))
            {
                var pathfindingNetwork = dijkstraNodeNetwork.GetCollisionLayerNetwork(pathRequest.CollisionCategory);

                _dijkstraAlgorithm.StartFindPath(pathfindingNetwork, dijkstraNodeNetwork.DefinitionNodeGrid.NodeArray, pathRequest.PathEnd);
                _dijkstraAlgorithm.FindPath(pathfindingNetwork, dijkstraNodeNetwork.DefinitionNodeGrid.NodeGrid.Array, pathRequest.PathStart, pathRequest.AgentSize, pathRequest.CollisionCategory);
                potentialField = FindPath(dijkstraNodeNetwork, pathfindingNetwork, pathRequest.PathEnd, pathRequest);
                _potentialFieldCache?.Add(pathRequest, potentialField);
            }
            ref var startDefinitionNode = ref dijkstraNodeNetwork.DefinitionNodeGrid.NodeArray[pathRequest.PathStart];
        public async Task RemoveShouldRemoveStoredResponse()
        {
            var cache = new ConcurrentCache();
            var mcc   = "001";
            var mnc   = "01";

            await cache.Add(mcc, mnc, new DiscoveryResponse(_responses[0]));

            await cache.Remove(mcc, mnc);

            var actual = await cache.Get(mcc, mnc);

            Assert.IsNull(actual);
        }
        public async Task AddShouldStoreDiscoveryResponse()
        {
            var cache    = new ConcurrentCache();
            var response = new DiscoveryResponse(_responses[0]);
            var mcc      = "001";
            var mnc      = "01";

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(response, new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });

            await cache.Add(mcc, mnc, response);

            var actual = await cache.Get(mcc, mnc);

            Assert.IsFalse(cache.IsEmpty);
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Cached);
            Assert.AreEqual(response.ResponseData.response, actual.ResponseData.response);
        }
Exemple #8
0
        public PotentialField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
        {
            try
            {
                if (pathRequest.AgentSize % 2 == 0)
                {
                    throw new InvalidAgentSizeException("Potential fields only support uneven agent sizes such as 1,3,5 etc.");
                }

                if (_potentialFieldCache == null || !_potentialFieldCache.TryGetValue(pathRequest, out var potentialField))
                {
                    var sw = Stopwatch.StartNew();
                    var pathfindingNetwork = dijkstraNodeNetwork.GetCollisionLayerNetwork(pathRequest.CollisionCategory);
                    var startNode          = NodePointer.Dereference(pathRequest.PathStart.Index, pathfindingNetwork);
                    var targetNode         = NodePointer.Dereference(pathRequest.PathEnd.Index, pathfindingNetwork);
                    if (_dijkstraAlgorithm.FindPath(pathfindingNetwork, targetNode, startNode, pathRequest))
                    {
                        potentialField = FindPath(dijkstraNodeNetwork, pathfindingNetwork, targetNode, pathRequest);
                    }
                    else
                    {
                        potentialField = new PotentialField(dijkstraNodeNetwork.DefinitionNodeGrid.Transformer, (Point2)targetNode.DefinitionNode.Position);
                    }
                    _potentialFieldCache?.Add(pathRequest, potentialField);
                    Debug.WriteLine($"Potentialfield created in {sw.ElapsedMilliseconds} ms.");
                }
                var nodeWorldPosition = potentialField.GridTransformer.ToWorld(pathRequest.PathStart.Position);
                var offset            = GridClearanceHelper.GridNodeOffset(pathRequest.AgentSize, dijkstraNodeNetwork.DefinitionNodeGrid.Transformer.Scale);
                succes = potentialField.GetHeading(nodeWorldPosition + offset).Length > 0;
                return(potentialField);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Debugger.Break();
                succes = false;
                return(null);
            }
        }
Exemple #9
0
 public FlowField FindPath(DijkstraNodeGrid dijkstraNodeNetwork, IPathRequest pathRequest, out bool succes)
 {
     try
     {
         if (_flowFieldCache == null || !_flowFieldCache.TryGetValue(pathRequest, out var flowField))
         {
             var potentialField = _potentialFieldAlgorithm.FindPath(dijkstraNodeNetwork, pathRequest, out succes);
             var sw             = Stopwatch.StartNew();
             flowField = new FlowField(potentialField);
             Debug.WriteLine($"Flowfield created in {sw.ElapsedMilliseconds} ms.");
             _flowFieldCache?.Add(pathRequest, flowField);
         }
         succes = flowField[pathRequest.PathStart.Index.Index].Length > 0;
         return(flowField);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
         Debugger.Break();
         succes = false;
         return(null);
     }
 }
 public async Task SaveData(string state, CachedParameters cachedParameters)
 {
     await cache.Add(state, cachedParameters);
 }