Example #1
0
        /// <summary>
        /// 模板数据格式化字符串
        /// </summary>
        /// <param name="model">计费模板模型</param>
        /// <param name="carType">0:时租车  2:储值车</param>
        /// <returns></returns>
        private string TemplateDataFormatStr(BillingTemplateModel model, CarTypeEnum carType)
        {
            string          templateStr = string.Empty;
            ITollCalculator tollModel   = TemplateDataFormat(model);

            if (tollModel != null)
            {
                templateStr = tollModel.GetTollFeesTemplateStr(model);
            }

            //模板字符串前缀 说明:T0100015  T:临时卡 R:储值卡   01:第一套算费模板   00015:出场免费时间(单位分钟)
            string prefix = "";

            if (carType == CarTypeEnum.TempCar)
            {
                prefix = "T";
            }
            else if (carType == CarTypeEnum.ValueCar)
            {
                prefix = "R";
            }
            else
            {
                return("");
            }
            string templateIndex = model.ChargeMode.ToString().PadLeft(2, '0');
            string timeOut       = tollModel.GetLeaveTimeOut(model).ToString().PadLeft(5, '0');

            prefix = prefix + templateIndex + timeOut;

            //示例 T0100015300102030405060708090A0A0A0A0A0A0A0A0A0A0A0A0A0A0AFFFFFF00000000
            templateStr = prefix + templateStr;
            return(templateStr);
        }
Example #2
0
        /// <summary>
        /// 获得模板数据的超时时长
        /// </summary>
        /// <param name="chargeMode">计费方式</param>
        /// <returns>分钟数</returns>
        private static int TemplateDataTimeOut(BillingTemplateModel model, ILogger m_logger, ISerializer m_serializer)
        {
            int             timeOut   = 0;
            ITollCalculator tollModel = null;

            switch (model.ChargeMode)
            {
            case 1:
                tollModel = new TollCalculator_Hourly(m_logger, m_serializer);
                break;

            case 2:
                tollModel = new TollCalculator_Segment(m_logger, m_serializer);
                break;

            case 3:
                tollModel = new TollCalculator_ShenZheng(m_logger, m_serializer);
                break;

            case 4:
                tollModel = new TollCalculator_HalfHourly(m_logger, m_serializer);
                break;

            case 5:
                tollModel = new TollCalculator_SimpleSegment(m_logger, m_serializer);
                break;

            case 6:
                tollModel = new TollCalculator_SegmentHourly(m_logger, m_serializer);
                break;

            case 7:
                tollModel = new TollCalculator_SegmentNone(m_logger, m_serializer);
                break;

            case 8:
                tollModel = new TollCalculator_SegmentHalfHour(m_logger, m_serializer);
                break;

            case 9:
                tollModel = new TollCalculator_NewSegment(m_logger, m_serializer);
                break;

            case 10:
                tollModel = new TollCalculator_SegmentQuarterHour(m_logger, m_serializer);
                break;
            }
            if (tollModel != null)
            {
                timeOut = tollModel.GetLeaveTimeOut(model);
            }
            return(timeOut);
        }
Example #3
0
        /// <summary>
        /// 模板数据进行格式化
        /// </summary>
        /// <param name="chargeMode">计费方式</param>
        /// <returns></returns>
        private ITollCalculator TemplateDataFormat(BillingTemplateModel model)
        {
            ITollCalculator tollModel = null;

            switch (model.ChargeMode)
            {
            case 1:
                tollModel = new TollCalculator_Hourly(m_logger, m_serializer);
                break;

            case 2:
                tollModel = new TollCalculator_Segment(m_logger, m_serializer);
                break;

            case 3:
                tollModel = new TollCalculator_ShenZheng(m_logger, m_serializer);
                break;

            case 4:
                tollModel = new TollCalculator_HalfHourly(m_logger, m_serializer);
                break;

            case 5:
                tollModel = new TollCalculator_SimpleSegment(m_logger, m_serializer);
                break;

            case 6:
                tollModel = new TollCalculator_SegmentHourly(m_logger, m_serializer);
                break;

            case 7:
                tollModel = new TollCalculator_SegmentNone(m_logger, m_serializer);
                break;

            case 8:
                tollModel = new TollCalculator_SegmentHalfHour(m_logger, m_serializer);
                break;

            case 9:
                tollModel = new TollCalculator_NewSegment(m_logger, m_serializer);
                break;

            case 10:
                tollModel = new TollCalculator_SegmentQuarterHour(m_logger, m_serializer);
                break;
            }
            return(tollModel);
        }
Example #4
0
        static void TestOccupancy(string regionName)
        {
            ITollCalculator tollCalc = regionName switch
            {
                "Pattern_CarTaxiOccupancy" => new TollCalculatorV2() as ITollCalculator,
                "Pattern_BusOccupancy" => new TollCalculatorV3() as ITollCalculator,
                "Pattern_DeliveryTruckWeight" => new TollCalculatorV4() as ITollCalculator,
                "Pattern_ChainedPatterns" => new TollCalculatorV5() as ITollCalculator,
                _ => new TollCalculatorV1() as ITollCalculator,
            };

            var soloDriver   = new Car();
            var twoRideShare = new Car {
                Passengers = 1
            };
            var threeRideShare = new Car {
                Passengers = 2
            };
            var fullVan = new Car {
                Passengers = 5
            };
            var emptyTaxi  = new Taxi();
            var singleFare = new Taxi {
                Fares = 1
            };
            var doubleFare = new Taxi {
                Fares = 2
            };
            var fullVanPool = new Taxi {
                Fares = 5
            };
            var lowOccupantBus = new Bus {
                Capacity = 90, Riders = 15
            };
            var normalBus = new Bus {
                Capacity = 90, Riders = 75
            };
            var fullBus = new Bus {
                Capacity = 90, Riders = 85
            };

            var heavyTruck = new DeliveryTruck {
                GrossWeightClass = 7500
            };
            var truck = new DeliveryTruck {
                GrossWeightClass = 4000
            };
            var lightTruck = new DeliveryTruck {
                GrossWeightClass = 2500
            };

            Console.WriteLine($"The toll for a solo driver is {tollCalc.CalculateToll(soloDriver)}");
            Console.WriteLine($"The toll for a two ride share is {tollCalc.CalculateToll(twoRideShare)}");
            Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}");
            Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}");

            Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
            Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}");
            Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}");
            Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}");

            Console.WriteLine($"The toll for a low-occupant bus is {tollCalc.CalculateToll(lowOccupantBus)}");
            Console.WriteLine($"The toll for a regular bus is {tollCalc.CalculateToll(normalBus)}");
            Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(fullBus)}");

            Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(heavyTruck)}");
            Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}");
            Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(lightTruck)}");

            try
            {
                tollCalc.CalculateToll("this will fail");
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Caught an argument exception when using the wrong type");
            }
            try
            {
                tollCalc.CalculateToll(null !);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Caught an argument exception when using null");
            }
        }
Example #5
0
 public HomeController(ITollCalculator tollCalculator)
 {
     _tollCalculator = tollCalculator;
 }
 public HomeController(ITollCalculator tollCalculator, GothenburgTollDBContext context)
 {
     _tollCalculator = tollCalculator;
     _context        = context;
 }