static WholesaleRouteRow mapToWholesaleRouteRow(RatedRouteDto pRoute)
        {
            if (pRoute == null)
            {
                return(null);
            }

            var _wholesaleRouteRow = new WholesaleRouteRow();

            _wholesaleRouteRow.Wholesale_route_id = pRoute.RatedRouteId;
            //TODO: should we add ServiceId to Route
            _wholesaleRouteRow.Service_id  = pRoute.AccountId;
            _wholesaleRouteRow.RouteStatus = pRoute.Status;

            if (pRoute.BaseRouteId == 0)
            {
                _wholesaleRouteRow.IsRoute_idNull = true;
            }
            else
            {
                _wholesaleRouteRow.Route_id = pRoute.BaseRouteId;
            }

            return(_wholesaleRouteRow);
        }
        //-------------------------------------------- Private -----------------------------------
        CustomerRoute getCustomerRoute(short pServiceId, int pBaseRouteId)
        {
            CustomerRoute _customerRoute = null;

            using (Rbr_Db _db = new Rbr_Db()) {
                RouteRow _routeRow = _db.RouteCollection.GetByPrimaryKey(pBaseRouteId);
                if (_routeRow != null)
                {
                    WholesaleRouteRow _wholesaleRouteRow = _db.WholesaleRouteCollection.GetByServiceIdBaseRouteId(pServiceId, pBaseRouteId);
                    if (_wholesaleRouteRow != null)
                    {
                        _customerRoute = new CustomerRoute(_wholesaleRouteRow, _routeRow);
                    }
                    else
                    {
                        T.LogRbr(LogSeverity.Error, "CustomerRouteImdbRepository.getCustomerRoute", string.Format("ServiceRouteRow NOT FOUND: {0}, {1}", pServiceId, pBaseRouteId));
                    }
                }
                else
                {
                    T.LogRbr(LogSeverity.Error, "CustomerRouteImdbRepository.getCustomerRoute", string.Format("CustomerRouteRow NOT FOUND: {0}, {1}", pServiceId, pBaseRouteId));
                }
            }
            return(_customerRoute);
        }
        /// <summary>
        /// Converts <see cref="System.Data.DataRow"/> to <see cref="WholesaleRouteRow"/>.
        /// </summary>
        /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param>
        /// <returns>A reference to the <see cref="WholesaleRouteRow"/> object.</returns>
        protected virtual WholesaleRouteRow MapRow(DataRow row)
        {
            WholesaleRouteRow mappedObject = new WholesaleRouteRow();
            DataTable         dataTable    = row.Table;
            DataColumn        dataColumn;

            // Column "Wholesale_route_id"
            dataColumn = dataTable.Columns["Wholesale_route_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Wholesale_route_id = (int)row[dataColumn];
            }
            // Column "Service_id"
            dataColumn = dataTable.Columns["Service_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Service_id = (short)row[dataColumn];
            }
            // Column "Route_id"
            dataColumn = dataTable.Columns["Route_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Route_id = (int)row[dataColumn];
            }
            // Column "Status"
            dataColumn = dataTable.Columns["Status"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Status = (byte)row[dataColumn];
            }
            return(mappedObject);
        }
        internal static void Add(Rbr_Db pDb, short pServiceId, int pBaseRouteId, out int pRouteId)
        {
            pRouteId = 0;

            if (pBaseRouteId == 0)
            {
                throw new ArgumentException("BaseRouteId cannot be 0.", "pBaseRouteId");
            }

            var _service           = ServiceManager.GetService(pDb, pServiceId);
            var _wholesaleRouteRow = new WholesaleRouteRow();

            _wholesaleRouteRow.Service_id  = _service.ServiceId;
            _wholesaleRouteRow.Route_id    = pBaseRouteId;
            _wholesaleRouteRow.RouteStatus = Status.Active;

            pDb.WholesaleRouteCollection.Insert(_wholesaleRouteRow);

            if (_service.IsRatingEnabled)
            {
                RatingManager.AddDefaultRatingInfo(pDb, _wholesaleRouteRow.Wholesale_route_id, _service.DefaultRatingInfo, RouteType.Wholesale);
            }

            pRouteId = _wholesaleRouteRow.Wholesale_route_id;
        }
Example #5
0
        CustomerRoute(WholesaleRouteRow pWholesaleRouteRow, int pRoutingPlanId, RouteRow pRouteRow) : base(pRouteRow)
        {
            wholesaleRouteRow = pWholesaleRouteRow;
            routingPlanId     = pRoutingPlanId;
            baseRouteId       = pRouteRow.Route_id;

            using (var _db = new Rbr_Db()) {
                var _serviceRow = _db.ServiceCollection.GetByPrimaryKey(wholesaleRouteRow.Service_id);
                if (_serviceRow == null)
                {
                    throw new Exception(string.Format("CustomerRoute.Ctor | ServiceRow NOT FOUND, Service_id:{0}", wholesaleRouteRow.Service_id));
                }
                ratingType = _serviceRow.RatingType;
            }
        }
        /// <summary>
        /// Reads data from the provided data reader and returns
        /// an array of mapped objects.
        /// </summary>
        /// <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the table.</param>
        /// <param name="startIndex">The index of the first record to map.</param>
        /// <param name="length">The number of records to map.</param>
        /// <param name="totalRecordCount">A reference parameter that returns the total number
        /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param>
        /// <returns>An array of <see cref="WholesaleRouteRow"/> objects.</returns>
        protected virtual WholesaleRouteRow[] MapRecords(IDataReader reader,
                                                         int startIndex, int length, ref int totalRecordCount)
        {
            if (0 > startIndex)
            {
                throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero.");
            }
            if (0 > length)
            {
                throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero.");
            }

            int wholesale_route_idColumnIndex = reader.GetOrdinal("wholesale_route_id");
            int service_idColumnIndex         = reader.GetOrdinal("service_id");
            int route_idColumnIndex           = reader.GetOrdinal("route_id");
            int statusColumnIndex             = reader.GetOrdinal("status");

            System.Collections.ArrayList recordList = new System.Collections.ArrayList();
            int ri = -startIndex;

            while (reader.Read())
            {
                ri++;
                if (ri > 0 && ri <= length)
                {
                    WholesaleRouteRow record = new WholesaleRouteRow();
                    recordList.Add(record);

                    record.Wholesale_route_id = Convert.ToInt32(reader.GetValue(wholesale_route_idColumnIndex));
                    record.Service_id         = Convert.ToInt16(reader.GetValue(service_idColumnIndex));
                    if (!reader.IsDBNull(route_idColumnIndex))
                    {
                        record.Route_id = Convert.ToInt32(reader.GetValue(route_idColumnIndex));
                    }
                    record.Status = Convert.ToByte(reader.GetValue(statusColumnIndex));

                    if (ri == length && 0 != totalRecordCount)
                    {
                        break;
                    }
                }
            }

            totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
            return((WholesaleRouteRow[])(recordList.ToArray(typeof(WholesaleRouteRow))));
        }
        /// <summary>
        /// Updates a record in the <c>WholesaleRoute</c> table.
        /// </summary>
        /// <param name="value">The <see cref="WholesaleRouteRow"/>
        /// object used to update the table record.</param>
        /// <returns>true if the record was updated; otherwise, false.</returns>
        public virtual bool Update(WholesaleRouteRow value)
        {
            string sqlStr = "UPDATE [dbo].[WholesaleRoute] SET " +
                            "[service_id]=" + _db.CreateSqlParameterName("Service_id") + ", " +
                            "[route_id]=" + _db.CreateSqlParameterName("Route_id") + ", " +
                            "[status]=" + _db.CreateSqlParameterName("Status") +
                            " WHERE " +
                            "[wholesale_route_id]=" + _db.CreateSqlParameterName("Wholesale_route_id");
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "Service_id", value.Service_id);
            AddParameter(cmd, "Route_id",
                         value.IsRoute_idNull ? DBNull.Value : (object)value.Route_id);
            AddParameter(cmd, "Status", value.Status);
            AddParameter(cmd, "Wholesale_route_id", value.Wholesale_route_id);
            return(0 != cmd.ExecuteNonQuery());
        }
        internal static void AddDefault(Rbr_Db pDb, ServiceDto pService, out int pDefaultWholesaleRouteId)
        {
            var _wholesaleRouteRow = new WholesaleRouteRow();

            _wholesaleRouteRow.Service_id = pService.ServiceId;

            //DefaultWholesaleRoute, set WholesaleRouteId = -ServiceId, NO Base RouteId
            pService.DefaultRoute.RatedRouteId    = -pService.ServiceId;
            _wholesaleRouteRow.IsRoute_idNull     = true;
            _wholesaleRouteRow.Wholesale_route_id = pService.DefaultRoute.RatedRouteId;
            _wholesaleRouteRow.RouteStatus        = Status.Blocked;      //for Default WholesaleServiceRoute

            pDb.WholesaleRouteCollection.Insert(_wholesaleRouteRow);

            //always add Def RatingInfo for Def WholesaleRoute
            RatingManager.AddDefaultRatingInfo(pDb, _wholesaleRouteRow.Wholesale_route_id, pService.DefaultRatingInfo, RouteType.Wholesale);

            pDefaultWholesaleRouteId = _wholesaleRouteRow.Wholesale_route_id;
        }
        /// <summary>
        /// Adds a new record into the <c>WholesaleRoute</c> table.
        /// </summary>
        /// <param name="value">The <see cref="WholesaleRouteRow"/> object to be inserted.</param>
        public virtual void Insert(WholesaleRouteRow value)
        {
            string sqlStr = "INSERT INTO [dbo].[WholesaleRoute] (" +
                            "[wholesale_route_id], " +
                            "[service_id], " +
                            "[route_id], " +
                            "[status]" +
                            ") VALUES (" +
                            _db.CreateSqlParameterName("Wholesale_route_id") + ", " +
                            _db.CreateSqlParameterName("Service_id") + ", " +
                            _db.CreateSqlParameterName("Route_id") + ", " +
                            _db.CreateSqlParameterName("Status") + ")";
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "Wholesale_route_id", value.Wholesale_route_id);
            AddParameter(cmd, "Service_id", value.Service_id);
            AddParameter(cmd, "Route_id",
                         value.IsRoute_idNull ? DBNull.Value : (object)value.Route_id);
            AddParameter(cmd, "Status", value.Status);
            cmd.ExecuteNonQuery();
        }
        static RatedRouteDto mapToRoute(WholesaleRouteRow pWholesaleRouteRow, int pRoutingPlanId, RoutingAlgorithmType pRoutingAlgorithmType, ServiceDto pService, BaseRouteDto pBaseRoute, RouteState pRouteState)
        {
            if (pWholesaleRouteRow == null)
            {
                return(null);
            }

            var _route = new RatedRouteDto
            {
                RatedRouteId      = pWholesaleRouteRow.Wholesale_route_id,
                AccountId         = pService.ServiceId,
                AccountName       = pService.Name,
                AccountStatus     = pService.Status,
                RoutingPlanId     = pRoutingPlanId,
                Algorithm         = pRoutingAlgorithmType,
                Status            = pWholesaleRouteRow.RouteStatus,
                BaseRoute         = pBaseRoute,
                RouteState        = pRouteState,
                DefaultRatingInfo = pService.DefaultRatingInfo
            };

            return(_route);
        }
Example #11
0
        //------------------------------------- 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;
            }
        }
 /// <summary>
 /// Deletes the specified object from the <c>WholesaleRoute</c> table.
 /// </summary>
 /// <param name="value">The <see cref="WholesaleRouteRow"/> object to delete.</param>
 /// <returns>true if the record was deleted; otherwise, false.</returns>
 public bool Delete(WholesaleRouteRow value)
 {
     return(DeleteByPrimaryKey(value.Wholesale_route_id));
 }
        public static RatedRouteDto Get(Rbr_Db pDb, ServiceDto pService, int pRoutingPlanId, WholesaleRouteRow pWholesaleRouteRow)
        {
            try {
                if (pWholesaleRouteRow == null)
                {
                    return(null);
                }
                var _routingPlanDetailRow = pDb.RoutingPlanDetailCollection.GetByPrimaryKey(pRoutingPlanId, pWholesaleRouteRow.Route_id);
                var _routingPlanId        = 0;
                var _routingAlgorithmType = RoutingAlgorithmType.Unknown;
                if (_routingPlanDetailRow != null)
                {
                    _routingPlanId        = _routingPlanDetailRow.Routing_plan_id;
                    _routingAlgorithmType = _routingPlanDetailRow.Algorithm;
                }
                var _routeState = (_routingPlanDetailRow != null) ? RouteState.Valid : RouteState.NotInRoutingPlan;

                if (pService.IsRatingEnabled)
                {
                    //get Rates status
                    bool _allRatesValid;
                    var  _wholesaleRateHistoryRow = pDb.WholesaleRateHistoryCollection.GetByWholesaleRouteIdDate(pWholesaleRouteRow.Wholesale_route_id, DateTime.Today);
                    if (_wholesaleRateHistoryRow == null)
                    {
                        _allRatesValid = false;
                    }
                    else
                    {
                        _allRatesValid = pDb.RateCollection.HasAllValidRates(_wholesaleRateHistoryRow.Rate_info_id);
                    }
                    _routeState = (_allRatesValid) ? _routeState | RouteState.Valid : _routeState | RouteState.NoRates;
                }
                var _baseRoute = RoutingManager.GetBaseRoute(pDb, pWholesaleRouteRow.Route_id);
                return(mapToRoute(pWholesaleRouteRow, _routingPlanId, _routingAlgorithmType, pService, _baseRoute, _routeState));
            }
            catch (Exception _ex) {
                var _exc = _ex;
            }
            return(null);
        }