void makeCall() { session.State = SessionState.Leg2Signaling; var _destIPAddress = IPUtil.ExtractIPAddress(legOutOptions[outboundAttempt - 1].DestIPAndPort); var _destNumberAndPrefix = legOutOptions[outboundAttempt - 1].DestNumber; //var _destPrefix = getPrefix(_destNumberAndPrefix); //var _destNumber = getDestNumber(_destNumberAndPrefix, _destPrefix.Length); var _customHeader = legOutOptions[outboundAttempt - 1].CustomHeader ?? string.Empty; if (session.Channel.MakeCall(session.ANI, _destNumberAndPrefix, _destIPAddress, isNotCallRoutingScript, _customHeader)) { if (isCallRoutingScript) { session.Channel.SendAcceptCall(Script.ScriptType.ToString()); session.Channel.WaitForEventIn(); } session.State = SessionState.Leg2Redirecting; if (session.Channel.RedirectMedia()) { session.State = SessionState.Leg2; if (isNotCallRoutingScript) { session.Channel.DestroyResources(); } setConnected(_destIPAddress); waitForCallEnd(); return; } throw new RbrException(RbrResult.IVR_MakeCallOut, "SessionScriptBase.makeCall", "ERROR: RedirectCall failed"); } throw new RbrException(RbrResult.IVR_MakeCallOut, "SessionScriptBase.makeCall", "ERROR: MakeCall Failed"); }
public CallState OnConnecting(LegIn pLegIn, LegOut pLegOut) { cdrAggrExporter.OnCallSetup(string.Empty, pLegOut.CarrierAcctId, pLegOut.CarrierBaseRouteId, pLegIn.CustomerAcctId, pLegIn.CustomerRouteId, IPUtil.ExtractIPAddress(pLegIn.IPAndPort), IPUtil.ExtractIPAddress(pLegOut.DestIPAndPort)); return(callStatistics.OnConnecting(pLegIn, pLegOut)); }
public override RbrResult AuthorizeRetail(ISession pSession, out LegIn pLegIn, out List <LegOut> pLegOutOptions) { pLegIn = new LegIn { ANI = pSession.ANI, IP = pSession.OrigIPAddress, IPAndPort = string.Empty, CustomerAcctId = 0, CustomerRouteId = 0, PromptTimeLimit = 0 }; pLegOutOptions = null; try { logger.LogRbr(LogSeverity.Status, AUTHORIZE_RETAIL_LABEL, string.Format("Request: IP={0}, ANI={1}, AccessNumber={2}, CardNumber={3}, DestNumber={4}", pSession.OrigIPAddress, pSession.ANI, pSession.AccessNumber, pSession.CardNumber, pSession.DestNumber)); var _retailService = RetailService.Get(pSession.AccessNumber); var _retailAcct = _retailService.GetRetailAccount(pSession); var _customerAcct = CustomerAcct.Get(_retailAcct.CustomerAcctId); if (CustomerAcct.NumberOfCallsCounter.ContainsKey(_customerAcct.Id)) { if (CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] > _customerAcct.MaxNumberOfCalls) { throw new RbrException(RbrResult.Customer_MaxCallsReached, AUTHORIZE_RETAIL_LABEL, string.Format("CustomerAcct ID={0}, MaxCalls={1}", _customerAcct.Id, CustomerAcct.NumberOfCallsCounter[_customerAcct.Id])); } } else { CustomerAcct.NumberOfCallsCounter.Add(_customerAcct.Id, 0); } CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] += 1; var _destNumber = routingService.CleanDestNumber(string.Empty, pSession.DestNumber); var _customerRoute = CustomerRoute.Get(_customerAcct.ServiceId, _customerAcct.CallingPlanId, _customerAcct.RoutingPlanId, _destNumber); pLegIn.CustomerRouteId = _customerRoute.BaseRouteId; //-- Authorize Wholesale Account var _wholesaleTimeLimit = _customerAcct.Authorize(_customerRoute); //-- Authorize Retail Account int _timeLimit; _retailService.Authorize(pSession, _retailAcct, _customerRoute, out _timeLimit, out pLegIn.PromptTimeLimit); if (_timeLimit > _wholesaleTimeLimit) { logger.LogRbr(LogSeverity.Status, AUTHORIZE_RETAIL_LABEL, string.Format("Customer MaxCallTime REACHED, CustomerAcctId={0}, TimeLimit={1}", _customerAcct.Id, _wholesaleTimeLimit)); _timeLimit = _wholesaleTimeLimit; } if (_timeLimit == 0) { throw new RbrException(RbrResult.Retail_NoBalanceForRoute, AUTHORIZE_RETAIL_LABEL, string.Format("NOT Enough Balance for Route, CustomerAcctId={0}, (W) RouteId={1}", _customerAcct.Id, _customerRoute.WholesaleRouteId)); } //-- propmpt multiplier if (_customerRoute.Multiplier > 0) { pLegIn.PromptTimeLimit = (_timeLimit * _customerRoute.Multiplier) / 100; } else { pLegIn.PromptTimeLimit = _timeLimit; } pLegOutOptions = routingService.GetTerminationByDestination(_customerAcct, _customerRoute, _destNumber, _timeLimit); _retailAcct.UpdateUsage(); //TODO: Move up to IVR for additional LCR calls!! cdrAggrExporter.OnCallSetup(pSession.AccessNumber, pLegOutOptions[0].CarrierAcctId, pLegOutOptions[0].CarrierBaseRouteId, _customerAcct.Id, pLegIn.CustomerRouteId, pSession.OrigIPAddress, IPUtil.ExtractIPAddress(pLegOutOptions[0].DestIPAndPort)); logger.LogRbr(LogSeverity.Status, AUTHORIZE_RETAIL_LABEL, string.Format("Response: Dest#={0}, CalledIP={1}, CustId={2}, CarrierId={3}, CustRouteId={4}, CarrierRouteId={5}, TimeLimit={6}, PTimeLimit={7}", /**/ pLegOutOptions[0].DestNumber, /**/ pLegOutOptions[0].DestIPAndPort, /**/ _customerAcct.Id, /**/ pLegOutOptions[0].CarrierAcctId, /**/ _customerRoute.BaseRouteId, /**/ pLegOutOptions[0].CarrierBaseRouteId, /**/ pLegOutOptions[0].TimeLimit, /**/ pLegIn.PromptTimeLimit)); } catch (RbrException _rbrex) { logger.LogRbr(LogSeverity.Error, AUTHORIZE_RETAIL_LABEL, string.Format("RbrException, from: {0}\r\n{1}", _rbrex.Source, _rbrex.Message)); return(_rbrex.RbrResult); } catch (Exception _ex) { logger.LogRbr(LogSeverity.Critical, AUTHORIZE_RETAIL_LABEL, string.Format("Exception:\r\n{0}", _ex)); return(RbrResult.ExceptionThrown); } return(RbrResult.Success); }
public void Set(LegOut pLegOut) { destIPAddress = IPUtil.ExtractIPAddress(pLegOut.DestIPAndPort); carrierAcctId = pLegOut.CarrierAcctId; carrierBaseRouteId = pLegOut.CarrierBaseRouteId; }
public override RbrResult AuthorizeWholesale(string pCallId, string pOrigIP, string pAlias, string pANI, string pDestNumber, out LegIn pLegIn, out List <LegOut> pLegOutOptions) { pLegIn = new LegIn { ANI = pANI, CustomerAcctId = 0, CustomerRouteId = 0, IP = pOrigIP, IPAndPort = String.Empty, PromptTimeLimit = 0 }; pLegOutOptions = null; var _outDestNumber = pDestNumber; //it may be cleared of inbound prefix and overwritten by outbound Prefix, IntlDialCode try { //-- Resolve OrigEndPoint and strip off origPrefix intl -dialcode: var _origEP = Endpoint.Get(pOrigIP); if (_origEP == null) { throw new RbrException(RbrResult.OrigEP_NotFound, AUTHORIZE_WHOLESALE_LABEL, string.Format("OrigEP IP={0}", pOrigIP)); } _origEP.TakeSample(); pLegIn.IPAndPort = string.Format("{0}:{1}", _origEP.IPAddress, _origEP.Port); if (_origEP.Status != Status.Active) { throw new RbrException(RbrResult.OrigEP_NotActive, AUTHORIZE_WHOLESALE_LABEL, string.Format("OrigEP IP={0}", _origEP.IPAddress)); } //-- Get inbound prefix and clean destNumber var _prefixIn = _origEP.GetPrefixIn(_outDestNumber); _outDestNumber = routingService.CleanDestNumber(_prefixIn, _outDestNumber); //-- First try to get CustomerAcct: var _customerAcct = CustomerAcct.Get(_origEP, _prefixIn); if (_customerAcct == null) { throw new RbrException(RbrResult.Customer_NotFound, AUTHORIZE_WHOLESALE_LABEL, string.Format("CustomerAcct NOT FOUND, OrigEPId={0}, Prefix={1}", _origEP.Id, _prefixIn)); } pLegIn.CustomerAcctId = _customerAcct.Id; //-- Limit CustomerAcct number of Calls if (CustomerAcct.NumberOfCallsCounter.ContainsKey(_customerAcct.Id)) { if (CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] > _customerAcct.MaxNumberOfCalls) { throw new RbrException(RbrResult.Customer_MaxCallsReached, AUTHORIZE_WHOLESALE_LABEL, string.Format("CustomerAcct ID={0}, MaxCalls={1}", _customerAcct.Id, CustomerAcct.NumberOfCallsCounter[_customerAcct.Id])); } } else { CustomerAcct.NumberOfCallsCounter.Add(_customerAcct.Id, 0); } CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] += 1; //-- Get and validate customer route: var _customerRoute = CustomerRoute.Get(_customerAcct.ServiceId, _customerAcct.CallingPlanId, _customerAcct.RoutingPlanId, _outDestNumber); pLegIn.CustomerRouteId = _customerRoute.BaseRouteId; if (_customerRoute.Status != Status.Active) { throw new RbrException(RbrResult.Customer_RouteBlocked, AUTHORIZE_WHOLESALE_LABEL, string.Format("Customer Route BLOCKED, RouteId={0}", _customerRoute)); } //-- Authorize CustomerAcct and get TimeLimit (if PrepaidEnabled): var _timeLimit = _customerAcct.Authorize(_customerRoute); //-- Get best termination choice: pLegOutOptions = routingService.GetTerminationByDestination(_customerAcct, _customerRoute, _outDestNumber, _timeLimit); //TODO: Move up to IVR for additional LCR calls!! cdrAggrExporter.OnCallSetup(string.Empty, pLegOutOptions[0].CarrierAcctId, pLegOutOptions[0].CarrierBaseRouteId, _customerAcct.Id, pLegIn.CustomerRouteId, _origEP.IPAddress, IPUtil.ExtractIPAddress(pLegOutOptions[0].DestIPAndPort)); } catch (RbrException _rbrex) { logger.LogRbr(LogSeverity.Error, AUTHORIZE_WHOLESALE_LABEL, string.Format("RbrException, from: {0}\r\n{1}", _rbrex.Source, _rbrex.Message)); return(_rbrex.RbrResult); } catch (Exception _ex) { logger.LogRbr(LogSeverity.Critical, AUTHORIZE_WHOLESALE_LABEL, string.Format("Exception:\r\n{0}", _ex)); return(RbrResult.ExceptionThrown); } return(RbrResult.Success); }