Beispiel #1
0
        protected RouteRecord getRouteRecord(RouteRow _baseRouteRow, CountryRecord _countryRecord)
        {
            var _routeRecord = new RouteRecord(_baseRouteRow.Name);

            _routeRecord.CountryName = _countryRecord.Name;
            _routeRecord.CountryCode = _countryRecord.Code;
            return(_routeRecord);
        }
        void importRouteDialCodes(RouteRecord pRouteRecord)
        {
            Host.ReportStatus(string.Format("Importing Dial Codes for Route: {0}", pRouteRecord.FullName));

            using (var _db = new Rbr_Db()) {
                _db.BeginTransaction();
                try {
                    int _countryId = getCountryId(_db, pRouteRecord.CountryName, pRouteRecord.CountryCode);
                    int _routeId   = getRouteId(_db, _countryId, pRouteRecord);

                    int _indexDialCode = 0;
                    foreach (long _dialCode in pRouteRecord.DialCodes.Values)
                    {
                        if (Host.CancellationPending)
                        {
                            throw new Exception("Import canceled");
                        }

                        if (!_dialCode.ToString().StartsWith(pRouteRecord.CountryCode.ToString()))
                        {
                            throw new Exception(string.Format("Invalid Dial Code={0}, CCode={1}", _dialCode, pRouteRecord.CountryCode));
                        }

                        var _dialCodeDto = new DialCodeDto();
                        _dialCodeDto.Code          = _dialCode;
                        _dialCodeDto.BaseRouteId   = _routeId;
                        _dialCodeDto.CallingPlanId = args.CallingPlanId;
                        _dialCodeDto.Version       = 0;
                        try {
                            CallingPlanManager.AddDialCode(_db, _dialCodeDto);
                        }
                        catch (Exception _ex) {
                            TimokLogger.Instance.LogRbr(LogSeverity.Debug, "", string.Format("Error inserting dial code: {0}\r\n{1}", _dialCodeDto.Code, _ex));
                        }

                        if (++_indexDialCode % 10 == 0)
                        {
                            Host.ReportProgress(_indexDialCode * 100 / pRouteRecord.DialCodes.Values.Count);
                        }
                    }

                    Host.ReportStatus(string.Format("Imported total of {0} Dial Codes for Route: {1}", pRouteRecord.DialCodes.Values.Count, pRouteRecord.FullName));
                    _db.CommitTransaction();
                }
                catch (Exception _ex) {
                    _db.RollbackTransaction();
                    reportStatus(LogSeverity.Error, "DialPlanImporter.importRouteDialCodes", _ex.Message);
                    throw;
                }
            }
        }
Beispiel #3
0
        protected void writeBadLines(RouteRecord _routeRecord)
        {
            if (File.Exists(errorFilePath))
            {
                File.Delete(errorFilePath);
            }

            using (var _sw = new StreamWriter(errorFilePath, false)) {
                _sw.WriteLine(args.PerMinute ? RatesFileHeaderCostPerMinute : RatesFileHeaderCostPerIncrements);                 //write header for Bad Rates File [only]
                foreach (string _routeLine in _routeRecord.BadRouteLines)
                {
                    _sw.WriteLine(_routeLine);
                }
            }
        }
Beispiel #4
0
        //-------------------------- Private --------------------------------------------

        /*
         * DialCodes
         * Brazil|55|ROC_CEL
         * 551281234512|551281234512|551281234512|551281234512|551281234512|551281234512
         * 551281234512|551281234512
         * Brazil|55|ROC_LOCAL
         * 551281234512|551281234512|551281234512|551281234512|551281234512|551281234512
         * 551281234512|551281234512|551281234512|551281234512|551281234512|551281234512
         * 551281234512|551281234512
         * Mexico|52|Acapoulco
         * 551281234512|551281234512|551281234512|551281234512|551281234512|551281234512
         * 551281234512|551281234512|551281234512|551281234512|551281234512|551281234512
         */

        void parse(ImportExportFilter pImportExportFilter, string[] pRouteLines, List <string> pDialCodes)
        {
            string      _breakoutName = pRouteLines[0].Split(AppConstants.ImportExport_FieldDelimiter)[2];
            RouteRecord _routeRecord  = null;

            if (pImportExportFilter == ImportExportFilter.DialPlan)
            {
                _routeRecord = new RouteRecord(Code, Name, _breakoutName, pDialCodes.ToArray(), null);
            }
            else if (pImportExportFilter == ImportExportFilter.Rates)
            {
                _routeRecord = new RouteRecord(Code, Name, _breakoutName, null, pRouteLines);
            }
            if (_routeRecord != null)
            {
                Routes.Add(_routeRecord.FullName, _routeRecord);
            }
        }
Beispiel #5
0
        protected int getRouteId(Rbr_Db pDb, int pCountryId, RouteRecord pRouteRecord)
        {
            RouteRow _routeRow = RoutingManager.GetByName(pDb, args.CallingPlanId, pRouteRecord.FullName);

            if (_routeRow == null)
            {
                _routeRow                 = new RouteRow();
                _routeRow.Name            = pRouteRecord.FullName;
                _routeRow.Country_id      = pCountryId;
                _routeRow.Calling_plan_id = args.CallingPlanId;
                _routeRow.RouteStatus     = Status.Active;
                RoutingManager.AddBaseRoute(pDb, RoutingManager.MapToBaseRoute(pDb, _routeRow));
            }
            else
            {
                // Existing RouteRow: delete all dialcodes
                pDb.DialCodeCollection.DeleteByRoute_id(_routeRow.Route_id);
            }
            return(_routeRow.Route_id);
        }
        void importRouteRates(RouteRecord pRouteRecord)          //}, int pCallingPlanId, short pId, RouteType pRouteType, int pRoutingPlanId) {
        {
            if (pRouteRecord.RatingInfo == null)
            {
                throw new Exception(string.Format("ERROR: No Rating Info found for Route={0}", pRouteRecord.FullName));
            }

            reportStatus(LogSeverity.Status, "DialPlanImporter.importRouteRates", string.Format("Importing Route={0}", pRouteRecord.FullName));
            using (var _db = new Rbr_Db()) {
                _db.BeginTransaction();

                try {
                    //-- get base RouteRow
                    var _routeRow = RoutingManager.GetByName(_db, args.CallingPlanId, pRouteRecord.FullName);
                    if (_routeRow == null)
                    {
                        reportStatus(LogSeverity.Status, "DialPlanImporter.importRouteRates", string.Format("SKIPPING: Route={0},  doesn't exists in CallingPlan={1}.", pRouteRecord.FullName, args.CallingPlanId));
                        return;
                    }

                    var _routeType   = getRouteType();
                    int _rateRouteId = getBaseRouteId(_db, _routeType, args.AccountId, args.RoutingPlanId, _routeRow.Route_id);
                    //-- Expects that imported file has records for Routes whose rates are changing only.
                    //-- If the rate import record for existing Route is missing; Route is skipped
                    //-- If the route record is not found we create a new record and add rates to it
                    //-- Add/Update ratingHistory: default time period today, maxTime used
                    var _ratingHistoryEntry = new RatingHistoryEntry(_routeType, _rateRouteId, args.From, args.To, pRouteRecord.RatingInfo);
                    RatingManager.SaveRatingHistoryEntry(_db, _ratingHistoryEntry);
                    _db.CommitTransaction();
                }
                catch (Exception _ex) {
                    _db.RollbackTransaction();
                    reportStatus(LogSeverity.Error, "DialPlanImporter.importRouteRates", _ex.Message);
                    throw;
                }
            }
        }
Beispiel #7
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;
            }
        }
Beispiel #8
0
        void exportDialPlan()
        {
            countries = new SortedList <string, CountryRecord>();

            using (var _db = new Rbr_Db()) {
                RouteRow[] _baseRouteRows = getBaseRouteRows(_db);
                if (_baseRouteRows == null || _baseRouteRows.Length <= 0)
                {
                    reportStatus(LogSeverity.Status, "DialPlanExporter.exportDialPlan", "No Routes to Process...");
                    return;
                }

                _baseRouteRows = RoutingManager.SortRouteRows(_baseRouteRows);

                string _filePath = getFilePath();

                using (var _swDialPlan = new StreamWriter(_filePath, false)) {
                    int           _index         = 0;
                    CountryRecord _countryRecord = null;
                    foreach (RouteRow _baseRouteRow in _baseRouteRows)
                    {
                        host.ReportProgress(_index++ *100 / _baseRouteRows.Length);

                        if (args.RoutingPlanId > 0)
                        {
                            RoutingPlanDetailRow _routingPlanDetailRow = _db.RoutingPlanDetailCollection.GetByPrimaryKey(args.RoutingPlanId, _baseRouteRow.Route_id);
                            if (_routingPlanDetailRow == null)
                            {
                                continue;                                 //NOTE: skip this route
                            }
                        }

                        if (_countryRecord == null || _countryRecord.Name != _baseRouteRow.Name)
                        {
                            _countryRecord = getCountryRecord(_db, _baseRouteRow);
                        }

                        if (_countryRecord.Routes.ContainsKey(_baseRouteRow.Name))
                        {
                            throw new Exception(string.Format("Unexpected: Route already processed? {0}", _baseRouteRow.Name));
                        }

                        RouteRecord _routeRecord = getRouteRecord(_baseRouteRow, _countryRecord);
                        _countryRecord.Routes.Add(_routeRecord.FullName, _routeRecord);

                        reportStatus(LogSeverity.Status, "DialPlanExporter.exportDialPlanToFile", string.Format("Exporting DialCodes for Route: {0}", _routeRecord.FullName));

                        DialCodeRow[] _dialCodeRows = _db.DialCodeCollection.GetByRoute_id(_baseRouteRow.Route_id);
                        if (_dialCodeRows != null && _dialCodeRows.Length > 0)
                        {
                            var _dialCodesAsStringArray = new string[_dialCodeRows.Length];
                            for (int _i = 0; _i < _dialCodeRows.Length; _i++)
                            {
                                _dialCodesAsStringArray[_i] = _dialCodeRows[_i].Dial_code.ToString();
                            }
                            _routeRecord.AddDialCodes(_dialCodesAsStringArray);
                        }
                        _swDialPlan.Write(_routeRecord.DialCodesAsString);
                    }
                }
            }
        }