Ejemplo n.º 1
0
        //------------------------------------- Static methods ---------------------------------------------
        public static CarrierAcct Get(short pCarrierAcctId)
        {
            CarrierAcct _carrierAcct = null;

            try {
                using (var _db = new Rbr_Db()) {
                    var _carrierAcctRow = _db.CarrierAcctCollection.GetByPrimaryKey(pCarrierAcctId);
                    if (_carrierAcctRow != null)
                    {
                        _carrierAcct = new CarrierAcct(_carrierAcctRow);
                    }
                }
            }
            catch (Exception _ex) {
                TimokLogger.Instance.LogRbr(LogSeverity.Critical, CARRIER_ACCT_GET_LABEL, string.Format("Exception:\r\n{0}", _ex));
            }

            if (_carrierAcct == null)
            {
                throw new RbrException(RbrResult.Carrier_NotFound, CARRIER_ACCT_GET_LABEL, string.Format("CarrierAcct NOT FOUND, CarrierAcctId={0}", pCarrierAcctId));
            }

            if (NumberOfCallsCounter.ContainsKey(_carrierAcct.Id))
            {
                if (NumberOfCallsCounter[_carrierAcct.Id] >= _carrierAcct.MaxNumberOfCalls)
                {
                    throw new RbrException(RbrResult.Carrier_LimitReached, CARRIER_ACCT_GET_LABEL, string.Format("CarrerAcctId={0}", _carrierAcct.Id));
                }
            }
            return(_carrierAcct);
        }
Ejemplo n.º 2
0
        //----------------------------------------- Public Instance Methods ------------------------------------
        public int Authorize(CustomerRoute pCustomerRoute)
        {
            if (Status != Status.Active)
            {
                throw new RbrException(RbrResult.Customer_NotActive, "CustomerAcct.Authorize", string.Format("CustomerAcctId={0}", Id));
            }

            if (NumberOfCallsCounter.ContainsKey(Id))
            {
                if (NumberOfCallsCounter[Id] >= MaxNumberOfCalls)
                {
                    throw new RbrException(RbrResult.Customer_LimitReached, "CustomerAcct.Authorize", string.Format("CustomerAcctId={0}", Id));
                }
            }

            if (!IsPrepaid)
            {
                return(MaxCallLength);
            }

            //-- Check prepaid conditions
            if (IsBalanceLimitReached)
            {
                throw new RbrException(RbrResult.Customer_BalanceInvalid, "CustomerAcct.Authorize", string.Format("Customer Balance INVALID, CustomerAcctId={0}", Id));
            }
            if (IsBalanceWarningLimitReached)
            {
                TimokLogger.Instance.LogRbr(LogSeverity.Error, "CustomerAcct.Authorize", string.Format("Customer Warning REACHED, CustomerAcctId={0}", Id));
            }

            if (pCustomerRoute.Status != Status.Active)
            {
                throw new RbrException(RbrResult.Customer_RouteBlocked, "CustomerAcct.Authorize", string.Format("CustomerAcctId={0}, CustomerRouteId={1}", Id, pCustomerRoute.WholesaleRouteId));
            }

            int _timeLimit = pCustomerRoute.GetTimeLimit(Balance);

            if (_timeLimit <= 0)
            {
                throw new RbrException(RbrResult.Customer_LimitReached, "CustomerAcct.Authorize", string.Format("Customer Limit REACHED, CustomerAcct={0}", Id));
            }

            if (_timeLimit > MaxCallLength)
            {
                _timeLimit = MaxCallLength;
                TimokLogger.Instance.LogRbr(LogSeverity.Status, "CustomerAcct.Authorize", string.Format("Max Call Time Limit REACHED, CustomerAcct={0}, Calculated TimeLimit={1}", Id, _timeLimit));
            }
            return(_timeLimit);
        }