Beispiel #1
0
        public async Task <SIPAccount> Create(string username, string domain, string ha1Digest)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(domain) || string.IsNullOrWhiteSpace(ha1Digest))
            {
                throw new ArgumentNullException(nameof(username), "The username, domain and digest parameters must be specified when creating a SIP Account.");
            }

            SIPAccount sipAccount = new SIPAccount
            {
                SIPUsername = username,
                HA1Digest   = ha1Digest
            };

            using (var db = _dbContextFactory.CreateDbContext())
            {
                SIPDomain sipDomain = await db.SIPDomains.Where(x => x.Domain.ToLower() == domain.ToLower()).SingleOrDefaultAsync();

                if (sipDomain == null)
                {
                    throw new ApplicationException($"SIP Domain not found for {domain} when creating SIP Account.");
                }
                else
                {
                    sipAccount.ID       = Guid.NewGuid();
                    sipAccount.Inserted = DateTime.UtcNow;
                    sipAccount.DomainID = sipDomain.ID;
                    await db.SIPAccounts.AddAsync(sipAccount);

                    await db.SaveChangesAsync();
                }
            }

            return(sipAccount);
        }
        public async Task <string> GetCanonicalDomain(string host)
        {
            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException(nameof(host), "The host parameter must be specified for GetCanonicalDomain.");
            }

            using (var db = _dbContextFactory.CreateDbContext())
            {
                SIPDomain sipDomain = db.SIPDomains.Where(x => x.Domain.ToLower() == host.ToLower()).SingleOrDefault();
                if (sipDomain == null)
                {
                    sipDomain = await db.SIPDomains.Where(x => x.AliasList.ToLower().Contains(host.ToLower())).FirstOrDefaultAsync();
                }

                return(sipDomain?.Domain);
            }
        }