示例#1
0
        public List <LegOut> GetTerminationByDestination(CustomerAcct pCustomerAcct, CustomerRoute pCustomerRoute, string pDestNumber, int pTimeLimit)
        {
            var _routingAlgorithm = pCustomerRoute.RoutingAlgorithmType;

            TimokLogger.Instance.LogRbr(LogSeverity.Status, "RbrDispatcher.GetTerminationByDestination", string.Format("Routing Alghorithm={0}", _routingAlgorithm));

            var _carrierRoutes = getCarrierRoutes(pCustomerAcct, pCustomerRoute, _routingAlgorithm, pDestNumber);

            if (_carrierRoutes == null || _carrierRoutes.Count == 0)
            {
                throw new RbrException(RbrResult.Carrier_NoRoutesFound, "RoutingService.GetTerminationByDestination", string.Format("DestinationNumber={0}", pDestNumber));
            }

            var _termInfoList = new List <TerminationInfo>();

            foreach (var _carrierRoute in _carrierRoutes)
            {
                var _carrierAcct = CarrierAcct.Get(_carrierRoute.CarrierAcctId);
                if (_carrierAcct.Status != Status.Active)
                {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, "RoutingService.GetTerminationByDestination", string.Format("CarrierAcct NOT Active, CarrierAcct={0}", _carrierAcct.Id));
                    continue;
                }

                if (CarrierAcct.NumberOfCallsCounter.ContainsKey(_carrierAcct.Id))
                {
                    if (CarrierAcct.NumberOfCallsCounter[_carrierAcct.Id] >= _carrierAcct.MaxNumberOfCalls)
                    {
                        TimokLogger.Instance.LogRbr(LogSeverity.Error, "RoutingService.GetTerminationByDestination", string.Format("CarrierAcct Max Calls Limit, CarrierAcct={0}", _carrierAcct.Id));
                        continue;
                    }
                }
                else
                {
                    CarrierAcct.NumberOfCallsCounter.Add(_carrierAcct.Id, 0);
                }
                CarrierAcct.NumberOfCallsCounter[_carrierAcct.Id] += 1;

                var _termEP = _carrierRoute.GetFirstTermEndpoint();
                if (_termEP == null)
                {
                    continue;
                }

                var _termInfo = new TerminationInfo(_carrierAcct, _carrierRoute, _termEP);
                TimokLogger.Instance.LogRbr(LogSeverity.Debug, "RbrDispatcher.GetTerminationByDestination", string.Format("TermInfo={0}", _termInfo));
                _termInfoList.Add(_termInfo);
            }

            if (_termInfoList == null || _termInfoList.Count == 0)
            {
                throw new RbrException(RbrResult.Carrier_NoTermEPsFound, "RoutingService.GetTerminationByDestination", string.Format("DestinationNumber={0}", pDestNumber));
            }

            return(getLegOutOptions(pCustomerAcct, pDestNumber, _termInfoList, pTimeLimit));
        }
示例#2
0
        int parseCarrier(Cdr pCdr, out CarrierAcct pCarrierAcct, out CarrierRoute pCarrierRoute)
        {
            pCarrierAcct  = null;
            pCarrierRoute = null;

            if (pCdr.CarrierAcctId == 0)
            {
                T.LogRbr(LogSeverity.Error, "BillingService.parseCarrier:", "Carrier NOT FOUND, CarrierAcctId=0");
                return(1);
            }

            try {
                pCarrierAcct = CarrierAcct.Get(pCdr.CarrierAcctId);
                if (pCarrierAcct == null)
                {
                    return(1);
                }

                if (CarrierAcct.NumberOfCallsCounter.ContainsKey(pCarrierAcct.Id))
                {
                    if (CarrierAcct.NumberOfCallsCounter[pCarrierAcct.Id] > 0)
                    {
                        T.LogRbr(LogSeverity.Debug, "BillingService.parseCarrier:", string.Format("Calls LIMIT stat, CarrierAcct={0}, NumberOfCalls={1}", pCarrierAcct.Id, CustomerAcct.NumberOfCallsCounter[pCarrierAcct.Id]));
                        CarrierAcct.NumberOfCallsCounter[pCarrierAcct.Id] -= 1;
                    }
                }

                //-- get carrier route
                pCarrierRoute = CarrierRoute.Get(pCdr.CarrierAcctId, pCdr.CarrierBaseRouteId);
                if (pCarrierRoute == null)
                {
                    T.LogRbr(LogSeverity.Error, "BillingService.parseCarrier:", string.Format("Route NOT FOUND, CarrierAcctId={0}, CarrierBaseRouteId={1}, DestNumber={2}", pCarrierAcct.Id, pCdr.CarrierBaseRouteId, pCdr.DestNumber));
                    return(1);
                }
                pCdr.CarrierRouteName = pCarrierRoute.Name;

                //-- get term ep
                var _termEP = (new RoutingService()).GetTermEP(pCdr.TermIP, pCdr.Duration);
                if (_termEP == null)
                {
                    T.LogRbr(LogSeverity.Error, "BillingService.parseCarrier:", string.Format("TermEP NOT FOUND={0}", pCdr));
                    pCdr.TermEPId = 0;
                    return(1);
                }
                pCdr.TermEPId = _termEP.Id;
            }
            catch (Exception _ex) {
                T.LogRbr(LogSeverity.Error, "BillingService.parseCarrier:", string.Format("Exception:\r\n{0}", _ex));
                return(1);
            }
            return(0);
        }
        static bool rerateCDR(CDRViewRow_Base pCdrViewRow, IBackgroundWorker pBackgroundWorker)
        {
            try {
                var _customerAcct = CustomerAcct.Get(pCdrViewRow.Customer_acct_id);
                if (_customerAcct == null)
                {
                    pBackgroundWorker.ReportStatus(string.Format("ERROR! CustomerAcct NOT FOUND, {0}", pCdrViewRow.Customer_acct_id));
                    return(false);
                }

                var _customerRoute = CustomerRoute.Get(_customerAcct.ServiceId, _customerAcct.RoutingPlanId, pCdrViewRow.Customer_route_id);
                if (_customerRoute == null)
                {
                    pBackgroundWorker.ReportStatus(string.Format("ERROR! CustomerRoute NOT FOUND, {0}", pCdrViewRow.Customer_route_id));
                    return(false);
                }

                var _carrierAcct = CarrierAcct.Get(pCdrViewRow.Carrier_acct_id);
                if (_carrierAcct == null)
                {
                    pBackgroundWorker.ReportStatus(string.Format("ERROR! CarrierAcct NOT FOUND, {0}", pCdrViewRow.Carrier_acct_id));
                    return(false);
                }

                var _carrierRoute = CarrierRoute.Get(_carrierAcct.Id, pCdrViewRow.Carrier_route_id);
                if (_carrierRoute == null)
                {
                    pBackgroundWorker.ReportStatus(string.Format("ERROR! CarrierRoute NOT FOUND, {0}", pCdrViewRow.Carrier_route_id));
                    return(false);
                }

                var _cdr = new Cdr(pCdrViewRow);
                _customerAcct.RateCall(_customerRoute, ref _cdr);
                pCdrViewRow.Customer_duration = _cdr.CustomerDuration;
                pCdrViewRow.Price             = _cdr.CustomerPrice;
                _carrierAcct.RateCall(_carrierRoute, ref _cdr);
                pCdrViewRow.Carrier_duration = _cdr.CarrierDuration;
                pCdrViewRow.Cost             = _cdr.CarrierCost;
            }
            catch (Exception _ex) {
                pBackgroundWorker.ReportStatus(string.Format("Exception! {0}", _ex.Message));
                TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CdrExportController.rerate", string.Format("Exception:\r\n{0}", _ex));
                return(false);
            }
            return(true);
        }