public SIPRegistrarBinding RefreshBinding( Guid id, int expiry, SIPEndPoint remoteSIPEndPoint, SIPEndPoint proxySIPEndPoint, SIPEndPoint registrarSIPEndPoint, bool dontMangle) { using (var db = new SIPAssetsDbContext()) { var existing = db.SIPRegistrarBindings.Where(x => x.ID == id).SingleOrDefault(); if (existing == null) { throw new ApplicationException("The SIP Registrar Binding to update could not be found."); } existing.LastUpdate = DateTime.UtcNow; existing.Expiry = expiry; existing.ExpiryTime = DateTime.UtcNow.AddSeconds(expiry); existing.RemoteSIPSocket = remoteSIPEndPoint?.ToString(); existing.ProxySIPSocket = proxySIPEndPoint?.ToString(); existing.RegistrarSIPSocket = registrarSIPEndPoint?.ToString(); db.SaveChanges(); return(existing); } }
public void Add(SIPCDR sipCDR) { CDR cdr = new CDR(sipCDR); using (var db = new SIPAssetsDbContext()) { cdr.Inserted = DateTime.UtcNow; db.CDRs.Add(cdr); db.SaveChanges(); } }
public void Delete(Guid id) { using (var db = new SIPAssetsDbContext()) { var binding = db.SIPRegistrarBindings.Where(x => x.ID == id).SingleOrDefault(); if (binding != null) { db.SIPRegistrarBindings.Remove(binding); db.SaveChanges(); } } }
public void Delete(Guid id) { using (var db = new SIPAssetsDbContext()) { var call = db.SIPCalls.Where(x => x.ID == id).SingleOrDefault(); if (call != null) { db.SIPCalls.Remove(call); db.SaveChanges(); } } }
public SIPRegistrarBinding Add(SIPRegistrarBinding binding) { using (var db = new SIPAssetsDbContext()) { binding.ID = Guid.NewGuid(); binding.LastUpdate = DateTime.UtcNow; db.SIPRegistrarBindings.Add(binding); db.SaveChanges(); } return(binding); }
public SIPCall Add(SIPCall call) { using (var db = new SIPAssetsDbContext()) { call.ID = Guid.NewGuid(); call.Inserted = DateTime.UtcNow; db.SIPCalls.Add(call); db.SaveChanges(); } return(call); }
public void UpdateBridgeID(Guid id, Guid bridgeID) { using (var db = new SIPAssetsDbContext()) { var existing = db.CDRs.Where(x => x.ID == id).SingleOrDefault(); if (existing == null) { logger.LogWarning($"CDRDataLayer the CDR with ID {id} could not be found for a Update BridgeID operation."); } else { existing.BridgeID = bridgeID; db.SaveChanges(); } } }
public SIPRegistrarBinding SetExpiry(Guid id, int expiry) { using (var db = new SIPAssetsDbContext()) { var existing = db.SIPRegistrarBindings.Where(x => x.ID == id).SingleOrDefault(); if (existing == null) { throw new ApplicationException("The SIP Registrar Binding to update could not be found."); } existing.LastUpdate = DateTime.UtcNow; existing.Expiry = expiry; db.SaveChanges(); return(existing); } }
public void Hangup(Guid id, string reason) { using (var db = new SIPAssetsDbContext()) { var existing = db.CDRs.Where(x => x.ID == id).SingleOrDefault(); if (existing == null) { logger.LogWarning($"CDRDataLayer the CDR with ID {id} could not be found for a Hangup operation."); } else { existing.HungupAt = DateTime.UtcNow; existing.HungupReason = reason; existing.Duration = Convert.ToInt32(existing.HungupAt.Value.Subtract(existing.AnsweredAt.Value).TotalSeconds); db.SaveChanges(); } } }
/// <summary> /// Updates an existing CDR. /// </summary> /// <param name="cdr">The CDR to update.</param> public void Update(SIPCDR sipCDR) { using (var db = new SIPAssetsDbContext()) { 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(); } } }