public async Task <Basket> GetBasket(string userId, string sessionId)
        {
            var basket = await _cache.GetObjectAsync <Basket>(KeyMaker.GetBasketKey(userId, sessionId));

            if (basket.HasNoValue())
            {
                basket = Basket.MakeNew(userId, sessionId);
            }

            return(basket);
        }
        protected virtual ParameterExpression GetParameter(Type type, string name)
        {
            var key = KeyMaker.GetHashCode(type, name);
            ParameterExpression result = null;

            if (!_params.TryGetValue(key, out result))
            {
                result       = Expression.Parameter(type, name);
                _params[key] = result;
            }
            return(result);
        }
        public async Task <Result> ClearBasket(string userId, string sessionId)
        {
            var basket = await _cache.GetObjectAsync <Basket>(KeyMaker.GetBasketKey(userId, sessionId));

            if (basket.HasValue())
            {
                await _cache.RemoveAsync(KeyMaker.GetBasketKey(userId, sessionId));

                return(Result.Ok());
            }

            return(Result.Failure("basket not found"));
        }
        public async Task <Result> AddToBasket(string userId, string sessionId, BasketItem item)
        {
            var options = new DistributedCacheEntryOptions()
                          .SetAbsoluteExpiration(TimeSpan.FromMinutes(BasketCache.DurationInMinutes));

            var basket = await GetBasket(userId, sessionId);

            basket.AddItem(item);

            await _cache.SaveObjectAsync(KeyMaker.GetBasketKey(userId, sessionId), basket, options);

            return(Result.Ok());
        }
Example #5
0
    // Create rooms
    void CreateRooms()
    {
        /*
         * RoomBuilder roomBuilder = new RoomBuilder(mazeRows, mazeColumns, wall, size);
         * roomBuilder.BuildRooms();
         */

        float width  = mazeRows * size - (2 * roomSize);
        float height = mazeColumns * size - (2 * roomSize);
        PoissonDiscSampler sampler = new PoissonDiscSampler(width, height,
                                                            3 * roomSize);

        foreach (Vector2 sample in sampler.Samples())
        {
            Collider[] hitColliders = Physics.OverlapBox(new Vector3(sample.x + roomSize, 0, sample.y + roomSize),
                                                         new Vector3((roomSize + 4) / 2f, 0, (roomSize + 4) / 2f));

            for (int i = 0; i < hitColliders.Length; i++)
            {
                if (hitColliders[i].gameObject.tag != "Room")
                {
                    Destroy(hitColliders[i].gameObject);
                }
            }

            Instantiate(room, new Vector3(sample.x + roomSize, 0, sample.y + roomSize), Quaternion.identity);
            roomCount++;
        }

        // Generate keys for each room created
        KeyMaker keyMaker = new KeyMaker(mazeRows, mazeColumns, size, key);

        print("Number of Rooms: " + roomCount);
        keyMaker.GenerateKeys(roomCount);

        // Update Text
        goalText.text = "Total Rooms: " + roomCount + @"
Width: " + mazeRows + @"
Length: " + mazeColumns;
    }
        protected void AddHash(object item)
        {
            if (item is TypeInfo type)
            {
                var h = type.Name.GetHashCode();

                var hashType = type.UnderlyingSystemType;
                if (hashType != null && hashType.AssemblyQualifiedName != null)
                {
                    h = KeyMaker.AddHashCode(h, hashType.AssemblyQualifiedName.GetHashCode());
                }

                Hash = KeyMaker.AddHashCode(Hash, h);
            }

            if (item is MemberInfo member)
            {
                var h = member.Name.GetHashCode();

                var hashType = member.DeclaringType;
                if (hashType != null && hashType.AssemblyQualifiedName != null)
                {
                    h = KeyMaker.AddHashCode(h, hashType.AssemblyQualifiedName.GetHashCode());
                }
                Hash = KeyMaker.AddHashCode(Hash, h);
                return;
            }

            if (item == null)
            {
                Hash = KeyMaker.AddHashCode(Hash, NullHashCode);
            }
            else
            {
                Hash = KeyMaker.AddHashCode(Hash, KeyMaker.GetHashCode(item));
            }
        }
 public DefinitionCollectionBase(KeyMaker keyMaker, Predicate <TValue> guardian)
 {
     ArgumentUtility.CheckNotNull("keyMaker", keyMaker);
     _keyMaker = keyMaker;
     _guardian = guardian;
 }
Example #8
0
 public MultiDefinitionCollection(KeyMaker keyMaker)
     : base(keyMaker, null)
 {
 }
Example #9
0
 public UniqueDefinitionCollection(KeyMaker keyMaker) : base(keyMaker, null)
 {
 }
Example #10
0
 public UniqueDefinitionCollection(KeyMaker keyMaker, Predicate <TValue> guardian) : base(keyMaker, guardian)
 {
 }