Пример #1
0
        //--------------------------- Private -----------------------------------------------
        void importCountry(CountryRecord pCountryRecord)
        {
            reportStatus(LogSeverity.Status, "DialPlanImporter.importCountry", string.Format("Importing Country={0}", pCountryRecord.Name));

            int _indexRoute = 0;

            foreach (var _routeRecord in pCountryRecord.Routes.Values)
            {
                if (_routeRecord.BadRouteLines != null && _routeRecord.BadRouteLines.Length > 0)
                {
                    writeBadLines(_routeRecord);
                    throw new Exception(string.Format("ERROR: Bad input data, Route={0}", _routeRecord.FullName));
                }

                Host.ReportProgress(_indexRoute++ *100 / pCountryRecord.Routes.Values.Count);

                if (args.ImportExportFilter == ImportExportFilter.DialPlan || args.ImportExportFilter == ImportExportFilter.Both)
                {
                    importRouteDialCodes(_routeRecord);
                }
                else if (args.ImportExportFilter == ImportExportFilter.Rates || args.ImportExportFilter == ImportExportFilter.Both)
                {
                    importRouteRates(_routeRecord);
                }
                else
                {
                    throw new Exception(string.Format("ERROR: Bad ImportExport Filter={0}", args.ImportExportFilter));
                }
            }
        }
Пример #2
0
        protected CountryRecord getCountryRecord(Rbr_Db pDb, RouteRow pBaseRouteRow)
        {
            CountryRow _countryRow = pDb.CountryCollection.GetByPrimaryKey(pBaseRouteRow.Country_id);

            if (_countryRow == null)
            {
                throw new Exception(string.Format("Country NOT FOUND CountryId: {0}", pBaseRouteRow.Country_id));
            }

            CountryRecord _countryRecord;

            if (countries.ContainsKey(_countryRow.Name))
            {
                _countryRecord = countries[_countryRow.Name];
            }
            else
            {
                _countryRecord = new CountryRecord(_countryRow.Country_code, _countryRow.Name);
                countries.Add(_countryRecord.Name, _countryRecord);
            }

            if (_countryRecord.Routes.ContainsKey(pBaseRouteRow.Name))
            {
                throw new Exception(string.Format("Unexpected: Route already processed? {0}", pBaseRouteRow.Name));
            }
            return(_countryRecord);
        }
Пример #3
0
        protected RouteRecord getRouteRecord(RouteRow _baseRouteRow, CountryRecord _countryRecord)
        {
            var _routeRecord = new RouteRecord(_baseRouteRow.Name);

            _routeRecord.CountryName = _countryRecord.Name;
            _routeRecord.CountryCode = _countryRecord.Code;
            return(_routeRecord);
        }
Пример #4
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;
            }
        }
Пример #5
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);
                    }
                }
            }
        }
Пример #6
0
        /*
         * 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
         *
         * or Rates
         *
         * //TODO: TO BE REMOVED old format
         * Brazil|55|55_ROC_LOC|R|30/6|0am|0.1320000,0.0264000
         * Brazil|55|55_ROC_LOC|W|30/6|0am,2pm|0.1110000,0.1164000|0.2220000,0.2264000
         * Brazil|55|55_ROC_LOC|H|30/6|0am,2pm,10pm|0.1110000,0.1164000|0.2220000,0.2264000|0.3330000,0.3364000
         * Mexico|52|Acapulco|R|30/6|0am|0.1320000,0.0264000
         * Mexico|52|Cancun|R|30/6|0am,2pm|0.1110000,0.1164000|0.2220000,0.2264000
         * Mexico|52|Cancun|H|30/6|0am,2pm,10pm|0.1110000,0.1164000|0.2220000,0.2264000|0.3330000,0.3364000
         * Mexico|52|Mexico City|R|30/6|0am,2pm|0.1110000,0.1164000
         * Mexico|52|Mexico City|W|60/6|0am,2pm,10pm|0.1110000,0.1164000|0.2220000,0.2264000|0.3330000,0.3364000
         * //TODO: END TO BE REMOVED
         *
         *
         * //NOTE: LATEST Rates Export/Import FORMAT
         * Brazil|55|ROC_CEL|Regular|Blocked|0am-1am
         * Brazil|55|ROC_CEL|Regular|Night|11pm-11pm|30/6|0.1110000|0.1164000
         * Brazil|55|ROC_CEL|Regular|Day|2pm-9pm|1/1|0.2220000|0.2264000
         * Brazil|55|ROC_CEL|Regular|Eve|10pm-10pm|60/60|0.3330000|0.3364000
         *
         * Brazil|55|ROC_CEL|Weekend|Blocked|0am-1am
         * Brazil|55|ROC_CEL|Weekend|Peak|8am-8pm|30/6|0.1110000|0.1164000
         * Brazil|55|ROC_CEL|Weekend|OffPeak|2am-7am,9pm-11pm|1/1|0.2220000|0.2264000
         *
         *
         * Brazil|55|ROC_CEL|Holiday|Blocked|0am-1am
         * Brazil|55|ROC_CEL|Holiday|Flat|2am-11pm|30/6|0.1110000|0.1164000
         */

        public IList <CountryRecord> Process(ImportExportFilter pImportExportFilter, string pFilePath)
        {
            var _countries  = new SortedList <string, CountryRecord>();
            int _lineNumber = 0;

            Host.ReportStatus(string.Format("Started File Parsing Process... File: {0}", pFilePath));
            Host.ReportProgress(0);

            try {
                int _totalLineCount;
                countLines(pFilePath, out _totalLineCount);

                using (var _sr = new StreamReader(pFilePath)) {
                    var    _countryLines = new List <string>();
                    string _line;
                    string _previousCountryName = null;
                    while ((_line = _sr.ReadLine()) != null)
                    {
                        Host.ReportProgress(_lineNumber++ *100 / _totalLineCount);

                        if (_line.StartsWith("Country"))
                        {
                            //Rates file header
                            continue;
                        }
                        if (!char.IsLetter(_line[0]) && !char.IsNumber(_line[0]))
                        {
                            throw new Exception(string.Format("Invalid File format. \r\nLine#: {0} \r\nLine: {1}", _lineNumber, _line));
                        }

                        if (Host.CancellationPending)
                        {
                            throw new Exception("File parsing canceled");
                        }

                        if (char.IsLetter(_line[0]))
                        {
                            string _currentCountryName = _line.Split(AppConstants.ImportExport_FieldDelimiter)[0];
                            if (_currentCountryName != _previousCountryName)
                            {
                                if (_previousCountryName != null)
                                {
                                    var _countryRecord = new CountryRecord(pImportExportFilter, _countryLines.ToArray());
                                    _countries.Add(_countryRecord.Name, _countryRecord);

                                    _countryLines = new List <string>();
                                }
                                _previousCountryName = _currentCountryName;
                            }
                        }
                        _countryLines.Add(_line);                         //collect country's route line
                    }

                    //-- collect last country
                    if (_countryLines.Count > 0)
                    {
                        var _countryRecord = new CountryRecord(pImportExportFilter, _countryLines.ToArray());
                        _countries.Add(_countryRecord.Name, _countryRecord);
                    }
                }
            }
            catch (Exception _ex) {
                TimokLogger.Instance.LogRbr(LogSeverity.Critical, "DialPlanFileParser.Process", string.Format("Failed parsing the file\r\n{0}", _ex));
                throw;
            }
            return(_countries.Values);
        }