public static long GetRemainingCredits(this DataCache dataCache, string account, long cost, long initialCredits,
            TimeSpan timeout, ICostCalculator costCalculator)
        {
            if (string.IsNullOrWhiteSpace(account))
            {
                throw new ArgumentNullException("account");
            }
            if (cost <= 0)
            {
                throw new ArgumentOutOfRangeException("cost", "Cost cannot be negative");
            }
            if (initialCredits <= 0)
            {
                throw new ArgumentOutOfRangeException("initialCredits", "Initial credit cannot be negative");
            }
            if (timeout.TotalMilliseconds <= 0)
            {
                throw new ArgumentOutOfRangeException("timeout", "Timeout must be a time interval");
            }

            DataCacheItem cacheItem = dataCache.GetCacheItem(account);


            long remainingCredits;

            if (cacheItem == null)
            {
                remainingCredits = costCalculator.CalculateRemainingCredits(initialCredits, cost);

                if (remainingCredits <= 0)
                {
                    return remainingCredits;
                }

                dataCache.Add(account, remainingCredits, timeout);

                return remainingCredits;
            }

            if (!(cacheItem.Value is long))
            {
                throw new InvalidOperationException(string.Format("The cached value with key {0} is not a valid long",
                    account));
            }

            var cachedValue = (long) cacheItem.Value;

            if (cachedValue <= 0)
            {
                return -1;
            }

            remainingCredits = costCalculator.CalculateRemainingCredits(cachedValue, cost);
            
            var newTimeout = cacheItem.Timeout;

            dataCache.Put(account, remainingCredits, cacheItem.Version, newTimeout);

            return remainingCredits;
        }
예제 #2
0
 public DeliveryCostCalculator(decimal costPerDelivery, decimal costPerProduct, decimal fixedCost, ShoppingCart cart, ICostCalculator calculatorStrategy)
 {
     CostPerDelivery    = costPerDelivery;
     CostPerProduct     = costPerProduct;
     CalculatorStrategy = calculatorStrategy;
     Cart      = cart;
     FixedCost = fixedCost;
 }
예제 #3
0
 public RentCostsBuilder()
 {
     _payment = new PaymentDetail();
     _hotWaterCostsCalculator       = new HotWaterCostsCalculator();
     _coldWaterCostsCalculator      = new ColdWaterCostsCalculator();
     _heatingWaterCostsCalculator   = new HeatingCostsCalculator();
     _administrationCostsCalculator = new AdministrationCostsCalculator();
     _garbageCostsCalculator        = new GarbageCostsCalculator();
 }
예제 #4
0
 public WinkelwagenFacade(ICostCalculator calculator,
                          IWinkelwagenRepository repositoryWinkelwagen,
                          IKlantRepository repositoryKlant,
                          IWinkelwagenMapper winkelwagenMapper)
 {
     _calculator            = calculator;
     _repositoryWinkelwagen = repositoryWinkelwagen;
     _repositoryKlant       = repositoryKlant;
     _winkelwagenMapper     = winkelwagenMapper;
 }
예제 #5
0
        public CostCalculatorTests()
        {
            _parcelRepositoryMock = new Mock <IParcelRepository>();
            ConfigureRepositoryMock(CostCalculatorTestData.SmallParcel);
            ConfigureRepositoryMock(CostCalculatorTestData.MediumParcel);
            ConfigureRepositoryMock(CostCalculatorTestData.LargeParcel);
            ConfigureRepositoryMock(CostCalculatorTestData.XLParcel);

            _service = new Services.CostCalculator(_parcelRepositoryMock.Object);
        }
예제 #6
0
        public Line(Bike bike, int quantity, ICostCalculator costCalculator)
        {
            _costCalculator = costCalculator;

            Brand = bike.Brand;
            Model = bike.Model;
            Price = bike.Price;
            Quantity = quantity;
            Cost = _costCalculator.CalculateCost(quantity, Price);
        }
예제 #7
0
 public PlaceOrderCustomer(IEventBus eventBus, ICostCalculator costCalculator,
                           IOrderNumberGenerator orderNumberGenerator, IOrdersRepository ordersRepository, OrdersDbContext dbContext,
                           ICommandBus commandBus)
 {
     _eventBus             = eventBus;
     _costCalculator       = costCalculator;
     _orderNumberGenerator = orderNumberGenerator;
     _ordersRepository     = ordersRepository;
     _dbContext            = dbContext;
     _commandBus           = commandBus;
 }
예제 #8
0
 public BestellingFacade(IBestellingRepository repositoryBestelling,
                         IWinkelwagenRepository repositoryWinkelwagen,
                         IKlantRepository klantRepository,
                         ICostCalculator costCalculator,
                         IBestellingMapper bestellingMapper)
 {
     _repositoryBestelling  = repositoryBestelling;
     _repositoryWinkelwagen = repositoryWinkelwagen;
     _klantRepository       = klantRepository;
     _costCalculator        = costCalculator;
     _bestellingMapper      = bestellingMapper;
 }
예제 #9
0
        private void OnConfirmClicked(object sender, EventArgs e)
        {
            printDialog = new PrintDialog();

            if (printDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                XtraMessageBox.Show("Print has been Canceled By User");
                return;
            }
            if (BLL.Settings.IsCenter)
            {
                GRV = new CenterCostCalculator();
                GRV.LoadGRV(ReceiptID);
                GRV.CalculateFinalCost();
            }
            else
            {
                GRV = new CostCalculator();
                GRV.LoadGRV(ReceiptID);
                (GRV as CostCalculator).LoadGRVPreviousStock();
                GRV.CalculateFinalCost();
            }
            if (!SetSellingPrice(GRV))
            {
                return;
            }

            HCMIS.Desktop.Reports.ReceiptConfirmationPrintout printout = new HCMIS.Desktop.Reports.ReceiptConfirmationPrintout(CurrentContext.LoggedInUserName);
            MyGeneration.dOOdads.TransactionMgr transaction            = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                transaction.BeginTransaction();
                // This is where we set the Price for the previous Stock
                foreach (CostElement costElement in GRV.CostElements)
                {
                    costElement.PreviousCostDetials.Confirm(CurrentContext.UserId);
                }
                printout = PrintConfirmation(null);
                CostingService.ConfirmPriceChange(GRV.CostElements, CurrentContext.UserId, ChangeMode.Recieve, ReceiptID.ToString());
                GRV.SetFinalCostlog(CurrentContext.UserId);
                transaction.CommitTransaction();
            }
            catch (Exception ex)
            {
                transaction.RollbackTransaction();

                XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
            printout.Print(printDialog.PrinterSettings.PrinterName);
        }
예제 #10
0
        private void OnConfirmClicked(object sender, EventArgs e)
        {
            if (BLL.Settings.IsCenter)
            {
                GRV = new CenterCostCalculator();
                GRV.LoadGRV(ReceiptID);
                GRV.CalculateFinalCost();
            }
            else
            {
                GRV = new CostCalculator();
                GRV.LoadGRV(ReceiptID);
                (GRV as CostCalculator).LoadGRVPreviousStock();
                GRV.CalculateFinalCost();
            }
            if (!SetSellingPrice(GRV))
            {
                return;
            }

            TransactionMgr transaction = TransactionMgr.ThreadTransactionMgr();

            try
            {
                transaction.BeginTransaction();
                // This is where we set the Price for the previous Stock
                foreach (CostElement costElement in GRV.CostElements)
                {
                    costElement.PreviousCostDetials.Confirm(CurrentContext.UserId);
                }

                PrintConfirmation(null);
                try
                {
                    CostingService.ConfirmPriceChange(GRV.CostElements, CurrentContext.UserId, ChangeMode.Recieve, ReceiptID.ToString());
                }
                catch (Exception exception)
                {
                    XtraMessageBox.Show(exception.Message);
                    throw exception;
                }
                transaction.CommitTransaction();
                this.LogActivity("Print-SRM", ReceiptID);
            }
            catch (Exception ex)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(ex.Message);
            }
        }
예제 #11
0
 private bool SetSellingPrice(ICostCalculator CostCalculator)
 {
     foreach (CostElement costElement in CostCalculator.CostElements)
     {
         costElement.CheckMovingAverageCost();
         using (SellingPriceValidation pricePerPackPage = new SellingPriceValidation(costElement.PreviousCostDetials))
         {
             if (pricePerPackPage.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #12
0
        public void CanInjectArraysOfComponentsInConstructor2()
        {
            Order order1 = new Order();

            order1.CountryCode = "NZ";
            order1.Items.Add(new OrderItem("water", 10, 1.0m, false));
            order1.Items.Add(new OrderItem("glass", 5, 20.0m, true));

            Order order2 = new Order();

            order2.CountryCode = "US";
            order2.Items.Add(new OrderItem("sand", 50, 0.2m, false));

            ICostCalculator costCalculator = _container.Resolve <ICostCalculator>("cost_calculator_default");

            Assert.AreEqual(110m, costCalculator.CalculateTotal(order1));
            Assert.AreEqual(10m, costCalculator.CalculateTotal(order2));
        }
예제 #13
0
        public PathfinderEngine(int width, int height,
                                ICostCalculator costCalculator,
                                IHeuristicCalculator heuristicCalculator,
                                MovementMode explorationMode = MovementMode.FourDirection)
        {
            Debug.Assert(width > 0, "width <= 0");
            Debug.Assert(height > 0, "height <= 0");

            _width  = width;
            _height = height;

            this.MovementMode = explorationMode;

            _solution = new PathfinderNode[width, height];

            CostCalculator      = costCalculator;
            HeuristicCalculator = heuristicCalculator;
        }
예제 #14
0
        private static void CalculateRentTest()
        {
            Write("Podaj imię: ");
            string firstName = ReadLine();

            Write("Podaj nazwisko: ");
            string lastName = ReadLine();

            var rentee = new Man();

            rentee.FirstName = firstName;
            rentee.LastName  = lastName;

            Product item = new CrossCountrySki
            {
                Id           = 1,
                PricePerHour = 50,
                Name         = "Fisher",
                Size         = 150,
            };

            var rent = new Rent(rentee, item)
            {
                Id = 1,
            };

            // zwrot

            Thread.Sleep(TimeSpan.FromSeconds(1));

            rent.Return();

            ICalculatorFactory calculatorFactory = new CalculatorFactory();

            ICostCalculator calculator = calculatorFactory.Create(rent);

            rent.Cost = calculator.Calculate(rent);
        }
 private bool SetSellingPrice(ICostCalculator CostCalculator)
 {
     foreach (CostElement costElement in CostCalculator.CostElements)
     {
         costElement.CheckMovingAverageCost();
         if (costElement.PreviousCostDetials.PreviousStock.Rows.Count > 0)
         {
             using (SellingPriceValidation pricePerPackPage = new SellingPriceValidation(costElement.PreviousCostDetials))
             {
                 if (pricePerPackPage.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
                     return false;
             }
         }
     }
     return true;
 }
        private void OnConfirmClicked(object sender, EventArgs e)
        {
            if (BLL.Settings.IsCenter)
                {
                    GRV = new CenterCostCalculator();
                    GRV.LoadGRV(ReceiptID);
                    GRV.CalculateFinalCost();
                }
                else
                {
                    GRV = new CostCalculator();
                    GRV.LoadGRV(ReceiptID);
                    (GRV as CostCalculator).LoadGRVPreviousStock();
                    GRV.CalculateFinalCost();
                }
                if(!SetSellingPrice(GRV))
                {
                    return;
                }

            TransactionMgr transaction = TransactionMgr.ThreadTransactionMgr();
            try
            {
                transaction.BeginTransaction();
                // This is where we set the Price for the previous Stock
                foreach (CostElement costElement in GRV.CostElements)
                {
                    costElement.PreviousCostDetials.Confirm(CurrentContext.UserId);
                }

                PrintConfirmation(null);
                try
                {
                    CostingService.ConfirmPriceChange(GRV.CostElements, CurrentContext.UserId, ChangeMode.Recieve, ReceiptID.ToString());

                }
                catch (Exception exception)
                {
                    XtraMessageBox.Show(exception.Message);
                    throw exception;
                }
                transaction.CommitTransaction();
                this.LogActivity("Print-SRM", ReceiptID);
            }
            catch (Exception ex)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(ex.Message);
            }
        }
        private void OnConfirmClicked(object sender, EventArgs e)
        {
            printDialog = new PrintDialog();

                if (printDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
               {
                   XtraMessageBox.Show("Print has been Canceled By User");
                   return;
               }
                if (BLL.Settings.IsCenter)
                {
                    GRV = new CenterCostCalculator();
                    GRV.LoadGRV(ReceiptID);
                    GRV.CalculateFinalCost();
                }
                else
                {
                    GRV = new CostCalculator();
                    GRV.LoadGRV(ReceiptID);
                    (GRV as CostCalculator).LoadGRVPreviousStock();
                    GRV.CalculateFinalCost();
                }
                if(!SetSellingPrice(GRV))
                {
                    return;
                }

                HCMIS.Desktop.Reports.ReceiptConfirmationPrintout printout = new HCMIS.Desktop.Reports.ReceiptConfirmationPrintout(CurrentContext.LoggedInUserName);
                MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                try
                {
                  transaction.BeginTransaction();
                  // This is where we set the Price for the previous Stock
                  foreach (CostElement costElement in GRV.CostElements)
                  {
                          costElement.PreviousCostDetials.Confirm(CurrentContext.UserId);
                  }
                    printout = PrintConfirmation(null);
                    CostingService.ConfirmPriceChange(GRV.CostElements, CurrentContext.UserId, ChangeMode.Recieve, ReceiptID.ToString());
                    GRV.SetFinalCostlog(CurrentContext.UserId);
                    transaction.CommitTransaction();
                }
                catch (Exception ex)
                {
                    transaction.RollbackTransaction();

                    XtraMessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    throw ;
                }
                printout.Print(printDialog.PrinterSettings.PrinterName);
        }
예제 #18
0
 ServiceTaxApplicableCostCalculator(
     ICostCalculator with, ICostCalculator without)
 {
     this.with    = with;
     this.without = without;
 }
예제 #19
0
 public NightInOtherLines(ICostCalculator inner)
 {
     _inner = inner;
 }
예제 #20
0
 public App(IShoppingCart shoppingCart, ICostCalculator costCalculator)
 {
     _shoppingCart   = shoppingCart;
     _costCalculator = costCalculator;
 }
예제 #21
0
 public PeakHourInOtherLines(ICostCalculator inner)
 {
     _inner = inner;
 }
 public AzureCacheThrottlingService(DataCache dataCache, ICostCalculator costCalculator)
 {
     _dataCache = dataCache;
     _costCalculator = costCalculator;
 }
 public BestInsertion(ICostCalculator costCalculator)
 {
     _costCalculator = costCalculator;
 }
예제 #24
0
 public InterchangingAtNonPeak(ICostCalculator inner)
 {
     _inner = inner;
 }
예제 #25
0
 public SuperSendingMicroApp(ICostCalculator cost, IMessageSender sender, IAppLogger logger)
 {
     _cost   = cost ?? throw new ArgumentNullException(nameof(cost), $"{nameof(cost)} is null.");
     _sender = sender ?? throw new ArgumentNullException(nameof(sender), $"{nameof(sender)} is null.");
     _logger = logger ?? throw new ArgumentNullException(nameof(logger), $"{nameof(logger)} is null.");
 }
예제 #26
0
 protected PathFinder(NodeHandler nodeHandler, ICostCalculator costCalculator)
 {
     NodeHandler    = nodeHandler;
     CostCalculator = costCalculator;
 }
 public RentalsController(BikeRentalDbContext context, ICostCalculator calculator)
 {
     _context    = context;
     _calculator = calculator;
 }
예제 #28
0
 public InterchangingAtNight(ICostCalculator inner)
 {
     _inner = inner;
 }
예제 #29
0
 public InterchangingAtPeakHour(ICostCalculator inner)
 {
     _inner = inner;
 }
예제 #30
0
 public DataAccess(ICostCalculator c)
 {
     context    = new Context();
     calculator = c;
 }
예제 #31
0
 public NonPeakInDtTe(ICostCalculator inner)
 {
     _inner = inner;
 }
예제 #32
0
 public CostCalculatorTest()
 {
     CostCalculator = new CostCalculator();
 }
 public DisabledJourneyTime(ICostCalculator inner)
 {
     _inner = inner;
 }
예제 #34
0
 public PeakHourInNeNs(ICostCalculator inner)
 {
     _inner = inner;
 }
예제 #35
0
 public ConstructionWithBestInsertion(IRouteRepository routeRepository, IBestInsertion bestInsertion,
                                      INodeAndArcRepository nodeAndArcRepository, ICostCalculator costCalculator)
 {
     _routeRepository      = routeRepository;
     _bestInsertion        = bestInsertion;
     _nodeAndArcRepository = nodeAndArcRepository;
 }
예제 #36
0
 public OrOpt(IRouteRepository routeRepository, ICostCalculator costCalculator)
 {
     _routeRepository = routeRepository;
     _costCalculator  = costCalculator;
 }