public List <SIPRegistrarBinding> GetForSIPAccount(Guid sipAccountID)
 {
     using (var db = new SIPAssetsDbContext())
     {
         return(db.SIPRegistrarBindings.Where(x => x.SIPAccountID == sipAccountID).ToList());
     }
 }
        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);
            }
        }
Exemplo n.º 3
0
 public CDR Get(Guid id)
 {
     using (var db = new SIPAssetsDbContext())
     {
         return(db.CDRs.Where(x => x.ID == id).FirstOrDefault());
     }
 }
Exemplo n.º 4
0
 public SIPCall Get(Expression <Func <SIPCall, bool> > where)
 {
     using (var db = new SIPAssetsDbContext())
     {
         return(db.SIPCalls.Where(where).FirstOrDefault());
     }
 }
Exemplo n.º 5
0
        public SIPAccount GetSIPAccount(string username, string domain)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException(nameof(username), "The username parameter must be specified for GetSIPAccount.");
            }
            else if (string.IsNullOrEmpty(domain))
            {
                throw new ArgumentNullException(nameof(domain), "The domain parameter must be specified for GetSIPAccount.");
            }

            using (var db = new SIPAssetsDbContext())
            {
                SIPAccount sipAccount = db.SIPAccounts.Include(x => x.Domain).Where(x => x.SIPUsername.ToLower() == username.ToLower() &&
                                                                                    x.Domain.Domain.ToLower() == domain.ToLower()).SingleOrDefault();
                if (sipAccount == null)
                {
                    // A full lookup failed. Now try a partial lookup if the incoming username is in a dotted domain name format.
                    if (username.Contains("."))
                    {
                        string usernameSuffix = username.Substring(username.LastIndexOf(".") + 1);
                        sipAccount = db.SIPAccounts.Include(x => x.Domain).Where(x => x.SIPUsername.ToLower() == usernameSuffix.ToLower() &&
                                                                                 x.Domain.Domain.ToLower() == domain.ToLower()).SingleOrDefault();
                    }
                }

                return(sipAccount);
            }
        }
 public SIPRegistrarBinding GetNextExpired(DateTime expiryTime)
 {
     using (var db = new SIPAssetsDbContext())
     {
         return(db.SIPRegistrarBindings
                .Include(x => x.SIPAccount)
                .Where(x => x.ExpiryTime <= expiryTime)
                .OrderBy(x => x.ExpiryTime)
                .FirstOrDefault());
     }
 }
 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();
         }
     }
 }
Exemplo n.º 8
0
        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();
            }
        }
Exemplo n.º 9
0
 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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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();
                }
            }
        }
Exemplo n.º 13
0
        public string GetCanonicalDomain(string host, bool wildcardOk)
        {
            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException(nameof(host), "The host parameter must be specified for GetCanonicalDomain.");
            }

            using (var db = new SIPAssetsDbContext())
            {
                SIPDomain sipDomain = db.SIPDomains.Where(x => x.Domain.ToLower() == host.ToLower()).SingleOrDefault();
                if (sipDomain == null)
                {
                    sipDomain = db.SIPDomains.Where(x => x.AliasList.ToLower().Contains(host.ToLower())).FirstOrDefault();
                }

                return(sipDomain?.Domain);
            }
        }
        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);
            }
        }
Exemplo n.º 15
0
        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();
                }
            }
        }
Exemplo n.º 16
0
        /// <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();
                }
            }
        }