コード例 #1
0
        public static EndpointASR[] GetTermEndpointsASR(int pTimokDate)
        {
            DataTable _dt;

            using (var _db = new Cdr_Db(TimokDate.ToDateTime(pTimokDate))) {
                _dt = _db.CDRCollection.GetTermEpAsr(pTimokDate);
            }
            var _list = new ArrayList();

            if (_dt != null && _dt.Rows.Count > 0)
            {
                using (var _db = new Rbr_Db()) {
                    foreach (DataRow _dataRow in _dt.Rows)
                    {
                        var _endpointAsr = new EndpointASR
                        {
                            EndpointId     = ((short)_dataRow[EndpointAsrDataTable.Id_ColumnName]),
                            Calls          = ((int)_dataRow[EndpointAsrDataTable.Calls_ColumnName]),
                            ConnectedCalls = ((int)_dataRow[EndpointAsrDataTable.Connected_calls_ColumnName]),
                            Asr            = ((int)_dataRow[EndpointAsrDataTable.Asr_ColumnName])
                        };
                        if (_endpointAsr.EndpointId > 0)
                        {
                            var _endPointRow = _db.EndPointCollection.GetByPrimaryKey(_endpointAsr.EndpointId);
                            _endpointAsr.Alias = _endPointRow.Alias;
                        }
                        _list.Add(_endpointAsr);
                    }
                }
                _list.Sort(new GenericComparer(EndpointASR.Alias_PropName, ListSortDirection.Ascending));
            }
            return((EndpointASR[])_list.ToArray(typeof(EndpointASR)));
        }
コード例 #2
0
        //used by ReportEngine
        public static RouteMinutesSummary[] GetCustomerRouteMinutesSummaries(int pTimokDate)
        {
            DataTable _dt;

            using (var _db = new Cdr_Db(TimokDate.ToDateTime(pTimokDate))) {
                _dt = _db.CDRCollection.GetCustomerRoutesTotalMinutes(pTimokDate);
            }
            var _list = new ArrayList();

            if (_dt != null && _dt.Rows.Count > 0)
            {
                using (var _db = new Rbr_Db()) {
                    foreach (DataRow _dataRow in _dt.Rows)
                    {
                        var _routeMinutesSummary = new RouteMinutesSummary
                        {
                            Id      = ((int)_dataRow[CustomerRoutesTotalMinutesDataTable.Id_ColumnName]),
                            Minutes = ((decimal)_dataRow[CustomerRoutesTotalMinutesDataTable.Minutes_ColumnName])
                        };
                        if (_routeMinutesSummary.Id > 0)
                        {
                            var _routeRow = _db.RouteCollection.GetByPrimaryKey(_routeMinutesSummary.Id);
                            _routeMinutesSummary.Name = _routeRow.Name;
                        }
                        _list.Add(_routeMinutesSummary);
                    }
                }
                _list.Sort(new GenericComparer(RouteMinutesSummary.Name_PropName, ListSortDirection.Ascending));
            }
            return((RouteMinutesSummary[])_list.ToArray(typeof(RouteMinutesSummary)));
        }
コード例 #3
0
 public Cdr(string pCallId, string pOrigIP, string pPrefixIn, string pDestNumber, short pCustomerAcctId, int pCustomerRouteId)
 {
     cdrRow                         = new CDRRow();
     cdrRow.Id                      = pCallId;
     cdrRow.Start                   = DateTime.Now;
     cdrRow.Date_logged             = cdrRow.Start;
     cdrRow.Timok_date              = TimokDate.Parse(cdrRow.Start);
     cdrRow.Duration                = 0;
     cdrRow.Customer_duration       = 0;
     cdrRow.Retail_duration         = 0;
     cdrRow.Carrier_duration        = 0;
     cdrRow.Ccode                   = 0;
     cdrRow.Local_number            = pDestNumber;
     cdrRow.Carrier_route_id        = 0;
     cdrRow.Customer_route_id       = pCustomerRouteId;
     cdrRow.Price                   = (decimal)0.0;
     cdrRow.Cost                    = (decimal)0.0;
     cdrRow.Orig_IP_address         = IPUtil.ToInt32(pOrigIP);
     OrigIP                         = IPUtil.ToString(cdrRow.Orig_IP_address);
     cdrRow.Term_end_point_id       = 0;
     cdrRow.Customer_acct_id        = pCustomerAcctId;
     cdrRow.Carrier_acct_id         = 0;
     cdrRow.Disconnect_cause        = 0;
     cdrRow.Mapped_disconnect_cause = 0;
     cdrRow.Rbr_result              = (short)RbrResult.Unknown;
     cdrRow.Prefix_in               = pPrefixIn;
     cdrRow.Prefix_out              = string.Empty;
     cdrRow.DNIS                    = 0;
     cdrRow.ANI                     = 0;
     cdrRow.Serial_number           = 0;
     cdrRow.Used_bonus_minutes      = 0;
     cdrRow.Node_id                 = 0;
 }
コード例 #4
0
        public DataTable GetCustomerRoutesTotalMinutes(int pStartTimokDate, int pEndTimokDate)
        {
            if (TimokDate.IsShortTimokDate(pStartTimokDate))
            {
                pStartTimokDate = pStartTimokDate * 100;                //add 00 hour
            }
            if (TimokDate.IsShortTimokDate(pEndTimokDate))
            {
                pEndTimokDate = pEndTimokDate * 100 + 23;                //add 23rd hour
            }

            string sqlStr = "SELECT " + CDRRow.customer_route_id_DbName + " AS " + CustomerRoutesTotalMinutesDataTable.Id_ColumnName +
                            ", SUM(" +
                            "CAST(" + CDRRow.duration_DbName + " / 6 + (CASE WHEN " + CDRRow.duration_DbName + " % 6 > 0 THEN 1 ELSE 0 END) AS decimal(9, 1)) / 10 " +
                            //CDRRow.minutes_DbName +
                            ") AS " + CustomerRoutesTotalMinutesDataTable.Minutes_ColumnName + " " +
                            "FROM CDR " +
                            "WHERE (" + CDRRow.timok_date_DbName + " BETWEEN " +
                            base.Database.CreateSqlParameterName("Start_timok_date") +
                            " AND " + base.Database.CreateSqlParameterName("End_timok_date") +
                            ") GROUP BY " + CDRRow.customer_route_id_DbName;

            IDbCommand cmd = base.Database.CreateCommand(sqlStr);

            base.Database.AddParameter(cmd, "Start_timok_date", DbType.Int32, pStartTimokDate);
            base.Database.AddParameter(cmd, "End_timok_date", DbType.Int32, pEndTimokDate);

            cmd.CommandTimeout = 600;

            using (IDataReader reader = cmd.ExecuteReader()) {
                return(MapRecordsToDataTable(reader, CustomerRoutesTotalMinutesDataTable.CreateNew()));
            }
        }
コード例 #5
0
        static void export(string pWhereFilter, ICdrExportInfo pCdrExportInfo, string pFilePath, BackgroundWorker pBackgroundWorker)
        {
            pBackgroundWorker.ReportStatus("CDR Export started...");
            pBackgroundWorker.ReportProgress(0);
            DateTime _processDate = pCdrExportInfo.DateStart;

            if (File.Exists(pFilePath))
            {
                File.Delete(pFilePath);
            }
            string _tempFilePath = pFilePath + ".temp";

            if (File.Exists(_tempFilePath))
            {
                File.Delete(_tempFilePath);
            }

            try {
                int _totalRecords = 0;

                while (_processDate <= pCdrExportInfo.DateEnd)
                {
                    if (pBackgroundWorker.CancellationPending)
                    {
                        throw new Exception("CDR Export canceled");
                    }

                    var _records = new List <string>();
                    for (int _hour = 0; _hour <= 23; _hour++)
                    {
                        int _timokDate = TimokDate.Parse(_processDate, _hour);                         // YYYYJJJ00
                        _records.AddRange(getCDRs(pWhereFilter, pCdrExportInfo, _timokDate, pBackgroundWorker));
                        _totalRecords += _records.Count;
                    }

                    using (var _sw = new StreamWriter(_tempFilePath, true)) {
                        foreach (string _record in _records)
                        {
                            _sw.WriteLine(_record);
                        }
                    }
                    _processDate = _processDate.AddDays(1);
                }

                FileHelper.Rename(_tempFilePath, pFilePath, TimokLogger.Instance.LogRbr);
                pBackgroundWorker.ReportStatus(string.Format("Exported total of {0} CDRs", _totalRecords));
                pBackgroundWorker.ReportProgress(0);
            }
            catch {
                if (File.Exists(_tempFilePath))
                {
                    try {
                        File.Delete(_tempFilePath);
                    }
                    catch {}
                }
                throw;
            }
        }
コード例 #6
0
        ///NOTE: depricated
        //static List<string> getCDRs(string pWhereFilter, CdrExportMap pCdrExportMap, int pStartTimokDate, int pEndTimokDate, string pDecimalFormatString, BackgroundWorker pBackgroundWorker) {
        //  pBackgroundWorker.ReportStatus("Retrieving CDRs...");
        //  List<string> _records = new List<string>();
        //  if (Cdr_Db.Exists(TimokDate.ToDateTime(pStartTimokDate))) {
        //    using (Cdr_Db _db = new Cdr_Db(TimokDate.ToDateTime(pStartTimokDate))) {
        //      IDbCommand _cmd = _db.Connection.CreateCommand();
        //      _cmd.CommandText = getSQLForCDRViewExport(_db.Connection.Database, pCdrExportMap.CdrExportMapDetails, pStartTimokDate, pEndTimokDate, pWhereFilter);
        //      IDataReader _reader = _cmd.ExecuteReader();
        //      while (_reader.Read()) {
        //        if (pBackgroundWorker.CancellationPending) {
        //          throw new Exception("CDR Export canceled");
        //        }
        //        StringBuilder _record = new StringBuilder();
        //        foreach (CdrExportMapDetail _field in pCdrExportMap.CdrExportMapDetails) {
        //          object _value = _reader.GetValue(_field.Sequence - 1);
        //          _record.Append(_value);
        //          //NOTE: if need to format prices, here is the place to do that
        //          //if (_value is Decimal) {
        //          //  _record.Append(((decimal) _value).ToString(pDecimalFormatString));
        //          //}
        //          //else {
        //          //  _record.Append(_value);
        //          //}
        //          _record.Append((char) pCdrExportMap.CdrExportDelimeter);
        //        }
        //        _records.Add(_record.ToString().TrimEnd((char) pCdrExportMap.CdrExportDelimeter));
        //      }
        //    }
        //  }
        //  pBackgroundWorker.ReportStatus(string.Format("Retrieved {0} CDRs", _records.Count));
        //  return _records;
        //}
        static List <string> getCDRs(string pWhereFilter, ICdrExportInfo pCdrExportInfo, int pTimokDate, IBackgroundWorker pBackgroundWorker)
        {
            var _records = new List <string>();

            if (Cdr_Db.Exists(TimokDate.ToDateTime(pTimokDate)))
            {
                CDRViewRow[] _cdrViewRows;
                try {
                    using (var _db = new Cdr_Db(TimokDate.ToDateTime(pTimokDate))) {
                        _cdrViewRows = _db.CDRViewCollection.Get(pTimokDate, pWhereFilter);
                    }
                }
                catch (Exception _ex) {
                    TimokLogger.Instance.LogRbr(LogSeverity.Critical, GetcdrsLabel, string.Format("Exception:\r\n{0}", _ex));
                    pBackgroundWorker.ReportStatus(string.Format("Exception! Exported {0} CDRs", _records.Count));
                    return(_records);
                }
                if (_cdrViewRows == null || _cdrViewRows.Length == 0)
                {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, GetcdrsLabel, "No CDR Records found");
                    pBackgroundWorker.ReportStatus("No CDR Records found");
                    return(_records);
                }

                pBackgroundWorker.ReportStatus(string.Format("Retrieved {0} CDRs for: {1}", _cdrViewRows.Length, TimokDate.ToDateTime(pTimokDate).ToString("yyyy-MM-dd HH:mm")));

                var _recordCount = 0;
                foreach (var _cdrViewRow in _cdrViewRows)
                {
                    if (pBackgroundWorker.CancellationPending)
                    {
                        throw new Exception("CDR Export canceled");
                    }

                    if (pCdrExportInfo.WithRerating && _cdrViewRow.Duration > 0)
                    {
                        if (!rerateCDR(_cdrViewRow, pBackgroundWorker))
                        {
                            continue;
                        }
                    }

                    _records.Add(mapToExportedRecord(_cdrViewRow, pCdrExportInfo.CdrExportMap));
                    pBackgroundWorker.ReportProgress(++_recordCount * 100 / _cdrViewRows.Length);
                }

                if (_records.Count != _cdrViewRows.Length)
                {
                    pBackgroundWorker.ReportStatus(string.Format("ERROR: Exported {0} out of {1} retreived CDRs", _records.Count, _cdrViewRows.Length));
                }
                else
                {
                    pBackgroundWorker.ReportStatus(string.Format("Exported {0} CDRs for: {1}", _records.Count, TimokDate.ToDateTime(pTimokDate).ToString("yyyy-MM-dd HH:mm")));
                }
            }
            return(_records);
        }
コード例 #7
0
        public static List <CdrDto> GetCDRsByCarrierAcctIdEndpointId(int pStartTimokDate, int pEndTimokDate, short pCarrierAcctId, short pEndpointId)
        {
            var _cdrViewRows = new CDRViewRow[0];

            if (Cdr_Db.Exists(TimokDate.ToDateTime(pStartTimokDate)))
            {
                using (var db = new Cdr_Db(TimokDate.ToDateTime(pStartTimokDate))) {
                    _cdrViewRows = db.CDRViewCollection.GetByCarrierAcctIdEndpointId(pStartTimokDate, pEndTimokDate, pCarrierAcctId, pEndpointId);
                }
            }
            return(mapToCDRs(_cdrViewRows));
        }
コード例 #8
0
        public static List <CdrDto> GetRetailAcctCDRs(int pStartTimokDate, int pEndTimokDate, int pRetailAcctId)
        {
            var _cdrViewRows = new CDRViewRow[0];

            if (Cdr_Db.Exists(TimokDate.ToDateTime(pStartTimokDate)))
            {
                using (var db = new Cdr_Db(TimokDate.ToDateTime(pStartTimokDate))) {
                    _cdrViewRows = db.CDRViewCollection.GetByRetailAcctId(pStartTimokDate, pEndTimokDate, pRetailAcctId);
                }
            }
            return(mapToCDRs(_cdrViewRows));
        }
コード例 #9
0
        public static List <CdrDto> GetCDRsByRetailAcctId(int pStartTimokDate, int pEndTimokDate, int pRetailAcctId, int pPageNumber, int pPageSize, out int pTotalCount)
        {
            pTotalCount = 0;
            var _cdrViewRows = new CDRViewRow[0];

            if (Cdr_Db.Exists(TimokDate.ToDateTime(pStartTimokDate)))
            {
                using (var _db = new Cdr_Db(TimokDate.ToDateTime(pStartTimokDate))) {
                    _cdrViewRows = _db.CDRViewCollection.GetByRetailAcctIdPaged(pStartTimokDate, pEndTimokDate, pRetailAcctId, pPageNumber, pPageSize, out pTotalCount);
                }
            }
            return(mapToCDRs(_cdrViewRows));
        }
コード例 #10
0
        public static int GetCDRCountByCustomerAcctId(DateTime pDate, short pCustomerAcctId, int pPageNumber, int pPageSize, out int pTotalCount)
        {
            pTotalCount = 0;
            int _startTimokDate = TimokDate.Parse(pDate, TimokDate.MinHour);
            int _endTimokDate   = TimokDate.Parse(pDate, TimokDate.MaxHour);

            if (Cdr_Db.Exists(pDate))
            {
                using (var _db = new Cdr_Db(pDate)) {
                    return(_db.CDRViewCollection.GetCountByCustomerAcctIdPaged(_startTimokDate, _endTimokDate, pCustomerAcctId));
                }
            }
            return(0);
        }
コード例 #11
0
        public static List <CdrDto> GetCDRsByCustomerAcctId(DateTime pDate, short pCustomerAcctId)
        {
            var _cdrViewRows    = new CDRViewRow[0];
            int _startTimokDate = TimokDate.Parse(pDate, TimokDate.MinHour);
            int _endTimokDate   = TimokDate.Parse(pDate, TimokDate.MaxHour);

            if (Cdr_Db.Exists(pDate))
            {
                using (var _db = new Cdr_Db(pDate)) {
                    _cdrViewRows = _db.CDRViewCollection.GetByCustomer_acct_id(_startTimokDate, _endTimokDate, pCustomerAcctId);
                }
            }
            return(mapToCDRs(_cdrViewRows));
        }
コード例 #12
0
 //Day node_id  route_id carrier_acct_id Total Completed InMinutes OutMinutes Cost Name  PopName
 public RouteReportRecord(int?pDay, string pNode, string pCustomerName, int?pTotal, int?pCompleted, int?pInMinutes, decimal?pOutMinutes, decimal?pCost, string pRouteName, string pCarrierName)
 {
     Date         = TimokDate.ToDateTime((int)pDay).ToShortDateString();
     Node         = pNode;
     CustomerName = pCustomerName;
     Total        = pTotal;
     Completed    = pCompleted;
     InMinutes    = pInMinutes;
     OutMinutes   = pOutMinutes;
     Cost         = pCost;
     RouteName    = pRouteName;
     CarrierName  = pCarrierName;
     Asr          = StatsCalc.GetASR(Total, Completed);
     Acd          = StatsCalc.GetACD(OutMinutes, Completed);
 }
コード例 #13
0
        public static List <CdrDto> GetCDRsByCustomerAcctIdPaged(DateTime pDate, short pCustomerAcctId, int pPageNumber, int pPageSize, out int pTotalCount)
        {
            pTotalCount = 0;
            var _cdrViewRows    = new CDRViewRow[0];
            int _startTimokDate = TimokDate.Parse(pDate, TimokDate.MinHour);
            int _endTimokDate   = TimokDate.Parse(pDate, TimokDate.MaxHour);

            if (Cdr_Db.Exists(pDate))
            {
                using (var _db = new Cdr_Db(pDate)) {
                    _cdrViewRows = _db.CDRViewCollection.GetByCustomerAcctIdPaged(_startTimokDate, _endTimokDate, pCustomerAcctId, pPageNumber, pPageSize, out pTotalCount);
                }
            }
            return(mapToCDRs(_cdrViewRows));
        }
コード例 #14
0
        /// <summary>
        /// GetTermEpASRByTimokDateRange return number of calls completed and
        /// number of total calls for termination TrunkGroups for date range
        /// </summary>
        /// <param name="pStartTimokDate">TimokDate [yyyyjjj] or [yyyyjjjhh]</param>
        /// <param name="pEndTimokDate">TimokDate [yyyyjjj] or [yyyyjjjhh]</param>
        /// <returns></returns>
        public DataTable GetTermEpAsr(int pStartTimokDate, int pEndTimokDate)
        {
            if (TimokDate.IsShortTimokDate(pStartTimokDate))
            {
                pStartTimokDate = pStartTimokDate * 100;                //add 00 hour
            }
            if (TimokDate.IsShortTimokDate(pEndTimokDate))
            {
                pEndTimokDate = pEndTimokDate * 100 + 23;                //add 23rd hour
            }

            string sqlStr = "DECLARE  @T TABLE (term_ep_id smallint, term_ep_calls int, term_ep_connected_calls int) " +
                            //DECLARE @Start_timok_date int, @End_timok_date int
                            //SET @Start_timok_date = 200333000
                            //SET @End_timok_date = 200333023
                            "INSERT @T " +
                            "SELECT CAST(" + CDRRow.term_end_point_id_DbName + " as smallint), CAST(count(*) as int), CAST(0 as int) " +
                            "FROM [CDR] WHERE " + CDRRow.timok_date_DbName + " BETWEEN " +
                            base.Database.CreateSqlParameterName("Start_timok_date") +
                            " AND " + base.Database.CreateSqlParameterName("End_timok_date") +
                            " GROUP BY " + CDRRow.term_end_point_id_DbName + " " +

                            "UNION " +

                            "SELECT CAST(" + CDRRow.term_end_point_id_DbName + " as smallint), CAST(0 as int), CAST(count(*) as int) " +
                            "FROM [CDR] WHERE " + CDRRow.duration_DbName + " > 0 " +
                            "AND " + CDRRow.timok_date_DbName + " BETWEEN " +
                            base.Database.CreateSqlParameterName("Start_timok_date") +
                            " AND " + base.Database.CreateSqlParameterName("End_timok_date") +
                            " GROUP BY " + CDRRow.term_end_point_id_DbName + " " +

                            "SELECT term_ep_id AS " + EndpointAsrDataTable.Id_ColumnName + ", SUM(term_ep_calls) AS " + EndpointAsrDataTable.Calls_ColumnName + ", SUM(term_ep_connected_calls) AS " + EndpointAsrDataTable.Connected_calls_ColumnName + " " +
                            ", asr = " +
                            "CASE WHEN SUM(term_ep_calls) > 0 THEN SUM(term_ep_connected_calls) * 100 / SUM(term_ep_calls) " +
                            "ELSE 0 END " +
                            "FROM @T GROUP BY term_ep_id " +
                            "ORDER BY term_ep_id";

            IDbCommand cmd = base.Database.CreateCommand(sqlStr);

            cmd.CommandTimeout = 600;

            base.Database.AddParameter(cmd, "Start_timok_date", DbType.Int32, pStartTimokDate);
            base.Database.AddParameter(cmd, "End_timok_date", DbType.Int32, pEndTimokDate);
            using (IDataReader reader = cmd.ExecuteReader()) {
                return(MapRecordsToDataTable(reader, EndpointAsrDataTable.CreateNew()));
            }
        }
コード例 #15
0
        public static bool HasCDRsByTermEndPointId(short pTermEndPointId)
        {
            int       _count          = 0;
            int       _startTimokDate = TimokDate.Parse(DateTime.Now.AddMonths(MonthsBackToCheckCDRs));
            int       _endTimokDate   = TimokDate.Parse(DateTime.Now);
            ArrayList _dbDateList     = getDBDateList(_startTimokDate, _endTimokDate);

            foreach (DateTime _dbDate in _dbDateList)
            {
                if (_count <= 0)
                {
                    if (Cdr_Db.Exists(_dbDate))
                    {
                        using (var _db = new Cdr_Db(_dbDate)) {
                            _count += _db.CDRCollection.GetCountByTermEndPointId(_startTimokDate, _endTimokDate, pTermEndPointId);
                        }
                    }
                }
            }
            return(_count > 0);
        }
コード例 #16
0
        string getEndpointAsrSummary(DateTime pDate)
        {
            var _sb = new StringBuilder();
            var _endpointASRList = Cdr.GetTermEndpointsASR(TimokDate.ParseToShortTimokDate(pDate));

            _sb.Append("\r\nTerminating TG ASR (All/Connected)\r\n");
            _sb.Append("-------------------------------------------------------\r\n");
            var _totalCalls         = 0;
            var _totalConectedCalls = 0;

            foreach (var _endpointASR in _endpointASRList)
            {
                _sb.Append(_endpointASR.Alias);
                _sb.Append(" [TG" + _endpointASR.EndpointId + "]:" + "\t\t\t" + calculateTotalASR(_endpointASR.Calls, _endpointASR.ConnectedCalls) + "\t\t\t(" +
                           _endpointASR.Calls + "/" + _endpointASR.ConnectedCalls + ")\r\n");
                //_sb.Append(" [TG" + _endpointAsr.EndpointId + "]:" + "\t\t\t" + _endpointAsr.Asr.ToString("0%") + "\t\t\t(" + _endpointAsr.Calls + "/" + _endpointAsr.ConnectedCalls + ")\r\n");
                _totalCalls         += _endpointASR.Calls;
                _totalConectedCalls += _endpointASR.ConnectedCalls;
            }
            _sb.Append("\r\n" + "Total:\t\t\t" + calculateTotalASR(_totalCalls, _totalConectedCalls) + "\t\t\t(" + _totalCalls + "/" + _totalConectedCalls + ")\r\n");
            return(_sb.ToString());
        }
コード例 #17
0
        /// <summary>
        /// Purges the CdrAggregate table, leaving specified number of Days (including today)
        /// </summary>
        /// <param name="pDaysToKeep">Number of Days to keep in a table, (including today); Value 0 or less will delete all records.</param>
        /// <returns>Number of deleted records </returns>
        public int Purge(int pDaysToKeep)
        {
            int _maxDateHourToDelete = TimokDate.Parse(DateTime.Today.AddDays(-pDaysToKeep), 23);

            string _sqlStr = "DELETE TOP (1000) FROM CdrAggregate " +
                             " WHERE " + CdrAggregateRow.date_hour_DbName + " < " + Database.CreateSqlParameterName(CdrAggregateRow.date_hour_PropName);

            IDbCommand _cmd = Database.CreateCommand(_sqlStr);

            AddParameter(_cmd, CdrAggregateRow.date_hour_PropName, _maxDateHourToDelete);

            int _rowsAffected      = 0;
            int _totalRowsAffected = 0;

            do
            {
                _rowsAffected       = _cmd.ExecuteNonQuery();
                _totalRowsAffected += _rowsAffected;
            } while (_rowsAffected == 1000);

            return(_totalRowsAffected);
        }
コード例 #18
0
        string getCustomerRouteMinutesSummary(DateTime pDate)
        {
            var _sb = new StringBuilder();
            var _customerRouteMinutesSummaries = Cdr.GetCustomerRouteMinutesSummaries(TimokDate.ParseToShortTimokDate(pDate));

            _sb.Append("Inbound Country Summary (Minutes)\r\n");
            _sb.Append("-------------------------------------------------------\r\n");
            decimal _totalMinutes = 0;

            foreach (var _routeMinutesSummary in _customerRouteMinutesSummaries)
            {
                _sb.Append(_routeMinutesSummary.Name + ":" + "\t\t\t" + _routeMinutesSummary.Minutes.ToString("0.00") + "\r\n");
                _totalMinutes = decimal.Add(_totalMinutes, _routeMinutesSummary.Minutes);
            }
            _sb.Append("\r\n" + "Total Minutes:\t\t" + _totalMinutes.ToString("0.00") + "\r\n\r\n");
            return(_sb.ToString());
        }
コード例 #19
0
		public CDRViewRow[] GetByRetailAcctId(DateTime pDate, int pRetailAcctId) {
			int _startTimokDate = TimokDate.ParseToShortTimokDate(pDate) * 100;
			int _endTimokDate = TimokDate.ParseToShortTimokDate(pDate) * 100 + 23;
			return GetByRetailAcctId(_startTimokDate, _endTimokDate, pRetailAcctId);
		}
コード例 #20
0
ファイル: CdrAggregate.cs プロジェクト: cuongdodinh/timok.rbr
        public CdrAggregate(string pAccessNumber, string pOrigIP, string pTermIP, int pCustomerRouteId, int pCarrierRouteId, short pCustomerAcctId, short pCarrierAcctId)
        {
            NodeID   = (new CurrentNode()).Id;
            DateHour = TimokDate.Parse(DateTime.Now, DateTime.Now.Hour);

            //-- Parse AccessNumber
            long.TryParse(pAccessNumber, out accessNumber);
            if (accessNumber == 0)
            {
                TimokLogger.Instance.LogRbr(LogSeverity.Debug, "CdrAggregate.Ctor", string.Format("Invalid Access Number:{0}", pAccessNumber));
            }

            //-- Parse IP
            if (origIP != 0)
            {
                try {
                    origIP = IPUtil.ToInt32(pOrigIP);
                    var _ep = Endpoint.Get(pOrigIP);
                    if (_ep == null)
                    {
                        throw new RbrException(RbrResult.OrigEP_NotFound, "CdrAggregate.Ctor", string.Format("Endpoint NOT FOUND, IP={0}", pOrigIP));
                    }
                    origId = _ep.Id;
                }
                catch (RbrException _rbrex) {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, "CdrAggregate.Ctor", string.Format("Orig Endpoint NOT FOUND, IP={0}, Exception:\r\n{1}", pOrigIP, _rbrex));
                }
                catch (Exception _ex) {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, "CdrAggregate.Ctor", string.Format("Orig Endpoint NOT FOUND, IP={0}, Exception:\r\n{1}", pOrigIP, _ex));
                }
            }

            //-- Parse TermIP
            if (termIP != 0)
            {
                try {
                    termIP = IPUtil.ToInt32(pTermIP);
                    var _ep = Endpoint.Get(pTermIP);
                    if (_ep == null)
                    {
                        throw new RbrException(RbrResult.OrigEP_NotFound, "CdrAggregate.Ctor", string.Format("Endpoint NOT FOUND, IP={0}", pTermIP));
                    }

                    termId = _ep.Id;
                }
                catch (RbrException _rbrex) {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, "CdrAggregate.Ctor", string.Format("Term Endpoint NOT FOUND, IP={0}, Exception:\r\n{1}", pTermIP, _rbrex));
                }
                catch (Exception _ex) {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, "CdrAggregate.Ctor", string.Format("Term Endpoint NOT FOUND, IP={0}, Exception:\r\n{1}", pTermIP, _ex));
                }
            }

            customerRouteId = pCustomerRouteId;
            carrierRouteId  = pCarrierRouteId;
            customerAcctId  = pCustomerAcctId;
            carrierAcctId   = pCarrierAcctId;

            //-- set Pkey
            var _prep = string.Format("{0}{1}{2}{3}{4}{5}{6}", accessNumber, origId, termId, customerAcctId, customerRouteId, carrierAcctId, carrierRouteId);

            TimokLogger.Instance.LogRbr(LogSeverity.Debug, "CdrAggregate.Ctor", string.Format("Key: {0}-{1}-{2}-{3}-{4}-{5}-{6}", accessNumber, origId, termId, customerAcctId, customerRouteId, carrierAcctId, carrierRouteId));
            pk = Md5hash.Get(_prep);
        }
コード例 #21
0
 private static ArrayList getDBDateList(int pStartTimokDate, int pEndTimokDate)
 {
     return(getDBDateList(TimokDate.ToDateTime(pStartTimokDate), TimokDate.ToDateTime(pEndTimokDate)));
 }
コード例 #22
0
        public Cdr(string pGuid, string pRawCdr, bool pDateLoggedFromCdr)
        {
            cdrRow                    = new CDRRow();
            cdrRow.Id                 = pGuid;
            cdrRow.ANI                = 0;
            cdrRow.DNIS               = 0;
            cdrRow.Price              = decimal.Zero;
            cdrRow.Cost               = decimal.Zero;
            cdrRow.End_user_price     = decimal.Zero;
            cdrRow.Used_bonus_minutes = 0;
            cdrRow.Prefix_in          = string.Empty;
            cdrRow.Prefix_out         = string.Empty;
            cdrRow.Local_number       = string.Empty;
            cdrRow.Node_id            = (new CurrentNode()).Id;

            sipUserId = string.Empty;
            alias     = string.Empty;

            //--preset Cdr fields, in case route == null
            CountryCode       = 0;
            LocalNumber       = string.Empty;
            CarrierRouteName  = "UNKNOWN";
            CustomerRouteName = "UNKNOWN";

            #region cdr format:

            //	0		2|																		//duration
            //	1		Wed. 09 Mar 2005 14:20:43 -0500|			//startDateTime
            //	2		Wed. 09 Mar 2005 14:20:45 -0500|			//StopDateTime
            //	3		192.168.1.4:1719|											//OrigIp
            //	4		8113_endp|														//callerID
            //	5		192.168.1.10:1720|										//TermIp
            //	6		8473_endp|														//calledID or S#:xxx
            //	7		01152222234567:dialedDigits|					//DestNumber
            //	8		|1112222															//ANI(ANI), orig Alias?
            //	9		|Gk Alias															//Gk Alias or DNIS:xxx;ANIxxx
            // 10		customer route id
            // 11		carrier route id
            // 12   customer route id
            // 13   carrier route id
            // 14   Release cause code
            // 15   Release source
            // 16   Rbr result
            // 17   Original Release cause code

            #endregion

            var _fields = pRawCdr.Split('|');

            //-- fields[0]: Call Duration
            cdrRow.Duration = Convert.ToInt16(_fields[0]);

            //-- fields[1]: start date/time
            var _startDateTime = _fields[1];

            //-- fields[2]: stop date/time
            var _endDateTime = _fields[2];

            cdrRow.Start      = getStandardDateTime(_startDateTime, _endDateTime);
            cdrRow.Timok_date = TimokDate.Parse(cdrRow.Start);

            //-- late logged
            if (pDateLoggedFromCdr)
            {
                cdrRow.Date_logged = cdrRow.Start.AddMinutes((cdrRow.Duration / 60) + (cdrRow.Duration % 60 > 0 ? 1 : 0));
            }
            else
            {
                var _dtNow = DateTime.Now;
                cdrRow.Date_logged = new DateTime(_dtNow.Year, _dtNow.Month, _dtNow.Day, _dtNow.Hour, _dtNow.Minute, 0);
            }

            //-- fields[3]: Orig ip address
            var _origIP = _fields[3].Substring(0, _fields[3].IndexOf(':'));
            cdrRow.Orig_IP_address = IPUtil.ToInt32(_origIP);
            OrigIP = _origIP;

            //-- fields[4]: sipUserId ( m_callerId )
            sipUserId = SIPHelper.GetUserId(_fields[4], TimokLogger.Instance.LogRbr);
            if (sipUserId.Length > 0)
            {
                alias = sipUserId;
            }

            //-- fields[5]: TermIP address
            //75|Wed, 07 Feb 2007 18:45:17 -0500|Wed, 07 Feb 2007 18:46:32 -0500|67.130.1.45:1276|8435225294:dialedDigits=8435225294 :h323_ID=id$8435225294:h323_ID=ip$67.130.1.40:h323_ID|67.130.1.31:1720|2486_endp|18128772101:dialedDigits|8435225294|MUNDETEL-SW1|0|10000|10000|1|10306|16|0|0|16;)
            var _indx = _fields[5].IndexOf(':');
            if (_indx > -1)
            {
                TermIP = _fields[5].Substring(0, _indx);
            }
            else
            {
                TermIP = _fields[5];
            }
            //-- This is because Gk sends HostIP address in the CalledIP field when Rbr did not find termination
            //-- we want to show 0.0.0.0 in cdr
            if (TermIP.CompareTo(Configuration.Instance.Main.HostIP) == 0)
            {
                TermIP = "0.0.0.0";
            }

            //-- fields[6]: m_calledId - check if SerialNumber present
            //NOTE: some h323 endpoints send orig alias here
            //alias = tryAlias(_fields[6]);
            cdrRow.Serial_number = trySerialNumber(_fields[6]);
            TimokLogger.Instance.LogRbr(LogSeverity.Debug, "Cdr.Ctor", string.Format("Is Serial# ? field[6]: {0}", _fields[6]));

            //-- fields[7]: Dest number
            //TimokLogger.Instance.LogDebug(string.Format("Is Dest# ? field[7]: {0}", _fields[7]));
            _indx = _fields[7].IndexOf(':');
            if (_indx > -1)
            {
                DestNumber = _fields[7].Substring(0, _indx);
            }
            else
            {
                DestNumber = _fields[7];
            }

            if (DestNumber == null)
            {
                DestNumber = string.Empty;
            }

            //if (DestNumber.Length > 0) {
            //  CountryCode = int.Parse(DestNumber.Substring(0,1));
            //  LocalNumber = DestNumber.Substring(1);
            //}

            //-- fields[8]: ANI, Orig Alias
            //TimokLogger.Instance.LogDebug(string.Format("Is ANI/Alias ? field[8]: {0}", _fields[8]));

            /*
             * sourceAddress = 4 entries {
             * [0]=dialedDigits "3605759548"
             * [1]=h323_ID  11 characters {
             * 0033 0036 0030 0035 0037 0035 0039 0035   36057595
             * 0034 0038 0020                            48
             * }
             * [2]=h323_ID  13 characters {
             * 0069 0064 0024 0033 0036 0030 0035 0037   id$36057
             * 0035 0039 0035 0034 0038                  59548
             * }
             * [3]=h323_ID  14 characters {
             * 0069 0070 0024 0036 0037 002e 0031 0033   ip$67.13
             * 0030 002e 0031 002e 0034 0030             0.1.40
             * }
             * }
             * 75|Wed, 07 Feb 2007 18:45:17 -0500|Wed, 07 Feb 2007 18:46:32 -0500|67.130.1.45:1276|8435225294:dialedDigits=8435225294 :h323_ID=id$8435225294:h323_ID=ip$67.130.1.40:h323_ID|67.130.1.31:1720|2486_endp|18128772101:dialedDigits|8435225294|MUNDETEL-SW1|0|10000|10000|1|10306|16|0|0|16;)
             */
            var _subFields = _fields[8].Split('=');
            foreach (var _subfield in _subFields)
            {
                if (alias.Length == 0)
                {
                    alias = tryAlias(_subfield);
                    if (alias.Length > 0)
                    {
                        continue;
                    }
                }
                if (cdrRow.ANI == 0)
                {
                    cdrRow.ANI = tryANI(_subfield);
                    if (cdrRow.ANI > 0)
                    {
                        continue;
                    }
                }
            }

            //-- fields[9]: Gk Alias - check if DNIS is here
            cdrRow.DNIS = tryDNIS(_fields[9]);
            //TimokLogger.Instance.LogDebug(string.Format("Is DNIS ? field[9]: {0}", _fields[9]));

            //-- fields[10]: retail acct id
            try {
                cdrRow.Retail_acct_id = int.Parse(_fields[10]);
            }
            catch {
                cdrRow.Retail_acct_id = 0;
            }
            //TimokLogger.Instance.LogDebug(string.Format("Is RetailAcct ? field[10]: {0}", _fields[10]));

            //-- fields[11]: customer acct id
            try {
                cdrRow.Customer_acct_id = short.Parse(_fields[11]);
            }
            catch {
                cdrRow.Customer_acct_id = 0;
            }
            //TimokLogger.Instance.LogDebug(string.Format("Is CustomerAcct ? field[11]: {0}", _fields[11]));

            //-- fields[12]: carrier routaccte id
            try {
                cdrRow.Carrier_acct_id = short.Parse(_fields[12]);
            }
            catch {
                cdrRow.Carrier_acct_id = 0;
            }
            //TimokLogger.Instance.LogDebug(string.Format("Is CarrierAcct ? field[12]: {0}", _fields[12]));

            //-- fields[13]: customer route id
            try {
                cdrRow.Customer_route_id = int.Parse(_fields[13]);
            }
            catch {
                cdrRow.Customer_route_id = 0;
            }
            //TimokLogger.Instance.LogDebug(string.Format("Is CustomerRoute ? field[13]: {0}", _fields[13]));

            //-- fields[14]: carrier route id
            try {
                cdrRow.Carrier_route_id = int.Parse(_fields[14]);
            }
            catch {
                cdrRow.Carrier_route_id = 0;
            }
            //TimokLogger.Instance.LogDebug(string.Format("Is CarrierAcct ? field[14]: {0}", _fields[14]));

            //-- fields[15]: Release cause code
            var _causeStr = _fields[15];
            //TimokLogger.Instance.LogDebug(string.Format("Is DisconnectCause ? field[15]: {0}", _fields[15]));
            try {
                cdrRow.Disconnect_cause = short.Parse(_causeStr);
            }
            catch {
                cdrRow.Disconnect_cause = (short)GkDisconnectCause.Unknown;
            }

            //-- fields[16]: Release source
            var _sourceStr = _fields[16];
            //TimokLogger.Instance.LogDebug(string.Format("Is SourceStr ? field[16]: {0}", _fields[16]));
            try {
                cdrRow.Disconnect_source = byte.Parse(_sourceStr);
            }
            catch {
                cdrRow.Disconnect_source = (byte)GkDisconnectSource.Unknown;
            }

            //-- fields[17]: Rbr result
            var _rbrResultStr = _fields[17];
            //TimokLogger.Instance.LogDebug(string.Format("Is RbrResult ? field[17]: {0}", _fields[17]));
            try {
                cdrRow.Rbr_result = short.Parse(_rbrResultStr);
            }
            catch {
                cdrRow.Rbr_result = (short)RbrResult.Unknown;
            }

            //-- fields[18]: Original Release cause code
            //TimokLogger.Instance.LogDebug(string.Format("Is MappedCauseStr ? field[18]: {0}", _fields[18]));
            try {
                cdrRow.Mapped_disconnect_cause = short.Parse(_fields[18]);
            }
            catch {
                cdrRow.Mapped_disconnect_cause = (short)GkDisconnectCause.Unknown;
            }

            //-- fields[19]: Original Release cause code
            //TimokLogger.Instance.LogDebug(string.Format("Is InfoDigits ? field[19]: {0}", _fields[19]));
            string _infoDigits = _fields[19].TrimEnd(';');
            try {
                cdrRow.Info_digits = byte.Parse(_infoDigits);
            }
            catch {
                cdrRow.Info_digits = 0;
            }
        }