static RatingInfoDto getDefaultServiceRatingInfo(Rbr_Db pDb, short pServiceId) { var _defaultWholesaleRouteRow = pDb.WholesaleRouteCollection.GetByPrimaryKey(-pServiceId); var _wholesaleRateHistoryRows = pDb.WholesaleRateHistoryCollection.GetByWholesale_route_id(_defaultWholesaleRouteRow.Wholesale_route_id); if (_wholesaleRateHistoryRows.Length != 1) { throw new Exception("Unexpected: _wholesaleRateHistoryRows.Length = " + _wholesaleRateHistoryRows.Length); } return(RatingManager.GetRatingInfo(pDb, _wholesaleRateHistoryRows[0].Rate_info_id, false)); }
//-------------------- Private ---------------------------------------------- static CarrierAcctDto getAcct(Rbr_Db pDb, CarrierAcctRow pCarrierAcctRow) { if (pCarrierAcctRow == null) { return(null); } var _partner = PartnerManager.Get(pDb, pCarrierAcctRow.Partner_id); if (_partner == null) { return(null); } var _callingPlan = CallingPlanManager.GetCallingPlan(pDb, pCarrierAcctRow.Calling_plan_id); if (_callingPlan == null) { return(null); } var _carrierAcct = mapToCarrierAcct(pCarrierAcctRow, _partner, _callingPlan); _carrierAcct.DefaultRoute = CarrierRouteManager.GetDefaultRoute(pDb, _carrierAcct, RouteState.Valid); //-- GetDefaultCarrierRatingInfo if (_carrierAcct.IsRatingEnabled) { var _defaultCarrierRouteRow = pDb.CarrierRouteCollection.GetByPrimaryKey(-pCarrierAcctRow.Carrier_acct_id); var _carrierRateHistoryRows = pDb.CarrierRateHistoryCollection.GetByCarrier_route_id(_defaultCarrierRouteRow.Carrier_route_id); if (_carrierRateHistoryRows.Length < 1) { TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CarrierAcctManager.GetDefaultCarrierRatingInfo", string.Format("Unexpected: _carrierRateHistoryRows.Length = {0}", _carrierRateHistoryRows.Length)); throw new Exception(string.Format("CarrierAcctManager.GetDefaultCarrierRatingInfo, Unexpected: _carrierRateHistoryRows.Length = {0}", _carrierRateHistoryRows.Length)); } _carrierAcct.DefaultRatingInfo = RatingManager.GetRatingInfo(pDb, _carrierRateHistoryRows[0].Rate_info_id, false); } return(_carrierAcct); }
//------------------------------------- Private ---------------------------------------------- void exportWholesaleRates() { try { countries = new SortedList <string, CountryRecord>(); using (var _db = new Rbr_Db()) { ServiceDto _service = getService(_db); RouteRow[] _baseRouteRows = _db.RouteCollection.GetByCallingPlanIdRoutingPlanId(_service.CallingPlanId, args.RoutingPlanId); if (_baseRouteRows == null || _baseRouteRows.Length <= 0) { reportStatus(LogSeverity.Status, "DialPlanExporter.exportWholesaleRates", "WARNING: No Routes to Export..."); return; } _baseRouteRows = RoutingManager.SortRouteRows(_baseRouteRows); string _filePath = getFilePath(); using (var _sw = new StreamWriter(_filePath, false)) { _sw.WriteLine(args.PerMinute ? RatesFileHeaderCostPerMinute : RatesFileHeaderCostPerIncrements); int _index = 0; CountryRecord _countryRecord = null; foreach (RouteRow _baseRouteRow in _baseRouteRows) { host.ReportProgress(_index++ *100 / _baseRouteRows.Length); WholesaleRouteRow _wholesaleRouteRow = _db.WholesaleRouteCollection.GetByServiceIdBaseRouteId(_service.ServiceId, _baseRouteRow.Route_id); if (_wholesaleRouteRow == null) { continue; } if (_countryRecord == null || _countryRecord.Name != _baseRouteRow.Name) { _countryRecord = getCountryRecord(_db, _baseRouteRow); } RouteRecord _routeRecord = getRouteRecord(_baseRouteRow, _countryRecord); _countryRecord.Routes.Add(_routeRecord.FullName, _routeRecord); WholesaleRateHistoryRow _wholesaleRateHistoryRow = _db.WholesaleRateHistoryCollection.GetByWholesaleRouteIdDate(_wholesaleRouteRow.Wholesale_route_id, DateTime.Today); if (_wholesaleRateHistoryRow != null) { RatingInfoDto _ratingInfo = RatingManager.GetRatingInfo(_db, _wholesaleRateHistoryRow.Rate_info_id, false); if (_ratingInfo == null) { reportStatus(LogSeverity.Critical, "DialPlanExporter.exportWholesaleRates", string.Format("RatingInfo == null, {0}", _wholesaleRateHistoryRow.Rate_info_id)); continue; } _routeRecord.RatingInfo = _ratingInfo; reportStatus(LogSeverity.Status, "DialPlanExporter.exportWholesaleRates", string.Format("Exporting Rates for Route: {0}", _routeRecord.FullName)); _sw.Write(_routeRecord.GetRatesAsString(args.PerMinute)); } } } } } catch (Exception _ex) { reportStatus(LogSeverity.Critical, "DialPlanExporter.exportWholesaleRates", string.Format("Exception:\r\n{0}", _ex)); throw; } }