Exemple #1
0
 public CDR(SIPCDR sipCDR)
 {
     ID               = sipCDR.CDRId;
     Direction        = sipCDR.CallDirection.ToString();
     Created          = sipCDR.Created;
     DstUser          = sipCDR.Destination.User;
     DstHost          = sipCDR.Destination.Host;
     DstUri           = sipCDR.Destination.ToString();
     FromUser         = sipCDR.From.FromURI.User;
     FromName         = sipCDR.From.FromName;
     FromHeader       = sipCDR.From.ToString();
     CallID           = sipCDR.CallId;
     LocalSocket      = sipCDR.LocalSIPEndPoint?.ToString();
     RemoteSocket     = sipCDR.RemoteEndPoint?.ToString();
     BridgeID         = (sipCDR.BridgeId != Guid.Empty) ? sipCDR.BridgeId : null;
     InProgressAt     = sipCDR.ProgressTime;
     InProgressStatus = sipCDR.ProgressStatus;
     InProgressReason = sipCDR.ProgressReasonPhrase;
     RingDuration     = sipCDR.GetProgressDuration();
     AnsweredAt       = sipCDR.AnswerTime;
     AnsweredStatus   = sipCDR.AnswerStatus;
     AnsweredReason   = sipCDR.AnswerReasonPhrase;
     Duration         = sipCDR.GetAnsweredDuration();
     HungupAt         = sipCDR.HangupTime;
     HungupReason     = sipCDR.HangupReason;
 }
        /// <summary>
        /// Updates an existing CDR.
        /// </summary>
        /// <param name="cdr">The CDR to update.</param>
        public void Update(SIPCDR sipCDR)
        {
            using (var db = _dbContextFactory.CreateDbContext())
            {
                var existing = (from cdr in db.CDRs where cdr.ID == sipCDR.CDRId select cdr).SingleOrDefault();

                if (existing == null)
                {
                    logger.LogWarning($"CDRDataLayer the CDR with ID {sipCDR.CDRId} could not be found for an Update operation.");
                }
                else
                {
                    // Fields that are not permitted to be updated.
                    // ID
                    // Inserted
                    // Direction
                    // Created
                    // Destination
                    // From
                    // Call-ID

                    existing.BridgeID         = (sipCDR.BridgeId != Guid.Empty) ? sipCDR.BridgeId : null;
                    existing.InProgressAt     = sipCDR.ProgressTime;
                    existing.InProgressStatus = sipCDR.ProgressStatus;
                    existing.InProgressReason = sipCDR.ProgressReasonPhrase;
                    existing.RingDuration     = sipCDR.GetProgressDuration();
                    existing.AnsweredAt       = sipCDR.AnswerTime;
                    existing.AnsweredStatus   = sipCDR.AnswerStatus;
                    existing.AnsweredReason   = sipCDR.AnswerReasonPhrase;
                    existing.Duration         = sipCDR.GetAnsweredDuration();
                    existing.HungupAt         = sipCDR.HangupTime;
                    existing.HungupReason     = sipCDR.HangupReason;
                    existing.AnsweredAt       = sipCDR.AnsweredAt;
                    existing.RemoteSocket     = sipCDR.RemoteEndPoint?.ToString();
                    existing.LocalSocket      = sipCDR.LocalSIPEndPoint?.ToString();

                    db.SaveChanges();
                }
            }
        }