Esempio n. 1
0
        public MissionRewardViewModel(MissionReward missionReward, IItemStore itemStore)
        {
            this.missionReward = missionReward;

            if (missionReward.CountedItems != null)
            {
                var countedItem = missionReward.CountedItems[0];
                if (countedItem.ItemCount >= 2)
                {
                    ItemCount = countedItem.ItemCount;
                }
                Item       = itemStore.GetItemById(countedItem.ItemType);
                Visibility = Visibility.Visible;
            }
            else if (missionReward.Items != null)
            {
                Item       = itemStore.GetItemById(missionReward.Items[0]);
                ItemCount  = 1;
                Visibility = Visibility.Visible;
            }
            else
            {
                Visibility = Visibility.Collapsed;
            }

            CreditVisibility = (Credits > 0) ? Visibility.Visible : Visibility.Collapsed;
        }
Esempio n. 2
0
    public ObjectPool(Func <T> factory, int size, LoadingMode loadingMode = LoadingMode.Eager,
                      AccessMode accessMode = AccessMode.FIFO)
    {
        if (factory == null)
        {
            throw new ArgumentNullException(factoryMessage);
        }

        if (size <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(size), size, sizeMessage);
        }

        this.factory     = factory;
        this.size        = size;
        this.loadingMode = loadingMode;

        switch (accessMode)
        {
        case AccessMode.FIFO:
            store = new QueueStore(size);
            break;

        case AccessMode.LIFO:
            store = new StackStore(size);
            break;
        }

        if (loadingMode == LoadingMode.Eager)
        {
            PreloadItems();
        }
    }
Esempio n. 3
0
 /// <summary>
 /// Populate the product test data
 /// </summary>
 /// <param name="itemStore">
 /// The <see cref="IItemStore{TItem}"/> instance
 /// </param>
 public static async void Seed(this IItemStore <Item> itemStore)
 {
     foreach (var item in TestData.Items)
     {
         await itemStore.AddAsync(item);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Creates a pool.
        /// </summary>
        ///
        /// <param name="poolSize">
        /// Size of the pool.
        /// </param>
        ///
        /// <param name="factory">
        /// Func used to create PooledObjects.
        /// </param>
        ///
        /// <param name="poolLoadingMode">
        /// Loading mode of the pool.
        /// </param>
        ///
        /// <param name="poolAccessMode">
        /// Access mode of the pool.
        /// </param>
        ///
        /// <param name="initializeFunc">
        /// Func used to initialize pool's intances (if the class implements IPoolableObject).
        /// </param>
        public Pool(int poolSize, Func <Pool <T>, T> factory, PoolLoadingModeEnum poolLoadingMode, PoolAccessModeEnum poolAccessMode, Func <object> initializeFunc = null)
        {
            if (poolSize <= 0)
            {
                throw new ArgumentOutOfRangeException("poolSize", poolSize, "The 'poolSize' value must be greater than zero.");
            }

            if (factory == null)
            {
                throw new ArgumentNullException("_factory");
            }

            _poolSize        = poolSize;
            _poolLoadingMode = poolLoadingMode;

            _factory        = factory;
            _initializeFunc = initializeFunc;

            _sync      = new Semaphore(poolSize, poolSize);
            _itemStore = CreateItemStore(poolAccessMode, poolSize);

            if (poolLoadingMode == PoolLoadingModeEnum.Eager)
            {
                PreloadItems();
            }
        }
Esempio n. 5
0
 public BasketService(IBasketStore basketStore, IItemStore itemStore, IGuidWrapper guidWrapper, IBasketMapper basketMapper)
 {
     _basketStore  = basketStore;
     _itemStore    = itemStore;
     _guidWrapper  = guidWrapper;
     _basketMapper = basketMapper;
 }
Esempio n. 6
0
 public ModuleContext(DateTime time, Location2 location, ITransferManager transferManager, IMarket market, IItemStore itemStore)
 {
     Time = time;
     Location = location;
     TransferManager = transferManager;
     Market = market;
     ItemStore = itemStore;
 }
Esempio n. 7
0
 public AlertViewModel(Alert alert, FiltersEvent filtersEvent, IItemStore itemStore)
 {
     Id            = alert.Id;
     Activation    = Tools.Time.ToDateTime(alert.Activation.Date.NumberLong);
     PreActivation = Activation.AddMinutes(-5);
     Expiry        = Tools.Time.ToDateTime(alert.Expiry.Date.NumberLong);
     MissionInfo   = new MissionViewModel(alert.MissionInfo, filtersEvent, itemStore);
 }
Esempio n. 8
0
        bool ITransferToSyntax.To(IItemStore storage)
        {
            bool canTransferFrom = false;
            bool canTransferTo = false;

            int fromPartitionIndex = -1;
            IItemContainer fromPartition = null;

            IItemContainer toPartition = null;

            if (_from != null)
            {
                fromPartitionIndex = _from.Partitions.IndexOf(x => x.Item.Name == _item.Name);
                if (fromPartitionIndex > -1)
                {
                    fromPartition = _from.Partitions[fromPartitionIndex];
                    canTransferFrom = fromPartition.Used >= _quantity;
                }
            }
            else
            {
                canTransferFrom = true;
            }

            if (canTransferFrom)
            {
                toPartition = storage.Partitions.SingleOrDefault(x => x.Item.Name == _item.Name);

                if (toPartition != null)
                {
                    canTransferTo = toPartition.Used + _quantity <= toPartition.Capacity;
                }
                else
                {
                    int width = (int) Math.Ceiling(_item.UnitSize*_quantity);
                    if (width <= storage.SlotsAvaliable)
                    {
                        toPartition = new ItemStorePartition(_item, width);
                        storage.Partitions.Add(toPartition);
                        canTransferTo = true;
                    }
                }
            }

            if (canTransferFrom && canTransferTo)
            {
                if (fromPartition != null)
                {
                    UpdateFromPartition(fromPartition, fromPartitionIndex);
                }

                toPartition.Used += _quantity;

                return true;
            }

            return false;
        }
Esempio n. 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="itemStore">item storage</param>
        /// <param name="factory">factory to create items</param>
        /// <param name="preloadCount">number of items to preload</param>
        /// <exception cref="ArgumentNullException">if either <c>itemStore</c> or <c>factory</c> is <c>null</c></exception>
        /// <exception cref="ArgumentNullException">if <c>preloadCount</c> is less or equal to zero</exception>
        public EagerManager(IItemStore <T> itemStore, Func <T> factory, int preloadCount)
            : base(itemStore)
        {
            Assert.ArgumentNotNull(factory, "factory");
            Assert.ArgumentInRange(preloadCount > 0, "preloadCount", preloadCount);

            this.factory = factory;
            Preload(preloadCount);
        }
 public AspNetItemManager(
     IItemStore <TItem, TModule> store,
     IItemAccessor <TItem, TModule> accessor,
     IEnumerable <IValidator <TItem, TModule> > validators,
     ILogger <ItemManager <TItem, TModule> > logger,
     ILookupNormalizer <TItem> nameNormalizer,
     IHttpContextAccessor contextAccessor)
     : base(store, accessor, validators, logger, nameNormalizer)
     => _cancel = contextAccessor?.HttpContext?.RequestAborted ?? CancellationToken.None;
 public ItemManager(
     IItemStore <TItem, TModule> store,
     IItemAccessor <TItem, TModule> accessor,
     IEnumerable <IValidator <TItem, TModule> > validators,
     ILogger <ItemManager <TItem, TModule> > logger,
     ILookupNormalizer <TItem> nameNormalizer)
     : base(store, accessor, validators, logger)
 {
     NameNormalizer = nameNormalizer ?? throw new ArgumentNullException(nameof(nameNormalizer));
 }
Esempio n. 12
0
        public ITransferFromOrToSyntax Item(double quantity, ICanStore item)
        {
            if (item.UnitsDiscrete && (quantity - Math.Floor(quantity) > double.Epsilon))
                throw new ArgumentException(string.Format("Item must be transferred in discrete units, as specified by the UnitsDiscrete property. Value was {0}.", quantity), "quantity");
            _quantity = quantity;
            _item = item;

            _from = null;

            return this;
        }
Esempio n. 13
0
 public WrappersManager([NotNull] IWrapperTypesResolver wrapperTypesResolver,
                        [NotNull] IWrappersFactory wrappersFactory,
                        [NotNull] ICorrelationIdStore correlationIdStore,
                        [NotNull] IItemStore itemStore)
 {
     if (wrapperTypesResolver == null) throw new ArgumentNullException(nameof(wrapperTypesResolver));
     if (wrappersFactory == null) throw new ArgumentNullException(nameof(wrappersFactory));
     if (correlationIdStore == null) throw new ArgumentNullException(nameof(correlationIdStore));
     if (itemStore == null) throw new ArgumentNullException(nameof(itemStore));
     _wrapperTypesResolver = wrapperTypesResolver;
     _wrappersFactory = wrappersFactory;
     _correlationIdStore = correlationIdStore;
     _itemStore = itemStore;
 }
Esempio n. 14
0
        /// <summary>
        /// Constructs a new instance of the <see cref="OkapiBm25Scorer"/>.
        /// </summary>
        /// <param name="k1">The "k1" parameter for the scorer.</param>
        /// <param name="b">The "b" parameter for the scorer.</param>
        /// <param name="snapshot">
        /// The <see cref="IItemStore"/> of the index snapshot being queried.
        /// </param>
        internal OkapiBm25Scorer(double k1, double b, IItemStore snapshot)
        {
            if (snapshot is null)
            {
                throw new ArgumentNullException(nameof(snapshot));
            }

            var documentCount = (double)snapshot.Count;

            this.averageTokenCountByField = snapshot.IndexStatistics.TokenCountByField.ToDictionary(k => k.Key, k => k.Value / documentCount);
            this.documentCount            = documentCount;
            this.k1       = k1;
            this.b        = b;
            this.snapshot = snapshot;
        }
        public InvasionRewardViewModel(InvasionReward invasionReward, IItemStore itemStore)
        {
            this.invasionReward = invasionReward;

            if (invasionReward?.CountedItems != null)
            {
                var countedItem = invasionReward.CountedItems[0];
                Item       = itemStore.GetItemById(countedItem.ItemType);
                ItemCount  = invasionReward.CountedItems.Count;
                Visibility = Visibility.Visible;
            }
            else
            {
                Visibility = Visibility.Collapsed;
            }
        }
Esempio n. 16
0
 public InvasionViewModel(Invasion invasion, FiltersEvent filtersEvent, IItemStore itemStore)
 {
     this.invasion = invasion;
     Id            = invasion.Id;
     isDefenderFactionInfestation = invasion.DefenderMissionInfo.Faction == "FC_INFESTATION";
     AttackerFaction = FactionViewModel.ById(invasion.AttackerMissionInfo.Faction);
     DefenderFaction = FactionViewModel.ById(invasion.DefenderMissionInfo.Faction);
     Faction         = FactionViewModel.ById(invasion.Faction);
     Sector          = SectorViewModel.FromSector(invasion.Node);
     LocTag          = Model.Filters.ExpandMission(invasion.LocTag)?.Name ?? invasion.LocTag;
     DefenderReward  = new InvasionRewardViewModel(invasion.DefenderReward, itemStore);
     AttackerReward  = new InvasionRewardViewModel(invasion.AttackerReward, itemStore);
     Update();
     SectorsUpdatedWeakEventManager.AddHandler(filtersEvent, OnSectorsFilterUpdated);
     MissionsUpdatedWeakEventManager.AddHandler(filtersEvent, OnMissionsFilterUpdated);
 }
Esempio n. 17
0
        public ItemDetailsViewModel(ItemViewModel viewModel, IItemStore itemStore, IPageService pageService)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            _pageService = pageService;
            _itemStore   = itemStore;

            SaveCommand = new Command(async() => await Save());

            Item = new Item
            {
                Id    = viewModel.Id,
                Title = viewModel.Title,
                Notes = viewModel.Notes,
            };
        }
Esempio n. 18
0
        /// <summary>
        /// Initializes a new instance of the Pool class.
        /// </summary>
        /// <param name="size">Maximum pool size.</param>
        /// <param name="factory">Factory function(creator) for pooled objects.</param>
        /// <param name="loadingMode">Loading mode.</param>
        /// <param name="accessMode">Acess mode</param>
        public Pool(int size, Func <Pool <T>, T> factory = null, LoadingMode loadingMode = LoadingMode.Lazy, AccessMode accessMode = AccessMode.LIFO)
        {
            Exceptions.ThrowIf <ArgumentOutOfRangeException>(size == 0, "Argument 'size' must be greater than zero.");

            this.size        = size;
            this.factory     = factory;
            this.sync        = new Semaphore(size, size);
            this.LoadingMode = loadingMode;

            // Create pool
            switch (accessMode)
            {
            case AccessMode.FIFO:
            {
                this.itemStore = new QueueStore(size);
                break;
            }

            case AccessMode.LIFO:
            {
                this.itemStore = new StackStore(size);
                break;
            }

            case AccessMode.Circular:
            {
                this.itemStore = new CircularStore(size);
                break;
            }
            }

            // Default factory
            if (this.factory == null)
            {
                this.factory = p => (T)Activator.CreateInstance(typeof(T), true);
            }

            // Preaload
            if (loadingMode == LoadingMode.Eager)
            {
                PreloadItems();
            }
        }
Esempio n. 19
0
 public ContextPool(int size, Func <ContextPool <T>, T> factory, LoadingMode loadingMode, AccessMode accessMode)
 {
     if (size <= 0)
     {
         throw new ArgumentOutOfRangeException("size", size,
                                               "Argument 'size' must be greater than zero.");
     }
     if (factory == null)
     {
         throw new ArgumentNullException("factory");
     }
     this.size        = size;
     this.factory     = factory;
     sync             = new Semaphore(size, size);
     this.loadingMode = loadingMode;
     this.itemStore   = CreateItemStore(accessMode, size);
     if (loadingMode == LoadingMode.Eager)
     {
         PreloadItems();
     }
 }
Esempio n. 20
0
 public APIController(IItemStore itemStore, IMenuStore menuStore, IRestaurantStore restaurantStore)
 {
     _itemStore       = itemStore;
     _menuStore       = menuStore;
     _restaurantStore = restaurantStore;
 }
Esempio n. 21
0
 public void setup()
 {
     _ItemStore = Substitute.For<IItemStore>();
     _controller = new ItemsController(_ItemStore);
 }
Esempio n. 22
0
 public void SetUp()
 {
     itemStoreMock = MockRepository.GenerateMock <IItemStore <ObjectStub> >();
     manager       = new LazyManager <ObjectStub>(itemStoreMock, () => new ObjectStub());
 }
Esempio n. 23
0
 public void SetUp()
 {
     itemStore = new StackStore<object>();
 }
Esempio n. 24
0
 public AlertsEngine(FiltersEvent filtersEvent, IItemStore itemStore) : base(filtersEvent)
 {
     this.itemStore = itemStore;
 }
 public PrimaryReceiptCalculator(IItemStore itemStore, IDiscountProvider discountProvider)
 {
     this.itemStore        = itemStore ?? throw new ArgumentNullException(nameof(itemStore));
     this.discountProvider = discountProvider ?? throw new ArgumentNullException(nameof(discountProvider));
 }
Esempio n. 26
0
 public void SetUp()
 {
     itemStoreMock = MockRepository.GenerateMock<IItemStore<ObjectStub>>();
     manager = new LazyManager<ObjectStub>(itemStoreMock, () => new ObjectStub());
 }
Esempio n. 27
0
 public void SetUp()
 {
     itemStore = new QueueStore<object>();
 }
Esempio n. 28
0
 public void SetUp()
 {
     itemStore = new StackStore <object>();
 }
Esempio n. 29
0
 /// <summary>
 /// Initialise a new <see cref="DefaultAddItemsToOrder"/> instance
 /// </summary>
 /// <param name="itemStore">
 /// The item store dependancy
 /// </param>
 public DefaultAddItemsToOrder(IItemStore <Item> itemStore)
 {
     this.itemStore = itemStore;
 }
Esempio n. 30
0
 /// <summary>
 /// Initialise a new instance of <see cref="DefaultRemoveItemsFromOrder"/>
 /// </summary>
 /// <param name="itemStore">
 /// The <see cref="IItemStore{TItem}"/> dependancy
 /// </param>
 public DefaultRemoveItemsFromOrder(IItemStore <Item> itemStore)
 {
     this.itemStore = itemStore;
 }
Esempio n. 31
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="itemStore">item storage</param>
 /// <exception cref="ArgumentNullException">if either <c>itemStore</c> is <c>null</c></exception>
 protected PoolItemManagerBase(IItemStore <T> itemStore)
 {
     Assert.ArgumentNotNull(itemStore, "itemStore");
     ItemStore = itemStore;
 }
Esempio n. 32
0
 public void SetUp()
 {
     itemStore = new CircularStore<object>();
 }
Esempio n. 33
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="itemStore">item storage</param>
 /// <param name="factory">factory to create items</param>
 /// <exception cref="ArgumentNullException">if either <c>itemStore</c> or <c>factory</c> is <c>null</c></exception>
 public LazyManager(IItemStore <T> itemStore, Func <T> factory)
     : base(itemStore)
 {
     Assert.ArgumentNotNull(factory, "factory");
     this.factory = factory;
 }
 public ShoppingBasketService(IShoppingBasketStore shoppingBasketStore, IItemStore itemStore)
 {
     _shoppingBasketStore = shoppingBasketStore;
     _itemStore           = itemStore;
 }
Esempio n. 35
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     ConfigId    = new ConfigStore();
     FranchiseId = new FranchiseStoreInCookies();
     base.OnActionExecuting(filterContext);
 }
Esempio n. 36
0
 public ItemsController(IItemStore itemStore)
 {
     _itemStore = itemStore;
 }
Esempio n. 37
0
 public ItemsController(IItemStore store)
 {
     _store = store;
     _jss = new JavaScriptSerializer();
 }
Esempio n. 38
0
 public void SetUp()
 {
     itemStore = new QueueStore <object>();
 }
Esempio n. 39
0
 public void SetUp()
 {
     itemStore = new CircularStore <object>();
 }
Esempio n. 40
0
 /// <summary>
 /// Initialise a new <see cref="ItemController"/> instance
 /// </summary>
 /// <param name="itemStore">
 /// The item store dependancy
 /// </param>
 public ItemController(IItemStore <Item> itemStore)
 {
     this.itemStore = itemStore;
 }
Esempio n. 41
0
 protected override void setup()
 {
     base.setup();
     _ItemStore = new ItemStore(TestDbContext);
     SetupData();
     ThenItem = null;
 }
Esempio n. 42
0
 ITransferToSyntax ITransferFromSyntax.From(IItemStore storage)
 {
     _from = storage;
     return this;
 }