Example #1
0
        /// <summary>
        /// Save this to the filesystem in Current
        /// </summary>
        /// <returns>Success</returns>
        public virtual bool Remove()
        {
            try
            {
                LiveData dataAccessor = new LiveData();
                dataAccessor.RemoveEntity(this);
                LiveCache.Remove(new LiveCacheKey(this));
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Processes the CDR
        /// </summary>
        /// <returns>Returns task to wait for</returns>
        private async Task _Process()
        {
            // Calculate Gatway Price
            if (this.callDataRecord.CLGatewayRatePerMin.HasValue)
            {
                this.callDataRecord.CLGatewayRateTotal = this.callDataRecord.CLGatewayRatePerMin * (((decimal)this.callDataRecord.YBilltime) / 1000 / 60);
            }

            // Calculate Customer Price
            if (this.callDataRecord.CLCustomerRatePerMin.HasValue)
            {
                this.callDataRecord.CLCustomerRateTotal = this.callDataRecord.CLCustomerRatePerMin * (((decimal)this.callDataRecord.YBilltime) / 1000 / 60);
            }

            /// Retrieve routing tree prepared in <see cref="CallRouteWorker"/> if CDR is of incoming leg
            Utilities.RoutingTree.Root routingTree = null;

            if (callDataRecord.YDirection == Direction.Incoming)
            {
                object data;
                string key = $"routingTree-{this.Node.Id}-{this.callDataRecord.YBillId}";

                data = LiveCache.Get(key);
                if (data != null && data is Utilities.RoutingTree.Root)
                {
                    routingTree = data as Utilities.RoutingTree.Root;
                }

                if (this.callDataRecord.YEnded)
                {
                    LiveCache.Remove(key);
                }

                if (routingTree != null)
                {
                    this.callDataRecord.RoutingTree = JsonConvert.SerializeObject(routingTree, Formatting.None);
                }
            }

            this.isHandled = await this.database.WriteCDR(this.callDataRecord).ConfigureAwait(false);

            this._Acknowledge();
        }
Example #3
0
        /// <summary>
        /// Retrieves RTP data from cache
        /// </summary>
        /// <returns></returns>
        private CallLegInfo getRtpDetailsFromChangHangup()
        {
            if (this.Message.MessageType != MessageType.ChanHangup)
            {
                return(null);
            }

            string channelId = this.Message.GetValue("id");
            int    nodeId    = this.Message.Node.Id;

            var callLeg = new CallLegInfo();

            callLeg.ChannelId = channelId;
            callLeg.BillId    = this.Message.GetValue("billid");

            // Usage of same 'data' reference for performance
            object data = LiveCache.Get($"channelIdToYRtpId-{nodeId}-{channelId}");

            if (data != null && data is string)
            {
                callLeg.YRtpId = data as string;
            }
            else
            {
                return(null);
            }

            if (string.IsNullOrEmpty(callLeg.BillId))
            {
                data = LiveCache.Get($"yRtpIdToBillId-{nodeId}-{callLeg.YRtpId}");
                if (data == null)
                {
                    data = LiveCache.Get($"channelIdToBillId-{nodeId}-{channelId}");
                }

                if (data != null && data is string)
                {
                    callLeg.BillId = data as string;
                }
            }

            // Resolve remote ip
            data = LiveCache.Get($"yRtpIdToRemoteRtpIp-{nodeId}-{callLeg.YRtpId}");
            if (data != null && data is string)
            {
                callLeg.RemoteRtpIp = data as string;
            }

            // Resolve remote port
            data = LiveCache.Get($"yRtpIdToRemoteRtpPort-{nodeId}-{callLeg.YRtpId}");
            if (data != null && data is string)
            {
                callLeg.RemoteRtpPort = int.Parse(data as string);
            }

            // Cleanup
            // Clean ChannelId To YRtpId
            if (!string.IsNullOrEmpty(callLeg.ChannelId))
            {
                LiveCache.Remove($"channelIdToYRtpId-{nodeId}-{callLeg.ChannelId}");
            }

            // Clean ChannelId to BillId
            if (!string.IsNullOrEmpty(callLeg.ChannelId))
            {
                LiveCache.Remove($"channelIdToBillId-{nodeId}-{callLeg.ChannelId}");
            }

            // Clean YRtpId to BillId
            if (!string.IsNullOrEmpty(callLeg.YRtpId))
            {
                LiveCache.Remove($"yRtpIdToBillId-{nodeId}-{callLeg.YRtpId}");
            }

            // Clean YRtpId to RemoteRtpIP
            if (!string.IsNullOrEmpty(callLeg.YRtpId))
            {
                LiveCache.Remove($"yRtpIdToRemoteRtpIp-{nodeId}-{callLeg.YRtpId}");
            }

            return(callLeg);
        }