示例#1
0
        /// <summary>
        /// Returns value of message parameter
        /// </summary>
        /// <param name="message"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public string GetValue(string parameter)
        {
            var values = IncomingSplittedMessage.Skip(4);

            int    pos           = 0;
            string yateParameter = string.Empty;
            string yateValue     = string.Empty;

            foreach (var value in values)
            {
                if (!string.IsNullOrEmpty(value))
                {
                    pos = value.IndexOf('=');

                    yateParameter = value.Substring(0, pos);

                    // Check if current parameter is requested parameter
                    if (yateParameter == parameter)
                    {
                        // Check if has value
                        if (pos <= value.Length - 1)
                        {
                            yateValue = CharacterCoding.Decode(value.Substring(pos + 1));
                        }

                        break;
                    }
                }
            }

            return(yateValue);
        }
示例#2
0
        /// <summary>
        /// Parses the message for it's values
        /// </summary>
        private void _Parse()
        {
            var values = Messages.Skip(4).ToArray();

            string yateParameter, yateValue;
            int    pos;

            foreach (var value in values)
            {
                pos = value.IndexOf('=');

                // ignore everything without =
                if (pos == -1)
                {
                    continue;
                }

                yateParameter = value.Substring(0, pos);

                // Check if has value
                if (pos <= value.Length - 1)
                {
                    yateValue = CharacterCoding.Decode(value.Substring(pos + 1));
                }
                else
                {
                    continue;
                }

                switch (yateParameter)
                {
                case "id":
                    this.channelId = yateValue;
                    break;

                case "remoteip":
                    this.remoteRtpIp = yateValue;
                    break;

                case "remoteport":
                    this.remoteRtpPort = yateValue;
                    break;

                case "rtpId":
                    this.rtpChannelId = yateValue;
                    break;

                case "call_billid":
                    this.callBillId = yateValue;
                    break;

                default:
                    continue;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Parses the statements from yate into C# object
        /// </summary>
        private void _Parse()
        {
            var values = Messages.Skip(4).ToArray();

            string rtpAddress = string.Empty;
            string rtpPort    = string.Empty;
            string operation  = string.Empty;
            string runid      = string.Empty;

            int    pos           = 0;
            string yateParameter = string.Empty;
            string yateValue     = string.Empty;

            foreach (var value in values)
            {
                pos = value.IndexOf('=');

                // ignore everything without =
                if (pos == -1)
                {
                    continue;
                }

                yateParameter = value.Substring(0, pos);

                // Check if has value
                if (pos <= value.Length - 1)
                {
                    yateValue = CharacterCoding.Decode(value.Substring(pos + 1));
                }
                else
                {
                    continue;
                }

                switch (yateParameter)
                {
                case "runid":
                    runid = yateValue;
                    break;

                case "operation":
                    operation = yateValue;
                    break;

                case "time":
                    this.callDataRecord.YYateTime = decimal.Parse(yateValue, Formats.CultureInfo);
                    this.callDataRecord.CLSQLTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).AddSeconds((double)this.callDataRecord.YYateTime);
                    break;

                case "billid":
                    this.callDataRecord.YBillId = yateValue;
                    break;

                case "chan":
                    this.callDataRecord.YChan = yateValue;
                    break;

                case "address":
                    this.callDataRecord.YAddress = new IPEndPoint(IPAddress.Parse(yateValue.Substring(0, yateValue.IndexOf(':'))), int.Parse(yateValue.Substring(yateValue.IndexOf(':') + 1), Formats.CultureInfo));
                    break;

                case "caller":
                    this.callDataRecord.YCaller = yateValue;
                    break;

                case "callername":
                    this.callDataRecord.YCallername = yateValue;
                    break;

                case "called":
                    this.callDataRecord.YCalled = yateValue;
                    break;

                case "status":
                    this.callDataRecord.YStatus = yateValue;
                    break;

                case "reason":
                    this.callDataRecord.YReason = yateValue;
                    break;

                case "ended":
                    this.callDataRecord.YEnded = bool.Parse(yateValue);
                    break;

                case "format":
                    this.callDataRecord.YFormat = yateValue;
                    break;

                case "formats":
                    this.callDataRecord.YFormats = yateValue;
                    break;

                case "rtp_addr":
                    rtpAddress = yateValue;
                    break;

                case "rtp_port":
                    rtpPort = yateValue;
                    break;

                case "rtp_forward":
                    this.callDataRecord.YRTPForward = bool.Parse(yateValue);
                    break;

                case "billtime":
                    // Convert from Second.Millisecond to Millisecond
                    this.callDataRecord.YBilltime = (long)(decimal.Parse(yateValue, Formats.CultureInfo) * 1000);
                    break;

                case "ringtime":
                    this.callDataRecord.YRingtime = (long)(decimal.Parse(yateValue, Formats.CultureInfo) * 1000);
                    break;

                case "duration":
                    this.callDataRecord.YDuration = (long)(decimal.Parse(yateValue, Formats.CultureInfo) * 1000);
                    break;

                case "direction":
                    if (yateValue == "incoming")
                    {
                        this.callDataRecord.YDirection = Direction.Incoming;
                    }
                    else
                    {
                        this.callDataRecord.YDirection = Direction.Outgoing;
                    }
                    break;

                case "cause_q391":
                    this.callDataRecord.YCauseQ931 = yateValue;
                    break;

                case "error":
                    this.callDataRecord.YError = yateValue;
                    break;

                case "cause_sip":
                    this.callDataRecord.YCauseSIP = yateValue;
                    break;

                case "sip_user_agent":
                case "sip_server":
                    // Set value of whatever comes first, if first is empty, second will be used automatically in second run
                    if (string.IsNullOrEmpty(this.callDataRecord.YSIPUserAgent))
                    {
                        this.callDataRecord.YSIPUserAgent = yateValue;
                    }

                    break;

                case "sip_x_asterisk_hangupcause":
                    this.callDataRecord.YSIPXAsteriskHangupCause = yateValue;
                    break;

                case "sip_x_asterisk_hangupcausecode":
                    this.callDataRecord.YSIPXAsteriskHangupCode = yateValue;
                    break;

                case "clgatewayaccountid":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLGatewayAccountId = int.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clgatewayipid":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLGatewayIPId = int.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clcustomeripid":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLCustomerIPId = int.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clgatewayid":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLGatewayId = int.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clcustomerid":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLCustomerId = int.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "cltrackingid":
                    this.callDataRecord.CLTrackingId = yateValue;
                    break;

                case "clwaitingtime":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLWaitingTime = int.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clprocessingtime":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLProcessingTime = int.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "cltechcalled":
                    this.callDataRecord.CLTechCalled = yateValue;
                    break;

                case "clcustomerpriceid":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLCustomerRateId = long.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clcustomerpricepermin":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLCustomerRatePerMin = decimal.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clcustomercurrency":
                    this.callDataRecord.CLCustomerCurrency = yateValue;
                    break;

                case "clgatewaypriceid":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLGatewayRateId = long.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clgatewaypricepermin":
                    if (!string.IsNullOrEmpty(yateValue))
                    {
                        this.callDataRecord.CLGatewayRatePerMin = decimal.Parse(yateValue, Formats.CultureInfo);
                    }

                    break;

                case "clgatewaycurrency":
                    this.callDataRecord.CLGatewayCurrency = yateValue;
                    break;

                case "cldialcodemasterid":
                    this.callDataRecord.CLDialcodeMasterId = int.Parse(yateValue, Formats.CultureInfo);
                    break;

                default:
                    break;
                }
            }

            if (!string.IsNullOrEmpty(rtpAddress))
            {
                this.callDataRecord.YRTPAddress = new IPEndPoint(IPAddress.Parse(rtpAddress), int.Parse(rtpPort, Formats.CultureInfo));
            }

            this.callLegInfo = new Model.CallLegTracking()
            {
                Ended      = this.callDataRecord.YEnded,
                EndedOn    = this.callDataRecord.CLSQLTime.AddMilliseconds(this.callDataRecord.YDuration),
                Identifier = $"{runid}-{this.callDataRecord.YBillId}-{this.callDataRecord.YChan}",
                Operation  = operation,
                Status     = this.callDataRecord.YStatus,
                Direction  = this.callDataRecord.YDirection
            };
        }