コード例 #1
0
 public static int Update(Cdr pCdr)
 {
     using (var _db = new Cdr_Db(DateTime.Now)) {
         _db.CDRCollection.Update(pCdr.CdrRow);
     }
     return(0);
 }
コード例 #2
0
ファイル: CarrierAcct.cs プロジェクト: cuongdodinh/timok.rbr
        //----------------------------------------- Public Instance Methods ------------------------------------
        public int RateCall(CarrierRoute pCarrierRoute, ref Cdr pCdr)
        {
            int _result = 0;

            pCdr.CarrierDuration  = (short)((pCdr.Duration / 6) * 6);
            pCdr.CarrierDuration += (short)(pCdr.Duration % 6 > 0 ? 6 : 0);

            if (IsRatingEnabled && pCarrierRoute != null)
            {
                try {
                    short _roundedSeconds;
                    pCdr.CarrierCost = pCarrierRoute.GetCost(pCdr.StartTime, pCdr.Duration, out _roundedSeconds);
                    if (_roundedSeconds > short.MaxValue)
                    {
                        TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CarrierAcct.RateCall", "Rounded Seconds greater then short.MaxValue");
                    }
                    pCdr.CarrierDuration       = _roundedSeconds;
                    pCdr.CarrierRoundedMinutes = (short)(_roundedSeconds / 60);
                }
                catch (Exception _ex) {
                    _result = 1;
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, "CarrierAcct.RateCall", string.Format("Finding Carrier's cost, Exception:\r\n{0}", _ex));
                }
            }
            return(_result);
        }
コード例 #3
0
        //--------------- Static factories -------------------------------------------------------------
        public static IRetailAccount Get(CustomerAcct pCustomerAcct, Cdr pCdr, IConfiguration pConfiguration, ILogger pLogger)
        {
            if (pCustomerAcct == null)
            {
                TimokLogger.Instance.LogRbr(LogSeverity.Error, "RetailAccount.Get", "CustomerAcct NOT Found");
                return(null);
            }
            if (!pCustomerAcct.IsRetail)
            {
                TimokLogger.Instance.LogRbr(LogSeverity.Status, "RetailAccount.Get", string.Format("CustomerAcct NOT Retail: {0}", pCustomerAcct.Id));
                return(null);
            }

            IRetailAccount _retailAcct = null;

            try {
                if (pCustomerAcct.RetailType == RetailType.PhoneCard)
                {
                    _retailAcct = getPhoneCardBySerialNumber(pCustomerAcct.ServiceId, pCdr.SerialNumber, pConfiguration, pLogger);
                }
                else if (pCustomerAcct.RetailType == RetailType.Residential)
                {
                    _retailAcct = getResidential(pCustomerAcct.ServiceId, pCdr.ANI);
                }
                else
                {
                    TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Get", string.Format("Unknown Retailtype: CustomerAcct: {0} SerialNumber: {1}", pCustomerAcct.Id, pCdr.SerialNumber));
                }

                if (_retailAcct == null)
                {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, "RetailAccount.Get", string.Format("RetailAcct NOT FOUND: CustomerAcct: {0} SerialNumber: {1}", pCustomerAcct.Id, pCdr.SerialNumber));
                    return(null);
                }
            }
            catch (Exception _ex) {
                TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Get", string.Format("Exception:\r\n{0}", _ex));
                return(null);
            }
            return(_retailAcct);
        }
コード例 #4
0
ファイル: CustomerAcct.cs プロジェクト: cuongdodinh/timok.rbr
        public int RateCall(CustomerRoute pCustomerRoute, ref Cdr pCdr)
        {
            int _result = 0;

            pCdr.CustomerDuration  = (short)((pCdr.Duration / 6) * 6);
            pCdr.CustomerDuration += (short)(pCdr.Duration % 6 > 0 ? 6 : 0);

            if (IsRatingEnabled && pCustomerRoute != null)
            {
                if (IsWholesale)
                {
                    try {
                        short _roundedSeconds;
                        pCdr.CustomerPrice = pCustomerRoute.GetWholesaleCost(pCdr.StartTime, pCdr.Duration, out _roundedSeconds);
                        if (_roundedSeconds > short.MaxValue)
                        {
                            TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CustomerAcct.RateCall", "Rounded Seconds greater then short.MaxValue");
                        }
                        pCdr.CustomerDuration       = _roundedSeconds;
                        pCdr.CustomerRoundedMinutes = (short)(_roundedSeconds / 60);
                    }
                    catch (Exception _ex) {
                        _result = 1;
                        TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerAcct.RateCall", string.Format("Finding Wholesale price, Exception:\r\n{0}", _ex));
                    }
                }
                else if (IsRetail)
                {
                    //-- Add retail part, to supress errors, retail rated separately
                }
                else
                {
                    _result = 1;
                    TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CustomerAcct.RateCall", string.Format("Unknown CustomerType, {0}", serviceType));
                }
            }
            return(_result);
        }
コード例 #5
0
        public int Rate(CustomerRoute pCustomerRoute, ref Cdr pCdr)
        {
            short _roundedSeconds = 0;

            try {
                pCdr.RetailDuration = 0;
                if (pCdr.Duration > 0)
                {
                    pCdr.RetailDuration  = (short)((pCdr.Duration / 6) * 6);
                    pCdr.RetailDuration += (short)(pCdr.Duration % 6 > 0 ? 6 : 0);
                }

                if (pCustomerRoute != null && pCustomerRoute.WithBonusMinutes && WithBonusMinutes && CurrentBonusBalance > 0)
                {
                    pCdr.RetailRoundedMinutes = (short)(pCdr.Duration / 60 + (pCdr.Duration % 60 > 0 ? 1 : 0));
                    if (CurrentBonusBalance < pCdr.RetailRoundedMinutes)
                    {
                        TimokLogger.Instance.LogRbr(LogSeverity.Debug, "RetailAccount.Rate", string.Format("All bonus minutes used: {0} | {1}", CurrentBonusBalance, pCdr.RetailRoundedMinutes));
                        var _overflowDuration = (pCdr.RetailRoundedMinutes - CurrentBonusBalance) * 60;                         //in seconds
                        pCdr.RetailPrice = pCustomerRoute.GetWholesaleCost(pCdr.StartTime, _overflowDuration, out _roundedSeconds);
                    }
                    else
                    {
                        //TODO: should substract bonus minutes used from duration and then chargae balance for the remianing time used!!!
                        //NOTE: this is NOT correct
                        _roundedSeconds       = (short)(pCdr.RetailRoundedMinutes * 60);
                        pCdr.UsedBonusMinutes = pCdr.RetailRoundedMinutes;
                    }
                }
                else
                {
                    var _service = RetailService.Get(pCdr.DNIS.ToString());
                    if (_service == null)
                    {
                        TimokLogger.Instance.LogRbr(LogSeverity.Error, "RetailAccount.Rate", string.Format("Service NOT found, AccessNumber: {0}", pCdr.DNIS));
                        return(1);
                    }

                    var _payphoneSurcharge = SurchargeInfo.Empty;
                    if (pCdr.InfoDigits > 0)
                    {
                        if (_service.PayphoneSurchargeInfo != null)
                        {
                            _payphoneSurcharge = _service.PayphoneSurchargeInfo;
                        }
                        else
                        {
                            TimokLogger.Instance.LogRbr(LogSeverity.Error, "RetailAccount.Rate", "PayphoneSurcharge required, but NOT defined");
                        }
                    }

                    if (pCustomerRoute != null)
                    {
                        pCdr.RetailPrice = pCustomerRoute.GetRetailCost(pCdr.StartTime, pCdr.Duration, _service.AccessNumberSurchargeInfo, _payphoneSurcharge, out _roundedSeconds);
                    }
                    else
                    {
                        //- Apply surcharges only!
                        if (_service.AccessNumberSurchargeInfo != null)
                        {
                            pCdr.RetailPrice += _service.AccessNumberSurchargeInfo.Cost;
                        }
                        if (_payphoneSurcharge != null)
                        {
                            pCdr.RetailPrice += _payphoneSurcharge.Cost;
                        }
                    }
                }

                if (pCdr.RetailPrice < decimal.Zero)
                {
                    TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Rate", string.Format("Price < decimal.Zero: {0} | 0.0", pCdr.RetailPrice));
                    return(1);
                }
                if (_roundedSeconds > short.MaxValue)
                {
                    TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Rate", "Rounded Seconds greater then short.MaxValue !");
                    return(1);
                }
                pCdr.RetailDuration       = _roundedSeconds;
                pCdr.RetailRoundedMinutes = (short)(_roundedSeconds / 60);
                pCdr.UsedBonusMinutes     = CurrentBonusBalance;
            }
            catch (Exception _ex) {
                TimokLogger.Instance.LogRbr(LogSeverity.Critical, "RetailAccount.Rate", string.Format("Exception:\r\n{0}", _ex));
                return(1);
            }
            return(0);
        }
コード例 #6
0
        public void OnCallComplete(Cdr pCdr)
        {
            try {
                T.LogRbr(LogSeverity.Debug, "CdrAggrExporter.OnCallComplete", string.Format("Duration {0}, InRouteId:{1}, CustomerAcctId:{2}, TermIP:{3}, Minutes: {4}, Cost: {5}, Resell: {6}, Sell: {7},", pCdr.Duration, pCdr.CustomerBaseRouteId, pCdr.CustomerAcctId, pCdr.TermIP, pCdr.Minutes, pCdr.CarrierCost, pCdr.CustomerPrice, pCdr.RetailPrice));
                if (pCdr.Duration <= 0)
                {
                    if (pCdr.Duration < 0)
                    {
                        T.LogRbr(LogSeverity.Critical, "CdrAggrExporter.OnCallComplete", "Duration less then zero?");
                    }
                    return;
                }

                lock (Padlock) {
                    var _cdrAggregate         = new CdrAggregate(pCdr.DNIS.ToString(), pCdr.OrigIP, pCdr.TermIP, pCdr.CustomerBaseRouteId, pCdr.CarrierBaseRouteId, pCdr.CustomerAcctId, pCdr.CarrierAcctId);
                    var _cdrAggregateFromImdb = Get(_cdrAggregate.PK);
                    if (_cdrAggregateFromImdb == null)
                    {
                        T.LogRbr(LogSeverity.Debug, "CdrAggrExporter.OnCallComplete", string.Format("CdrAggregate NOT FOUND, Pk={0}", _cdrAggregate.PK));

                        if (pCdr.Duration > 0)
                        {
                            _cdrAggregate.CallsCompleted = 1;

                            _cdrAggregate.ConnectedSeconds = pCdr.Duration;
                            _cdrAggregate.ConnectedMinutes = pCdr.Minutes;

                            _cdrAggregate.CarrierCost           = pCdr.CarrierCost;
                            _cdrAggregate.CarrierRoundedMinutes = pCdr.CarrierRoundedMinutes;

                            _cdrAggregate.WholesalePrice          = pCdr.CustomerPrice;
                            _cdrAggregate.WholesaleRoundedMinutes = pCdr.CustomerRoundedMinutes;

                            _cdrAggregate.EndUserPrice          = pCdr.RetailPrice;
                            _cdrAggregate.EndUserRoundedMinutes = pCdr.RetailRoundedMinutes;
                            Put(_cdrAggregate);
                        }
                        //else {
                        //TODO: need to pass leg1 length from Gk....
                        //_cdrAggregate.SetupSeconds = pCdr.Leg1Duration;
                        //}
                    }
                    else
                    {
                        T.LogRbr(LogSeverity.Debug, "CdrAggrExporter.OnCallComplete", string.Format("CdrAggregate FOUND, Pk={0}", _cdrAggregate.PK));

                        if (pCdr.Duration > 0)
                        {
                            _cdrAggregateFromImdb.CallsCompleted += 1;

                            _cdrAggregateFromImdb.ConnectedSeconds += pCdr.Duration;
                            _cdrAggregateFromImdb.ConnectedMinutes += pCdr.Minutes;

                            _cdrAggregateFromImdb.CarrierCost           = decimal.Add(_cdrAggregate.CarrierCost, pCdr.CarrierCost);
                            _cdrAggregateFromImdb.CarrierRoundedMinutes = decimal.Add(_cdrAggregate.CarrierRoundedMinutes, pCdr.CarrierRoundedMinutes);

                            _cdrAggregateFromImdb.WholesalePrice          = decimal.Add(_cdrAggregate.WholesalePrice, pCdr.CustomerPrice);
                            _cdrAggregateFromImdb.WholesaleRoundedMinutes = decimal.Add(_cdrAggregate.WholesaleRoundedMinutes, pCdr.CustomerRoundedMinutes);

                            _cdrAggregateFromImdb.EndUserPrice          = decimal.Add(_cdrAggregate.EndUserPrice, pCdr.RetailPrice);
                            _cdrAggregateFromImdb.EndUserRoundedMinutes = decimal.Add(_cdrAggregate.EndUserRoundedMinutes, pCdr.RetailRoundedMinutes);
                        }
                        //else {
                        //TODO: need to pass leg1 length from Gk....
                        //_cdrAggregate.SetupSeconds += pCdr.Leg1Duration;
                        //}
                    }
                }
            }
            catch (Exception _ex) {
                T.LogRbr(LogSeverity.Critical, "CdrAggrExporter.OnCallComplete", string.Format("OnCallComplete, Exception:\r\n{0}", _ex));
            }
        }